notify-dpml AT lists.ibiblio.org
Subject: DPML Notify
List archive
r1273 - in trunk/main: depot/core/src/main/net/dpml/depot station/server/src/main/net/dpml/station/server
- From: mcconnell at BerliOS <mcconnell AT mail.berlios.de>
- To: notify-dpml AT lists.ibiblio.org
- Subject: r1273 - in trunk/main: depot/core/src/main/net/dpml/depot station/server/src/main/net/dpml/station/server
- Date: Mon, 27 Mar 2006 14:03:18 +0200
Author: mcconnell
Date: 2006-03-27 14:03:15 +0200 (Mon, 27 Mar 2006)
New Revision: 1273
Modified:
trunk/main/depot/core/src/main/net/dpml/depot/DepotHandler.java
trunk/main/depot/core/src/main/net/dpml/depot/Main.java
trunk/main/station/server/src/main/net/dpml/station/server/LoggingServer.java
trunk/main/station/server/src/main/net/dpml/station/server/RemoteApplication.java
Log:
log aggregation (continued)
Modified: trunk/main/depot/core/src/main/net/dpml/depot/DepotHandler.java
===================================================================
--- trunk/main/depot/core/src/main/net/dpml/depot/DepotHandler.java
2006-03-27 08:15:53 UTC (rev 1272)
+++ trunk/main/depot/core/src/main/net/dpml/depot/DepotHandler.java
2006-03-27 12:03:15 UTC (rev 1273)
@@ -21,6 +21,7 @@
import java.io.IOException;
import java.io.OutputStream;
import java.io.ObjectOutputStream;
+import java.io.BufferedOutputStream;
import java.io.Serializable;
import java.net.Socket;
import java.net.SocketException;
@@ -42,7 +43,8 @@
private static final PID ID = new PID();
private final Socket m_socket;
- //private final ObjectOutputStream m_stream;
+ private final OutputStream m_output;
+ private final ObjectOutputStream m_stream;
/**
* Creation of a new handler instance.
@@ -60,6 +62,8 @@
public DepotHandler( String host, int port ) throws Exception
{
m_socket = new Socket( host, port );
+ m_output = m_socket.getOutputStream();
+ m_stream = new ObjectOutputStream( new BufferedOutputStream(
m_output ) );
}
/**
@@ -67,14 +71,6 @@
*/
public void flush()
{
- //try
- //{
- // m_stream.flush();
- //}
- //catch( Exception e )
- //{
- // e.printStackTrace();
- //}
}
/**
@@ -84,6 +80,14 @@
{
try
{
+ m_output.close();
+ }
+ catch( Exception e )
+ {
+ e.printStackTrace();
+ }
+ try
+ {
m_socket.close();
}
catch( Exception e )
@@ -96,28 +100,30 @@
* Publish a log record.
* @param record the log record
*/
- public synchronized void publish( LogRecord record )
+ public void publish( LogRecord record )
{
- if( m_socket.isClosed() )
+ synchronized( m_socket )
{
- return;
+ if( m_socket.isClosed() )
+ {
+ return;
+ }
+
+ try
+ {
+ LogStatement statement = new LogStatement( ID, record );
+ m_stream.writeObject( statement );
+ m_stream.flush();
+ }
+ catch( SocketException e )
+ {
+ e.printStackTrace();
+ }
+ catch( Exception e )
+ {
+ e.printStackTrace();
+ }
}
- try
- {
- OutputStream output = m_socket.getOutputStream();
- ObjectOutputStream stream = new ObjectOutputStream( output );
- LogStatement statement = new LogStatement( ID, record );
- stream.writeObject( statement );
- stream.flush();
- }
- catch( SocketException e )
- {
- //System.out.println( e.toString() );
- }
- catch( Exception e )
- {
- e.printStackTrace();
- }
}
}
Modified: trunk/main/depot/core/src/main/net/dpml/depot/Main.java
===================================================================
--- trunk/main/depot/core/src/main/net/dpml/depot/Main.java 2006-03-27
08:15:53 UTC (rev 1272)
+++ trunk/main/depot/core/src/main/net/dpml/depot/Main.java 2006-03-27
12:03:15 UTC (rev 1273)
@@ -84,21 +84,40 @@
private Main( String[] arguments )
{
- String[] args = arguments;
-
+ String[] args = processSystemProperties( arguments );
+
//
// check for debug mode
//
if( CLIHelper.isOptionPresent( args, "-debug" ) )
{
- System.setProperty( "dpml.logging.config",
"local:properties:dpml/transit/debug" );
args = CLIHelper.consolidate( args, "-debug" );
System.setProperty( "dpml.debug", "true" );
+ }
+
+ if( "true".equals( System.getProperty( "dpml.debug" ) ) )
+ {
m_debug = true;
+ }
+
+ if( null == System.getProperty( "dpml.logging.config" ) )
+ {
+ if( m_debug )
+ {
+ System.setProperty( "dpml.logging.config",
"local:properties:dpml/transit/debug" );
+ }
+ else
+ {
+ System.setProperty( "dpml.logging.config",
"local:properties:dpml/transit/default" );
+ }
+ }
+
+ if( m_debug )
+ {
for( int i=0; i<arguments.length; i++ )
{
- System.out.println( " arg[" + i + "] " + arguments[i] );
+ getLogger().debug( "arg[" + i + "]: " + arguments[i] );
}
}
@@ -132,38 +151,34 @@
}
}
- private void handleBuild( String[] arguments )
+ private void handleBuild( String[] args )
{
- String[] args = processSystemProperties( arguments );
String name = "build";
String spec = "@DEPOT-BUILDER-URI@";
handlePlugin( name, spec, args, false );
}
- private void handleMetro( String[] arguments )
+ private void handleMetro( String[] args )
{
- String[] args = processSystemProperties( arguments );
String name = "exec";
String spec = "@DEPOT-EXEC-URI@";
handlePlugin( name, spec, args, true );
}
- private void handleTransit( String[] arguments )
+ private void handleTransit( String[] args )
{
- String[] args = processSystemProperties( arguments );
String name = "transit";
String spec = "@TRANSIT-CONSOLE-URI@";
handlePlugin( name, spec, args, false );
}
- private void handleStation( String[] arguments )
+ private void handleStation( String[] args )
{
new File( Transit.DPML_DATA, "logs/station" ).mkdirs();
- String[] args = processSystemProperties( arguments );
- if( CLIHelper.isOptionPresent( arguments, "-server" ) )
+ if( CLIHelper.isOptionPresent( args, "-server" ) )
{
String name = "station";
- args = CLIHelper.consolidate( arguments, "-server" );
+ args = CLIHelper.consolidate( args, "-server" );
String spec = "@DEPOT-STATION-SERVER-URI@";
handlePlugin( name, spec, args, true );
}
@@ -171,7 +186,7 @@
{
String name = "station";
String spec = "@DEPOT-STATION-URI@";
- handlePlugin( name, spec, arguments, false );
+ handlePlugin( name, spec, args, false );
}
}
Modified:
trunk/main/station/server/src/main/net/dpml/station/server/LoggingServer.java
===================================================================
---
trunk/main/station/server/src/main/net/dpml/station/server/LoggingServer.java
2006-03-27 08:15:53 UTC (rev 1272)
+++
trunk/main/station/server/src/main/net/dpml/station/server/LoggingServer.java
2006-03-27 12:03:15 UTC (rev 1273)
@@ -23,6 +23,7 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.ObjectInputStream;
+import java.io.BufferedInputStream;
import java.util.logging.Logger;
import java.util.logging.LogRecord;
import java.util.logging.Formatter;
@@ -69,26 +70,9 @@
try
{
Socket socket = m_server.accept();
- InputStream input = socket.getInputStream();
- ObjectInputStream stream = new ObjectInputStream( input );
- Object object = stream.readObject();
- if( object instanceof LogStatement )
- {
- LogStatement statement = (LogStatement) object;
- PID pid = statement.getPID();
- if( !PID.equals( pid ) )
- {
- int id = pid.getValue();
- LogRecord record = statement.getLogRecord();
- String raw = record.getMessage();
- String message = "$[" + id + "] " + raw;
- record.setMessage( message );
- Logger logger = getNamedLogger( record );
- logger.log( record );
- }
- }
- input.close();
- socket.close();
+ RequestHandler handler = new RequestHandler( socket );
+ Thread thread = new Thread( handler );
+ thread.start();
}
catch( Throwable e )
{
@@ -114,5 +98,68 @@
return Logger.getAnonymousLogger();
}
}
+
+ class RequestHandler implements Runnable
+ {
+ private final Socket m_socket;
+
+ private RequestHandler( Socket socket )
+ {
+ m_socket = socket;
+ }
+
+ public void run()
+ {
+ try
+ {
+ InputStream input = m_socket.getInputStream();
+ BufferedInputStream buffer = new BufferedInputStream( input
);
+ ObjectInputStream ois = new ObjectInputStream( buffer );
+ while( true )
+ {
+ Object object = ois.readObject();
+ if( object instanceof LogStatement )
+ {
+ LogStatement statement = (LogStatement) object;
+ PID pid = statement.getPID();
+ if( !PID.equals( pid ) )
+ {
+ int id = pid.getValue();
+ LogRecord record = statement.getLogRecord();
+ String raw = record.getMessage();
+ String message = "$[" + id + "] " + raw;
+ record.setMessage( message );
+ Logger logger = getNamedLogger( record );
+ logger.log( record );
+ }
+ }
+ }
+ //input.close();
+ //m_socket.close();
+ }
+ catch( ClassNotFoundException e )
+ {
+ System.out.println( e.toString() );
+ }
+ catch( IOException ioe )
+ {
+ System.out.println( "read failed: " + ioe.toString() );
+ }
+ }
+
+ private Logger getNamedLogger( LogRecord record )
+ {
+ String name = record.getLoggerName();
+ if( null != name )
+ {
+ return Logger.getLogger( name );
+ }
+ else
+ {
+ return Logger.getAnonymousLogger();
+ }
+ }
+ }
+
}
Modified:
trunk/main/station/server/src/main/net/dpml/station/server/RemoteApplication.java
===================================================================
---
trunk/main/station/server/src/main/net/dpml/station/server/RemoteApplication.java
2006-03-27 08:15:53 UTC (rev 1272)
+++
trunk/main/station/server/src/main/net/dpml/station/server/RemoteApplication.java
2006-03-27 12:03:15 UTC (rev 1273)
@@ -333,19 +333,11 @@
properties.setProperty( "dpml.station.key", m_id );
properties.setProperty( "dpml.subprocess", "true" );
properties.setProperty( "dpml.station.partition", "depot.station." +
m_id );
- properties.setProperty( "dpml.station.logging.dir",
"${dpml.data}/logs/station" );
- //
- // BIG ISSUE: if the following is enabled we hit errors that seem to
be
- // related to the fact the the logging handler is using logging (via
- // RMI before the log handler is established. In effect we need to
rethink
- // the general model for log message aggregation.
- //
- //if( "true".equals( System.getProperty( "dpml.debug" ) ) )
- //{
- // properties.setProperty( "dpml.debug", "true" );
- //}
- //
+ if( "true".equals( System.getProperty( "dpml.debug" ) ) )
+ {
+ properties.setProperty( "dpml.debug", "true" );
+ }
if( null == properties.getProperty( "java.util.logging.config.class"
) )
{
@@ -354,7 +346,12 @@
"net.dpml.depot.DepotLoggingConfiguration" );
}
- properties.setProperty( "dpml.logging.config",
"local:properties:dpml/station/application" );
+ if( null == properties.getProperty( "dpml.logging.config" ) )
+ {
+ properties.setProperty(
+ "dpml.logging.config",
+ "local:properties:dpml/station/application" );
+ }
Enumeration names = properties.propertyNames();
while( names.hasMoreElements() )
- r1273 - in trunk/main: depot/core/src/main/net/dpml/depot station/server/src/main/net/dpml/station/server, mcconnell at BerliOS, 03/27/2006
Archive powered by MHonArc 2.6.24.