notify-dpml AT lists.ibiblio.org
Subject: DPML Notify
List archive
svn commit: r2862 - in development/laboratory/users/niclas/osgi/console: . api/src/main/net/dpml/console commands commands/src/main/net/dpml/console/commands commands/src/main/net/dpml/console/commands/bundle commands/src/test/net/dpml/console/test impl impl/src/main/net/dpml/console/impl socket socket/src/main/net/dpml/console/socket xmpp
- From: niclas AT hedhman.org
- To: notify-dpml AT lists.ibiblio.org
- Subject: svn commit: r2862 - in development/laboratory/users/niclas/osgi/console: . api/src/main/net/dpml/console commands commands/src/main/net/dpml/console/commands commands/src/main/net/dpml/console/commands/bundle commands/src/test/net/dpml/console/test impl impl/src/main/net/dpml/console/impl socket socket/src/main/net/dpml/console/socket xmpp
- Date: Wed, 15 Jun 2005 07:05:10 -0400
Author: niclas AT hedhman.org
Date: Wed Jun 15 07:05:09 2005
New Revision: 2862
Added:
development/laboratory/users/niclas/osgi/console/api/src/main/net/dpml/console/MinimalLogger.java
(contents, props changed)
development/laboratory/users/niclas/osgi/console/commands/src/main/net/dpml/console/commands/CommandActivator.java
(contents, props changed)
development/laboratory/users/niclas/osgi/console/commands/src/main/net/dpml/console/commands/LogEnabled.java
(contents, props changed)
development/laboratory/users/niclas/osgi/console/socket/src/main/net/dpml/console/socket/SocketActivator.java
(contents, props changed)
Removed:
development/laboratory/users/niclas/osgi/console/commands/src/main/net/dpml/console/commands/bundle/
Modified:
development/laboratory/users/niclas/osgi/console/commands/build.xml
development/laboratory/users/niclas/osgi/console/commands/src/main/net/dpml/console/commands/DeployCmd.java
development/laboratory/users/niclas/osgi/console/commands/src/main/net/dpml/console/commands/DummyCmd.java
development/laboratory/users/niclas/osgi/console/commands/src/main/net/dpml/console/commands/EchoCmd.java
development/laboratory/users/niclas/osgi/console/commands/src/main/net/dpml/console/commands/ExitCmd.java
development/laboratory/users/niclas/osgi/console/commands/src/main/net/dpml/console/commands/HelpCmd.java
development/laboratory/users/niclas/osgi/console/commands/src/main/net/dpml/console/commands/ListCmd.java
development/laboratory/users/niclas/osgi/console/commands/src/main/net/dpml/console/commands/LoginCmd.java
development/laboratory/users/niclas/osgi/console/commands/src/main/net/dpml/console/commands/RedeployCmd.java
development/laboratory/users/niclas/osgi/console/commands/src/main/net/dpml/console/commands/SelectCmd.java
development/laboratory/users/niclas/osgi/console/commands/src/main/net/dpml/console/commands/ShowModelCmd.java
development/laboratory/users/niclas/osgi/console/commands/src/main/net/dpml/console/commands/ThreadCmd.java
development/laboratory/users/niclas/osgi/console/commands/src/main/net/dpml/console/commands/UndeployCmd.java
development/laboratory/users/niclas/osgi/console/commands/src/test/net/dpml/console/test/EchoCommandTestCase.java
development/laboratory/users/niclas/osgi/console/impl/build.xml
development/laboratory/users/niclas/osgi/console/impl/src/main/net/dpml/console/impl/CommandInterpreterImpl.java
development/laboratory/users/niclas/osgi/console/impl/src/main/net/dpml/console/impl/ConsoleActivator.java
development/laboratory/users/niclas/osgi/console/impl/src/main/net/dpml/console/impl/ConsoleImpl.java
development/laboratory/users/niclas/osgi/console/index.xml
development/laboratory/users/niclas/osgi/console/socket/build.xml
development/laboratory/users/niclas/osgi/console/socket/src/main/net/dpml/console/socket/SocketCommandConnection.java
development/laboratory/users/niclas/osgi/console/socket/src/main/net/dpml/console/socket/SocketProvider.java
development/laboratory/users/niclas/osgi/console/xmpp/build.xml
Log:
Getting the various Bundles to co-operate.
Added:
development/laboratory/users/niclas/osgi/console/api/src/main/net/dpml/console/MinimalLogger.java
==============================================================================
--- (empty file)
+++
development/laboratory/users/niclas/osgi/console/api/src/main/net/dpml/console/MinimalLogger.java
Wed Jun 15 07:05:09 2005
@@ -0,0 +1,33 @@
+package net.dpml.console;
+
+import org.osgi.service.log.LogService;
+import org.osgi.framework.ServiceReference;
+
+public class MinimalLogger
+ implements LogService
+{
+ static private String[] LEVEL = new String[]
+ {
+ "", "ERROR", "WARNING", "INFO", "DEBUG"
+ };
+
+ public void log( int i, String s )
+ {
+ System.out.println( LEVEL[ i ] + " : " + s );
+ }
+
+ public void log( int i, String s, Throwable throwable )
+ {
+ System.out.println( LEVEL[ i ] + " : " + s );
+ }
+
+ public void log( ServiceReference serviceReference, int i, String s )
+ {
+ System.out.println( LEVEL[ i ] + " : " + s );
+ }
+
+ public void log( ServiceReference serviceReference, int i, String s,
Throwable throwable )
+ {
+ System.out.println( LEVEL[ i ] + " : " + s );
+ }
+}
Modified: development/laboratory/users/niclas/osgi/console/commands/build.xml
==============================================================================
--- development/laboratory/users/niclas/osgi/console/commands/build.xml
(original)
+++ development/laboratory/users/niclas/osgi/console/commands/build.xml Wed
Jun 15 07:05:09 2005
@@ -6,9 +6,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.dpml.net/central/about/legal/
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -21,4 +21,60 @@
<transit:import uri="artifact:template:dpml/magic/standard"/>
+ <target name="build" depends="standard.build">
+ <mkdir dir="target/manifest/" />
+ <x:property name="version" feature="version" />
+ <tstamp/>
+ <x:path mode="runtime" id="runtime-path" />
+ <pathconvert
+ dirsep="/"
+ pathsep=","
+ property="classpath"
+ refid="runtime-path"
+ >
+ <mapper type="flatten"/>
+ </pathconvert>
+ <manifest file="target/manifest/MANIFEST.MF" >
+ <attribute name="Built-By" value="${user.name}"/>
+ <attribute name="Specification-Title" value=""/>
+ <attribute name="Specification-Version" value="1.0"/>
+ <attribute name="Specification-Vendor" value="Digital Product Meta
Library"/>
+ <attribute name="Implementation-Title" value="DPML Console OSGi
Bundle"/>
+ <attribute name="Implementation-Version" value="${version}
${DSTAMP}"/>
+ <attribute name="Implementation-Vendor" value="Digital Product Meta
Library"/>
+
+ <attribute name="Bundle-Activator"
value="net.dpml.console.commands.CommandActivator" />
+ <attribute name="Bundle-Category" value="management, dpml-console"/>
+ <attribute name="Bundle-ClassPath" value=".,${classpath}"/>
+ <attribute name="Bundle-ContactAddress"
value="http://www.dpml.net/about"/>
+ <attribute name="Bundle-Copyright" value="Copyright 2005 Digital
Product Meta Library"/>
+ <attribute name="Bundle-Description" value="DPML command console for
management of running Metro instances."/>
+ <attribute name="Bundle-DocURL"
value="http://planet.dpml.net/osgi/console"/>
+ <attribute name="Bundle-Name" value="DPML Console Commands"/>
+ <!--
+ <attribute name="Bundle-RequiredExecutionEnvironment" value="J2SE"/>
+ -->
+ <attribute name="Bundle-UpdateLocation"
value="file:///home/niclas/.dpml/data/cache/dpml/planet/console/commands/jars/dpml-console-commands-SNAPSHOT.jar"/>
+ <attribute name="Bundle-Vendor" value="DPML"/>
+ <attribute name="Bundle-Version" value="${version}"/>
+ <attribute name="Import-Package" value="org.osgi.service.log,
net.dpml.console"/>
+ <attribute name="Export-Package" value="net.dpml.console"/>
+ </manifest>
+ </target>
+
+ <target name="package" depends="standard.package">
+ <x:replicate todir="target/bundle-content/" flatten="true"/>
+ <x:property name="jarfilename" feature="filename" />
+ <x:property name="transitdir" feature="spec" key="dpml-transit-main" />
+ <jar destfile="target/deliverables/jars/${jarfilename}"
+ manifest="target/manifest/MANIFEST.MF" >
+ <fileset dir="target/classes/" >
+ <include name="**" />
+ </fileset>
+ <fileset dir="target/bundle-content/" >
+ <include name="**/*.jar" />
+ </fileset>
+ </jar>
+ </target>
+
</project>
Added:
development/laboratory/users/niclas/osgi/console/commands/src/main/net/dpml/console/commands/CommandActivator.java
==============================================================================
--- (empty file)
+++
development/laboratory/users/niclas/osgi/console/commands/src/main/net/dpml/console/commands/CommandActivator.java
Wed Jun 15 07:05:09 2005
@@ -0,0 +1,159 @@
+package net.dpml.console.commands;
+
+import net.dpml.console.ConsoleCommand;
+import net.dpml.console.MinimalLogger;
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceRegistration;
+import org.osgi.framework.ServiceReference;
+import org.osgi.service.log.LogService;
+import org.osgi.util.tracker.ServiceTracker;
+import org.osgi.util.tracker.ServiceTrackerCustomizer;
+
+import java.util.Hashtable;
+import java.util.ArrayList;
+import java.util.Iterator;
+
+public class CommandActivator
+ implements BundleActivator
+{
+ static final LogService MINIMAL_LOGGER = new MinimalLogger();
+
+ private LogService m_Logger;
+
+ private BundleContext m_BundleContext;
+ private ArrayList m_Commands;
+
+ private ServiceRegistration m_Undeploy;
+ private ServiceRegistration m_Deploy;
+ private ServiceRegistration m_Dummy1;
+ private ServiceRegistration m_Dummy2;
+ private ServiceRegistration m_Echo;
+ private ServiceRegistration m_Exit;
+ private ServiceRegistration m_Quit;
+ private ServiceRegistration m_Help;
+ private ServiceRegistration m_List1;
+ private ServiceRegistration m_List2;
+ private ServiceRegistration m_Login;
+ private ServiceRegistration m_Redploy;
+ private ServiceRegistration m_Select;
+ private ServiceRegistration m_Cd;
+ private ServiceRegistration m_ShowModels;
+ private ServiceRegistration m_ShowThreads;
+ private ServiceTracker m_LogTracker;
+
+ public void start( BundleContext bundleContext )
+ throws Exception
+ {
+ m_BundleContext = bundleContext;
+ m_Commands = new ArrayList();
+ m_LogTracker = new ServiceTracker( bundleContext,
"org.osgi.service.log.LogService", new LogServiceTracking() );
+ m_LogTracker.open();
+ m_Deploy = register( new DeployCmd( "deploy" ) );
+ m_Dummy1 = register( new DummyCmd( "dummy" ) );
+ m_Dummy2 = register( new DummyCmd( "" ) );
+ m_Echo = register( new EchoCmd( "echo" ) );
+ m_Exit = register( new ExitCmd( "exit" ) );
+ m_Quit = register( new ExitCmd( "quit" ) );
+ m_Help = register( new HelpCmd( "help" ) );
+ m_List1 = register( new ListCmd( "list" ) );
+ m_List2 = register( new ListCmd( "ls" ) );
+ m_Login = register( new ListCmd( "login" ) );
+ m_Redploy = register( new RedeployCmd( "redeploy" ));
+ m_Select = register( new SelectCmd( "select" ) );
+ m_Cd = register( new SelectCmd( "cd" ) );
+ m_ShowModels = register( new ShowModelCmd( "show model" ) );
+ m_ShowThreads = register( new ThreadCmd( "show threads" ));
+ m_Undeploy = register( new UndeployCmd( "undeploy" ) );
+ }
+
+ private ServiceRegistration register( ConsoleCommand cmd )
+ {
+ synchronized( this )
+ {
+ m_Commands.add( cmd );
+ if( cmd instanceof LogEnabled )
+ {
+ LogEnabled logEnabled = (LogEnabled) cmd;
+ if( m_Logger == null )
+ logEnabled.setLogger( MINIMAL_LOGGER );
+ else
+ logEnabled.setLogger( m_Logger );
+ }
+ Hashtable dict = new Hashtable();
+ dict.put( "Name", cmd.getName() );
+ String name = "net.dpml.console.ConsoleCommand";
+ return m_BundleContext.registerService( name, cmd, dict );
+ }
+ }
+
+ public void stop( BundleContext bundleContext )
+ throws Exception
+ {
+ m_Undeploy.unregister();
+ m_Deploy.unregister();
+ m_Dummy1.unregister();
+ m_Dummy2.unregister();
+ m_Echo.unregister();
+ m_Exit.unregister();
+ m_Quit.unregister();
+ m_Help.unregister();
+ m_List1.unregister();
+ m_List2.unregister();
+ m_Login.unregister();
+ m_Redploy.unregister();
+ m_Select.unregister();
+ m_Cd.unregister();
+ m_ShowModels.unregister();
+ m_ShowThreads.unregister();
+ }
+
+ private class LogServiceTracking
+ implements ServiceTrackerCustomizer
+ {
+ public Object addingService( ServiceReference reference )
+ {
+ Object service = m_BundleContext.getService( reference );
+ m_Logger = (LogService) service;
+ synchronized( this )
+ {
+ Iterator list = m_Commands.iterator();
+ while( list.hasNext() )
+ {
+ Object command = list.next();
+ if( command instanceof LogEnabled )
+ {
+ ((LogEnabled) command).setLogger( m_Logger );
+ }
+ }
+ return m_Logger;
+ }
+ }
+
+ public void modifiedService( ServiceReference serviceReference,
Object value )
+ {
+ }
+
+ public void removedService( ServiceReference serviceReference,
Object value )
+ {
+ m_Logger = null;
+ resetLoggers();
+ }
+ }
+
+ private void resetLoggers()
+ {
+ synchronized( this )
+ {
+ Iterator list = m_Commands.iterator();
+ while( list.hasNext() )
+ {
+ Object command = list.next();
+ if( command instanceof LogEnabled )
+ {
+ ((LogEnabled) command).setLogger( MINIMAL_LOGGER );
+ }
+ }
+ }
+ }
+}
Modified:
development/laboratory/users/niclas/osgi/console/commands/src/main/net/dpml/console/commands/DeployCmd.java
==============================================================================
---
development/laboratory/users/niclas/osgi/console/commands/src/main/net/dpml/console/commands/DeployCmd.java
(original)
+++
development/laboratory/users/niclas/osgi/console/commands/src/main/net/dpml/console/commands/DeployCmd.java
Wed Jun 15 07:05:09 2005
@@ -21,6 +21,7 @@
import net.dpml.console.ConsoleCommand;
import org.osgi.service.cm.ConfigurationException;
import org.osgi.service.cm.ManagedService;
+import org.osgi.service.log.LogService;
import java.io.BufferedReader;
import java.io.BufferedWriter;
@@ -31,9 +32,10 @@
/**
*/
public class DeployCmd
- implements ConsoleCommand, ManagedService
+ implements ConsoleCommand, LogEnabled, ManagedService
{
private String m_Name;
+ private LogService m_Logger;
public DeployCmd( String name )
{
@@ -54,6 +56,8 @@
public void execute( Map context, BufferedReader input, BufferedWriter
output, String[] arguments )
throws Exception
{
+ m_Logger.log( LogService.LOG_DEBUG, "DeployCmd.execute() " );
+
if( arguments.length == 0 )
throw new CommandException( "block must be specified." );
@@ -94,5 +98,15 @@
m_Name = newName;
}
}
+
+ public LogService getLogger()
+ {
+ return m_Logger;
+ }
+
+ public void setLogger( LogService logger )
+ {
+ m_Logger = logger;
+ }
}
Modified:
development/laboratory/users/niclas/osgi/console/commands/src/main/net/dpml/console/commands/DummyCmd.java
==============================================================================
---
development/laboratory/users/niclas/osgi/console/commands/src/main/net/dpml/console/commands/DummyCmd.java
(original)
+++
development/laboratory/users/niclas/osgi/console/commands/src/main/net/dpml/console/commands/DummyCmd.java
Wed Jun 15 07:05:09 2005
@@ -16,16 +16,18 @@
package net.dpml.console.commands;
import net.dpml.console.ConsoleCommand;
+import org.osgi.service.log.LogService;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.util.Map;
public class DummyCmd
- implements ConsoleCommand
+ implements LogEnabled, ConsoleCommand
{
private String m_Name;
-
+ private LogService m_Logger;
+
public DummyCmd( String name )
{
@@ -46,7 +48,18 @@
public void execute( Map context, BufferedReader input, BufferedWriter
output, String[] arguments )
throws Exception
{
+ m_Logger.log( LogService.LOG_DEBUG, "DummyCmd.execute() " );
output.newLine();
output.flush();
}
+
+ public LogService getLogger()
+ {
+ return m_Logger;
+ }
+
+ public void setLogger( LogService logger )
+ {
+ m_Logger = logger;
+ }
}
Modified:
development/laboratory/users/niclas/osgi/console/commands/src/main/net/dpml/console/commands/EchoCmd.java
==============================================================================
---
development/laboratory/users/niclas/osgi/console/commands/src/main/net/dpml/console/commands/EchoCmd.java
(original)
+++
development/laboratory/users/niclas/osgi/console/commands/src/main/net/dpml/console/commands/EchoCmd.java
Wed Jun 15 07:05:09 2005
@@ -16,16 +16,18 @@
package net.dpml.console.commands;
import net.dpml.console.ConsoleCommand;
+import org.osgi.service.log.LogService;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.util.Map;
public class EchoCmd
- implements ConsoleCommand
+ implements LogEnabled, ConsoleCommand
{
private String m_Name;
-
+ private LogService m_Logger;
+
public EchoCmd( String name )
{
m_Name = name;
@@ -45,6 +47,7 @@
public void execute( Map context, BufferedReader input, BufferedWriter
output, String[] arguments )
throws Exception
{
+ m_Logger.log( LogService.LOG_DEBUG, "EchoCmd.execute() " );
output.newLine();
output.write( "echo: " );
for( int i=0 ; i < arguments.length ; i++ )
@@ -55,4 +58,14 @@
output.newLine();
output.flush();
}
+
+ public LogService getLogger()
+ {
+ return m_Logger;
+ }
+
+ public void setLogger( LogService logger )
+ {
+ m_Logger = logger;
+ }
}
Modified:
development/laboratory/users/niclas/osgi/console/commands/src/main/net/dpml/console/commands/ExitCmd.java
==============================================================================
---
development/laboratory/users/niclas/osgi/console/commands/src/main/net/dpml/console/commands/ExitCmd.java
(original)
+++
development/laboratory/users/niclas/osgi/console/commands/src/main/net/dpml/console/commands/ExitCmd.java
Wed Jun 15 07:05:09 2005
@@ -16,6 +16,7 @@
package net.dpml.console.commands;
import net.dpml.console.ConsoleCommand;
+import org.osgi.service.log.LogService;
import java.io.BufferedReader;
import java.io.BufferedWriter;
@@ -24,10 +25,11 @@
/**
*/
public class ExitCmd
- implements ConsoleCommand
+ implements LogEnabled, ConsoleCommand
{
private String m_Name;
-
+ private LogService m_Logger;
+
public ExitCmd( String name )
{
m_Name = name;
@@ -47,9 +49,20 @@
public void execute( Map contxt, BufferedReader input, BufferedWriter
output, String[] arguments )
throws Exception
{
+ m_Logger.log( LogService.LOG_DEBUG, "ExitCmd.execute() " );
output.write( "Logging out..." );
output.newLine();
output.flush();
throw new InterruptedException( "Exit the session." );
}
+
+ public LogService getLogger()
+ {
+ return m_Logger;
+ }
+
+ public void setLogger( LogService logger )
+ {
+ m_Logger = logger;
+ }
}
Modified:
development/laboratory/users/niclas/osgi/console/commands/src/main/net/dpml/console/commands/HelpCmd.java
==============================================================================
---
development/laboratory/users/niclas/osgi/console/commands/src/main/net/dpml/console/commands/HelpCmd.java
(original)
+++
development/laboratory/users/niclas/osgi/console/commands/src/main/net/dpml/console/commands/HelpCmd.java
Wed Jun 15 07:05:09 2005
@@ -18,6 +18,7 @@
import net.dpml.console.Console;
import net.dpml.console.ConsoleCommand;
+import org.osgi.service.log.LogService;
import java.io.BufferedReader;
import java.io.BufferedWriter;
@@ -27,9 +28,10 @@
/**
*/
public class HelpCmd
- implements ConsoleCommand
+ implements LogEnabled, ConsoleCommand
{
private String m_Name;
+ private LogService m_Logger;
public HelpCmd( String name )
{
@@ -50,6 +52,7 @@
public void execute( Map context, BufferedReader input, BufferedWriter
output, String[] arguments )
throws Exception
{
+ m_Logger.log( LogService.LOG_DEBUG, "HelpCmd.execute() " );
Console console = (Console) context.get( "Console" );
output.newLine();
if( arguments.length == 0 )
@@ -80,4 +83,14 @@
output.newLine();
output.flush();
}
+
+ public LogService getLogger()
+ {
+ return m_Logger;
+ }
+
+ public void setLogger( LogService logger )
+ {
+ m_Logger = logger;
+ }
}
Modified:
development/laboratory/users/niclas/osgi/console/commands/src/main/net/dpml/console/commands/ListCmd.java
==============================================================================
---
development/laboratory/users/niclas/osgi/console/commands/src/main/net/dpml/console/commands/ListCmd.java
(original)
+++
development/laboratory/users/niclas/osgi/console/commands/src/main/net/dpml/console/commands/ListCmd.java
Wed Jun 15 07:05:09 2005
@@ -18,18 +18,20 @@
import net.dpml.composition.model.ContainmentModel;
import net.dpml.composition.model.DeploymentModel;
import net.dpml.console.ConsoleCommand;
+import org.osgi.service.log.LogService;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.util.Map;
public class ListCmd
- implements ConsoleCommand
+ implements LogEnabled, ConsoleCommand
{
String LINE =
"\n-----------------------------------------------------------";
private String m_Name;
-
+ private LogService m_Logger;
+
public ListCmd( String name )
{
m_Name = name;
@@ -49,6 +51,7 @@
public void execute( Map context, BufferedReader input, BufferedWriter
output, String[] arguments )
throws Exception
{
+ m_Logger.log( LogService.LOG_DEBUG, "ListCmd.execute() " );
output.newLine();
ContainmentModel current = (ContainmentModel) context.get(
"CurrentContainer" );
String path;
@@ -72,5 +75,15 @@
output.newLine();
output.flush();
}
+
+ public LogService getLogger()
+ {
+ return m_Logger;
+ }
+
+ public void setLogger( LogService logger )
+ {
+ m_Logger = logger;
+ }
}
Added:
development/laboratory/users/niclas/osgi/console/commands/src/main/net/dpml/console/commands/LogEnabled.java
==============================================================================
--- (empty file)
+++
development/laboratory/users/niclas/osgi/console/commands/src/main/net/dpml/console/commands/LogEnabled.java
Wed Jun 15 07:05:09 2005
@@ -0,0 +1,11 @@
+package net.dpml.console.commands;
+
+import org.osgi.service.log.LogService;
+
+public interface LogEnabled
+{
+
+ LogService getLogger();
+
+ void setLogger( LogService logger );
+}
Modified:
development/laboratory/users/niclas/osgi/console/commands/src/main/net/dpml/console/commands/LoginCmd.java
==============================================================================
---
development/laboratory/users/niclas/osgi/console/commands/src/main/net/dpml/console/commands/LoginCmd.java
(original)
+++
development/laboratory/users/niclas/osgi/console/commands/src/main/net/dpml/console/commands/LoginCmd.java
Wed Jun 15 07:05:09 2005
@@ -32,14 +32,16 @@
import net.dpml.service.ServiceException;
import net.dpml.service.ServiceManager;
+import org.osgi.service.log.LogService;
/**
*/
public class LoginCmd
- implements ConsoleCommand
+ implements LogEnabled, ConsoleCommand
{
private String m_Password;
private String m_Name;
+ private LogService m_Logger;
public LoginCmd( String name, String rootPassword )
{
@@ -61,6 +63,7 @@
public void execute( Map context, BufferedReader input, BufferedWriter
output, String[] arguments )
throws Exception
{
+ m_Logger.log( LogService.LOG_DEBUG, "LoginCmd.execute() " );
output.write( "Password:" );
output.flush();
String password = input.readLine();
@@ -75,4 +78,14 @@
output.newLine();
output.flush();
}
+
+ public LogService getLogger()
+ {
+ return m_Logger;
+ }
+
+ public void setLogger( LogService logger )
+ {
+ m_Logger = logger;
+ }
}
Modified:
development/laboratory/users/niclas/osgi/console/commands/src/main/net/dpml/console/commands/RedeployCmd.java
==============================================================================
---
development/laboratory/users/niclas/osgi/console/commands/src/main/net/dpml/console/commands/RedeployCmd.java
(original)
+++
development/laboratory/users/niclas/osgi/console/commands/src/main/net/dpml/console/commands/RedeployCmd.java
Wed Jun 15 07:05:09 2005
@@ -16,6 +16,7 @@
package net.dpml.console.commands;
import net.dpml.console.ConsoleCommand;
+import org.osgi.service.log.LogService;
import java.io.BufferedReader;
import java.io.BufferedWriter;
@@ -24,9 +25,10 @@
/**
*/
public class RedeployCmd
- implements ConsoleCommand
+ implements LogEnabled, ConsoleCommand
{
private String m_Name;
+ private LogService m_Logger;
public RedeployCmd( String name )
{
@@ -47,9 +49,20 @@
public void execute( Map context, BufferedReader input, BufferedWriter
output, String[] arguments )
throws Exception
{
+ m_Logger.log( LogService.LOG_DEBUG, "RedeployCmd.execute() " );
output.write( "Not implemented yet!" );
output.newLine();
output.flush();
}
+
+ public LogService getLogger()
+ {
+ return m_Logger;
+ }
+
+ public void setLogger( LogService logger )
+ {
+ m_Logger = logger;
+ }
}
Modified:
development/laboratory/users/niclas/osgi/console/commands/src/main/net/dpml/console/commands/SelectCmd.java
==============================================================================
---
development/laboratory/users/niclas/osgi/console/commands/src/main/net/dpml/console/commands/SelectCmd.java
(original)
+++
development/laboratory/users/niclas/osgi/console/commands/src/main/net/dpml/console/commands/SelectCmd.java
Wed Jun 15 07:05:09 2005
@@ -18,6 +18,7 @@
import net.dpml.composition.model.ContainmentModel;
import net.dpml.composition.model.DeploymentModel;
import net.dpml.console.ConsoleCommand;
+import org.osgi.service.log.LogService;
import java.io.BufferedReader;
import java.io.BufferedWriter;
@@ -26,10 +27,11 @@
/**
*/
public class SelectCmd
- implements ConsoleCommand
+ implements LogEnabled, ConsoleCommand
{
private String m_Name;
-
+ private LogService m_Logger;
+
public SelectCmd( String name )
{
m_Name = name;
@@ -49,6 +51,7 @@
public void execute( Map context, BufferedReader input, BufferedWriter
output, String[] arguments )
throws Exception
{
+ m_Logger.log( LogService.LOG_DEBUG, "SelectCmd.execute() " );
if( arguments.length > 0 )
{
ContainmentModel current = (ContainmentModel) context.get(
"CurrentContainer" );
@@ -66,4 +69,14 @@
output.newLine();
output.flush();
}
+
+ public LogService getLogger()
+ {
+ return m_Logger;
+ }
+
+ public void setLogger( LogService logger )
+ {
+ m_Logger = logger;
+ }
}
Modified:
development/laboratory/users/niclas/osgi/console/commands/src/main/net/dpml/console/commands/ShowModelCmd.java
==============================================================================
---
development/laboratory/users/niclas/osgi/console/commands/src/main/net/dpml/console/commands/ShowModelCmd.java
(original)
+++
development/laboratory/users/niclas/osgi/console/commands/src/main/net/dpml/console/commands/ShowModelCmd.java
Wed Jun 15 07:05:09 2005
@@ -19,6 +19,7 @@
import net.dpml.composition.model.ContainmentModel;
import net.dpml.composition.model.DeploymentModel;
import net.dpml.console.ConsoleCommand;
+import org.osgi.service.log.LogService;
import java.io.BufferedReader;
import java.io.BufferedWriter;
@@ -27,12 +28,13 @@
/**
*/
public class ShowModelCmd
- implements ConsoleCommand
+ implements LogEnabled, ConsoleCommand
{
String LINE =
"\n-----------------------------------------------------------";
private String m_Name;
-
+ private LogService m_Logger;
+
public ShowModelCmd( String name )
{
m_Name = name;
@@ -52,6 +54,7 @@
public void execute( Map context, BufferedReader input, BufferedWriter
output, String[] arguments )
throws Exception
{
+ m_Logger.log( LogService.LOG_DEBUG, "ShowModelCmd.execute() " );
output.newLine();
ContainmentModel current = (ContainmentModel) context.get(
"CurrentContainer" );
String path;
@@ -184,5 +187,15 @@
}
return false;
}
+
+ public LogService getLogger()
+ {
+ return m_Logger;
+ }
+
+ public void setLogger( LogService logger )
+ {
+ m_Logger = logger;
+ }
}
Modified:
development/laboratory/users/niclas/osgi/console/commands/src/main/net/dpml/console/commands/ThreadCmd.java
==============================================================================
---
development/laboratory/users/niclas/osgi/console/commands/src/main/net/dpml/console/commands/ThreadCmd.java
(original)
+++
development/laboratory/users/niclas/osgi/console/commands/src/main/net/dpml/console/commands/ThreadCmd.java
Wed Jun 15 07:05:09 2005
@@ -16,16 +16,18 @@
package net.dpml.console.commands;
import net.dpml.console.ConsoleCommand;
+import org.osgi.service.log.LogService;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.util.Map;
public class ThreadCmd
- implements ConsoleCommand
+ implements LogEnabled, ConsoleCommand
{
private String m_Name;
-
+ private LogService m_Logger;
+
public ThreadCmd( String name )
{
m_Name = name;
@@ -45,6 +47,7 @@
public void execute( Map context, BufferedReader input, BufferedWriter
output, String[] arguments )
throws Exception
{
+ m_Logger.log( LogService.LOG_DEBUG, "ThreadCmd.execute() " );
ThreadGroup tg = Thread.currentThread().getThreadGroup();
ThreadGroup root = tg;
while( tg != null )
@@ -62,4 +65,14 @@
}
output.flush();
}
+
+ public LogService getLogger()
+ {
+ return m_Logger;
+ }
+
+ public void setLogger( LogService logger )
+ {
+ m_Logger = logger;
+ }
}
Modified:
development/laboratory/users/niclas/osgi/console/commands/src/main/net/dpml/console/commands/UndeployCmd.java
==============================================================================
---
development/laboratory/users/niclas/osgi/console/commands/src/main/net/dpml/console/commands/UndeployCmd.java
(original)
+++
development/laboratory/users/niclas/osgi/console/commands/src/main/net/dpml/console/commands/UndeployCmd.java
Wed Jun 15 07:05:09 2005
@@ -19,6 +19,7 @@
import net.dpml.composition.model.DeploymentModel;
import net.dpml.console.CommandException;
import net.dpml.console.ConsoleCommand;
+import org.osgi.service.log.LogService;
import java.io.BufferedReader;
import java.io.BufferedWriter;
@@ -27,10 +28,11 @@
/**
*/
public class UndeployCmd
- implements ConsoleCommand
+ implements LogEnabled, ConsoleCommand
{
private String m_Name;
-
+ private LogService m_Logger;
+
public UndeployCmd( String name )
{
m_Name = name;
@@ -50,6 +52,7 @@
public void execute( Map context, BufferedReader input, BufferedWriter
output, String[] arguments )
throws Exception
{
+ m_Logger.log( LogService.LOG_DEBUG, "UndeployCmd.execute() " );
if( arguments.length == 0 )
throw new CommandException( "target must be specified." );
@@ -77,5 +80,15 @@
output.newLine();
output.flush();
}
+
+ public LogService getLogger()
+ {
+ return m_Logger;
+ }
+
+ public void setLogger( LogService logger )
+ {
+ m_Logger = logger;
+ }
}
Modified:
development/laboratory/users/niclas/osgi/console/commands/src/test/net/dpml/console/test/EchoCommandTestCase.java
==============================================================================
---
development/laboratory/users/niclas/osgi/console/commands/src/test/net/dpml/console/test/EchoCommandTestCase.java
(original)
+++
development/laboratory/users/niclas/osgi/console/commands/src/test/net/dpml/console/test/EchoCommandTestCase.java
Wed Jun 15 07:05:09 2005
@@ -17,6 +17,7 @@
import junit.framework.TestCase;
import net.dpml.console.Console;
+import net.dpml.console.MinimalLogger;
import net.dpml.console.commands.EchoCmd;
import java.io.BufferedReader;
@@ -41,6 +42,8 @@
throws Exception
{
m_Command = new EchoCmd( "unit-test" );
+ m_Command.setLogger( new MinimalLogger() );
+
Console console = new TestConsole();
console.addCommand( m_Command );
Modified: development/laboratory/users/niclas/osgi/console/impl/build.xml
==============================================================================
--- development/laboratory/users/niclas/osgi/console/impl/build.xml
(original)
+++ development/laboratory/users/niclas/osgi/console/impl/build.xml Wed
Jun 15 07:05:09 2005
@@ -6,9 +6,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.dpml.net/central/about/legal/
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -43,8 +43,8 @@
<attribute name="Implementation-Version" value="${version}
${DSTAMP}"/>
<attribute name="Implementation-Vendor" value="Digital Product Meta
Library"/>
- <attribute name="Bundle-Activator"
value="net.dpml.console.osgi.ConsoleActivator" />
- <attribute name="Bundle-Category" value="container, platform"/>
+ <attribute name="Bundle-Activator"
value="net.dpml.console.impl.ConsoleActivator" />
+ <attribute name="Bundle-Category" value="management, dpml-console"/>
<attribute name="Bundle-ClassPath" value=".,${classpath}"/>
<attribute name="Bundle-ContactAddress"
value="http://www.dpml.net/about"/>
<attribute name="Bundle-Copyright" value="Copyright 2005 Digital
Product Meta Library"/>
@@ -54,10 +54,11 @@
<!--
<attribute name="Bundle-RequiredExecutionEnvironment" value="J2SE"/>
-->
- <attribute name="Bundle-UpdateLocation"
value="http://repository.dpml.net/classic/dpml/planet/console/jars/dpml-console-bundle.jar"/>
+ <attribute name="Bundle-UpdateLocation"
value="file:///home/niclas/.dpml/data/cache/dpml/planet/console/impl/jars/dpml-console-impl-SNAPSHOT.jar"/>
<attribute name="Bundle-Vendor" value="DPML"/>
<attribute name="Bundle-Version" value="${version}"/>
- <attribute name="Import-Package" value="org.osgi.service.log"/>
+ <attribute name="Import-Package" value="org.osgi.service.log,
net.dpml.console"/>
+ <attribute name="Export-Package" value="net.dpml.console"/>
</manifest>
</target>
Modified:
development/laboratory/users/niclas/osgi/console/impl/src/main/net/dpml/console/impl/CommandInterpreterImpl.java
==============================================================================
---
development/laboratory/users/niclas/osgi/console/impl/src/main/net/dpml/console/impl/CommandInterpreterImpl.java
(original)
+++
development/laboratory/users/niclas/osgi/console/impl/src/main/net/dpml/console/impl/CommandInterpreterImpl.java
Wed Jun 15 07:05:09 2005
@@ -25,6 +25,8 @@
import java.io.IOException;
import java.util.HashMap;
import java.util.StringTokenizer;
+import java.util.Hashtable;
+import java.net.SocketException;
class CommandInterpreterImpl
implements CommandInterpreter, Runnable
@@ -38,55 +40,56 @@
private LogService m_Logger;
private String m_Name;
- CommandInterpreterImpl( String name, BufferedReader input,
BufferedWriter output )
+ CommandInterpreterImpl( String name, BufferedReader input,
BufferedWriter output, Hashtable commands )
{
m_Name = name;
m_Input = input;
m_Output = output;
- m_Commands = new HashMap();
+ m_Commands = new HashMap( commands );
m_Context = new HashMap();
+ m_Context.put( "CurrentNode", "<none>" );
m_Thread = new Thread( this, "Console-" + name );
m_Thread.start();
}
public void close()
{
+ getLogger().log( LogService.LOG_DEBUG, "Closing CommandInterpreter:
" + this );
m_Thread.interrupt();
try
{
m_Output.close();
} catch( IOException e )
{
- if( getLogger() != null )
- {
- getLogger().log( LogService.LOG_WARNING, "Can not close the
Writer: " + m_Name );
- }
+ getLogger().log( LogService.LOG_WARNING, "Can not close the
Writer: " + m_Name );
}
try
{
m_Input.close();
} catch( IOException e )
{
- if( getLogger() != null )
- {
- getLogger().log( LogService.LOG_WARNING, "Can not close the
Reader: " + m_Name );
- }
+ getLogger().log( LogService.LOG_WARNING, "Can not close the
Reader: " + m_Name );
}
m_Login = false;
}
public void addCommand( ConsoleCommand cmd )
{
- m_Commands.put( cmd.getName(), cmd );
+ String commandname = cmd.getName();
+ getLogger().log( LogService.LOG_DEBUG, "Adding Command: " +
commandname );
+ m_Commands.put( commandname, cmd );
}
public void removeCommand( ConsoleCommand cmd )
{
- m_Commands.remove( cmd.getName() );
+ String commandname = cmd.getName();
+ getLogger().log( LogService.LOG_DEBUG, "Removing Command: " +
commandname );
+ m_Commands.remove( commandname );
}
public void removeCommand( String commandname )
{
+ getLogger().log( LogService.LOG_DEBUG, "Removing Command: " +
commandname );
m_Commands.remove( commandname );
}
@@ -107,6 +110,10 @@
} catch( InterruptedException e )
{
running = false;
+ } catch( SocketException e )
+ {
+ getLogger().log( LogService.LOG_INFO, "Socket problem : " +
e.getMessage() );
+ running = false;
} catch( IOException e )
{
String mess = e.getMessage();
@@ -141,7 +148,7 @@
return;
}
}
- errorMessage( "Unknown command. 'help' for available commands." );
+ errorMessage( "Unknown command: " + cmdline + "\n'help' for
available commands." );
}
private String waitForCommandLine()
@@ -180,6 +187,10 @@
LogService getLogger()
{
+ if( m_Logger == null )
+ {
+ return ConsoleActivator.MINIMAL_LOGGER;
+ }
return m_Logger;
}
Modified:
development/laboratory/users/niclas/osgi/console/impl/src/main/net/dpml/console/impl/ConsoleActivator.java
==============================================================================
---
development/laboratory/users/niclas/osgi/console/impl/src/main/net/dpml/console/impl/ConsoleActivator.java
(original)
+++
development/laboratory/users/niclas/osgi/console/impl/src/main/net/dpml/console/impl/ConsoleActivator.java
Wed Jun 15 07:05:09 2005
@@ -18,6 +18,7 @@
import net.dpml.console.CommandConnectionProvider;
import net.dpml.console.ConsoleCommand;
+import net.dpml.console.MinimalLogger;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceReference;
@@ -30,7 +31,7 @@
public class ConsoleActivator
implements BundleActivator
{
- private static final LogService MINIMAL_LOGGER = new MinimalLogger();
+ static final LogService MINIMAL_LOGGER = new MinimalLogger();
private ServiceTracker m_LogTracker;
private ConsoleImpl m_Console;
@@ -47,8 +48,9 @@
m_Console = new ConsoleImpl();
m_Console.setLogger( MINIMAL_LOGGER );
- m_BundleContext.registerService( "net.dpml.console.Console",
m_Console, null );
-
+ String[] intfaces = new String[] { "net.dpml.console.Console",
"net.dpml.console.CommandConnectionListener" };
+ m_BundleContext.registerService( intfaces, m_Console, null );
+
m_LogTracker = new ServiceTracker( bundleContext,
"org.osgi.service.log.LogService", new LogServiceTracking() );
m_LogTracker.open();
@@ -71,7 +73,8 @@
{
public Object addingService( ServiceReference reference )
{
- ConsoleCommand command = (ConsoleCommand)
m_BundleContext.getService( reference );
+ Object service = m_BundleContext.getService( reference );
+ ConsoleCommand command = (ConsoleCommand) service;
m_Console.addCommand( command );
return command;
}
@@ -113,7 +116,8 @@
{
public Object addingService( ServiceReference reference )
{
- LogService logger = (LogService) m_BundleContext.getService(
reference );
+ Object service = m_BundleContext.getService( reference );
+ LogService logger = (LogService) service;
m_Console.setLogger( logger );
return logger;
}
@@ -129,32 +133,4 @@
}
}
- static private class MinimalLogger
- implements LogService
- {
- static private String[] LEVEL = new String[]
- {
- "", "ERROR", "WARNING", "INFO", "DEBUG"
- };
-
- public void log( int i, String s )
- {
- System.out.println( LEVEL[ i ] + " : " + s );
- }
-
- public void log( int i, String s, Throwable throwable )
- {
- System.out.println( LEVEL[ i ] + " : " + s );
- }
-
- public void log( ServiceReference serviceReference, int i, String s )
- {
- System.out.println( LEVEL[ i ] + " : " + s );
- }
-
- public void log( ServiceReference serviceReference, int i, String s,
Throwable throwable )
- {
- System.out.println( LEVEL[ i ] + " : " + s );
- }
- }
}
Modified:
development/laboratory/users/niclas/osgi/console/impl/src/main/net/dpml/console/impl/ConsoleImpl.java
==============================================================================
---
development/laboratory/users/niclas/osgi/console/impl/src/main/net/dpml/console/impl/ConsoleImpl.java
(original)
+++
development/laboratory/users/niclas/osgi/console/impl/src/main/net/dpml/console/impl/ConsoleImpl.java
Wed Jun 15 07:05:09 2005
@@ -56,23 +56,32 @@
m_Interpreters = new ArrayList();
m_Connections = new HashMap();
m_Commands = new Hashtable();
+ m_Welcome = "Welcome to the DPML Console.\nAfter login, type\n\n
help[enter]\n\nfor list of commands";
}
public void updated( Dictionary dictionary )
throws ConfigurationException
{
- if( dictionary == null )
+ getLogger().log( LogService.LOG_INFO, "ConsoleImpl.updated():" +
dictionary );
+
+ if( dictionary != null )
{
- m_Welcome = "Welcome to the DPML Console.\nAfter login, type\n\n
help[enter]\n\nfor list of commands";
+ String setting = (String) dictionary.get( "welcomeText" );
+ if( setting != null )
+ {
+ m_Welcome = setting;
+ }
}
- else
- m_Welcome = (String) dictionary.get( "welcomeText" );
}
public void dispose()
{
- getConnectionProvider().removeCommandConnectionListener( this );
+ getLogger().log( LogService.LOG_INFO, "ConsoleImpl.dispose()" );
+ if( m_ConnectionProvider != null )
+ {
+ m_ConnectionProvider.removeCommandConnectionListener( this );
+ }
Iterator list = m_Interpreters.iterator();
while( list.hasNext() )
{
@@ -84,6 +93,7 @@
public void connected( CommandConnection connection )
{
String name = connection.getUser();
+ getLogger().log( LogService.LOG_INFO, "ConsoleImpl.connected() : " +
name );
try
{
BufferedReader input = connection.getInputReader();
@@ -92,7 +102,7 @@
synchronized( m_Connections )
{
- m_Interpreter = new CommandInterpreterImpl( name, input,
output );
+ m_Interpreter = new CommandInterpreterImpl( name, input,
output, m_Commands );
m_Connections.put( connection, m_Interpreter );
}
} catch( IOException e )
@@ -103,6 +113,7 @@
public void connectionLost( CommandConnection connection )
{
+ getLogger().log( LogService.LOG_INFO, "ConsoleImpl.connectionLost()
: " + connection );
synchronized( m_Connections )
{
CommandInterpreter intp = (CommandInterpreter)
m_Connections.get( connection );
@@ -112,6 +123,7 @@
public void addCommand( ConsoleCommand cmd )
{
+ getLogger().log( LogService.LOG_INFO, "ConsoleImpl.addCommand() : "
+ cmd.getName() );
String name = cmd.getName();
m_Commands.put( name, cmd );
synchronized( m_Interpreters )
@@ -127,6 +139,7 @@
public void removeCommand( ConsoleCommand cmd )
{
+ getLogger().log( LogService.LOG_INFO, "ConsoleImpl.removeCommand() :
" + cmd.getName() );
m_Commands.remove( cmd.getName() );
synchronized( m_Interpreters )
{
@@ -141,6 +154,7 @@
public void removeCommand( String commandname )
{
+ getLogger().log( LogService.LOG_INFO, "ConsoleImpl.addCommand() : "
+ commandname );
m_Commands.remove( commandname );
synchronized( m_Interpreters )
{
@@ -155,24 +169,27 @@
public ConsoleCommand getCommand( String name )
{
+ getLogger().log( LogService.LOG_INFO, "ConsoleImpl.getCommand() : "
+ name );
return (ConsoleCommand) m_Commands.get( name );
}
public Collection getCommandNames()
{
+ getLogger().log( LogService.LOG_INFO, "ConsoleImpl.getCommandNames()
: " );
return m_Commands.keySet();
}
private void welcomeMessage( BufferedWriter output, String name )
throws IOException
{
+ getLogger().log( LogService.LOG_INFO, "ConsoleImpl.welcomeMessage()"
);
try
{
output.newLine();
output.write( "Connection detected from " + name );
output.newLine();
output.newLine();
- output.write( m_Welcome );
+ output.write( m_Welcome);
output.newLine();
output.flush();
} catch( IOException e )
@@ -193,6 +210,10 @@
LogService getLogger()
{
+ if( m_Logger == null )
+ {
+ return ConsoleActivator.MINIMAL_LOGGER;
+ }
return m_Logger;
}
Modified: development/laboratory/users/niclas/osgi/console/index.xml
==============================================================================
--- development/laboratory/users/niclas/osgi/console/index.xml (original)
+++ development/laboratory/users/niclas/osgi/console/index.xml Wed Jun 15
07:05:09 2005
@@ -36,6 +36,7 @@
<dependencies>
<include key="dpml-transit-main"/>
<include key="dpml-composition-api"/>
+ <include key="osgi"/>
</dependencies>
</project>
@@ -91,6 +92,7 @@
<dependencies>
<include key="dpml-console-impl"/>
<include key="dpml-composition-api"/>
+ <include key="osgi"/>
</dependencies>
<plugins>
<include key="dpml-meta-tools"/>
Modified: development/laboratory/users/niclas/osgi/console/socket/build.xml
==============================================================================
--- development/laboratory/users/niclas/osgi/console/socket/build.xml
(original)
+++ development/laboratory/users/niclas/osgi/console/socket/build.xml Wed
Jun 15 07:05:09 2005
@@ -6,9 +6,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.dpml.net/central/about/legal/
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -17,8 +17,65 @@
-->
<project name="dpml-console-socket" default="install" basedir="."
- xmlns:transit="antlib:net.dpml.transit" >
+ xmlns:transit="antlib:net.dpml.transit"
+ xmlns:x="plugin:dpml/magic/dpml-magic-core"
+>
<transit:import uri="artifact:template:dpml/magic/standard"/>
+ <target name="build" depends="standard.build">
+ <mkdir dir="target/manifest/" />
+ <x:property name="version" feature="version" />
+ <tstamp/>
+ <x:path mode="runtime" id="runtime-path" />
+ <pathconvert
+ dirsep="/"
+ pathsep=","
+ property="classpath"
+ refid="runtime-path"
+ >
+ <mapper type="flatten"/>
+ </pathconvert>
+ <manifest file="target/manifest/MANIFEST.MF" >
+ <attribute name="Built-By" value="${user.name}"/>
+ <attribute name="Specification-Title" value=""/>
+ <attribute name="Specification-Version" value="1.0"/>
+ <attribute name="Specification-Vendor" value="Digital Product Meta
Library"/>
+ <attribute name="Implementation-Title" value="DPML Console OSGi
Bundle"/>
+ <attribute name="Implementation-Version" value="${version}
${DSTAMP}"/>
+ <attribute name="Implementation-Vendor" value="Digital Product Meta
Library"/>
+
+ <attribute name="Bundle-Activator"
value="net.dpml.console.socket.SocketActivator" />
+ <attribute name="Bundle-Category" value="management, dpml-console"/>
+ <attribute name="Bundle-ClassPath" value=".,${classpath}"/>
+ <attribute name="Bundle-ContactAddress"
value="http://www.dpml.net/about"/>
+ <attribute name="Bundle-Copyright" value="Copyright 2005 Digital
Product Meta Library"/>
+ <attribute name="Bundle-Description" value="DPML command console for
management of running Metro instances."/>
+ <attribute name="Bundle-DocURL"
value="http://planet.dpml.net/osgi/console"/>
+ <attribute name="Bundle-Name" value="DPML Console Socket
Connection"/>
+ <!--
+ <attribute name="Bundle-RequiredExecutionEnvironment" value="J2SE"/>
+ -->
+ <attribute name="Bundle-UpdateLocation"
value="file:///home/niclas/.dpml/data/cache/dpml/planet/console/socket/jars/dpml-console-socket-SNAPSHOT.jar"/>
+ <attribute name="Bundle-Vendor" value="DPML"/>
+ <attribute name="Bundle-Version" value="${version}"/>
+ <attribute name="Import-Package" value="org.osgi.service.log,
net.dpml.console"/>
+ <attribute name="Export-Package" value="net.dpml.console"/>
+ </manifest>
+ </target>
+
+ <target name="package" depends="standard.package">
+ <x:replicate todir="target/bundle-content/" flatten="true"/>
+ <x:property name="jarfilename" feature="filename" />
+ <x:property name="transitdir" feature="spec" key="dpml-transit-main" />
+ <jar destfile="target/deliverables/jars/${jarfilename}"
+ manifest="target/manifest/MANIFEST.MF" >
+ <fileset dir="target/classes/" >
+ <include name="**" />
+ </fileset>
+ <fileset dir="target/bundle-content/" >
+ <include name="**/*.jar" />
+ </fileset>
+ </jar>
+ </target>
</project>
Added:
development/laboratory/users/niclas/osgi/console/socket/src/main/net/dpml/console/socket/SocketActivator.java
==============================================================================
--- (empty file)
+++
development/laboratory/users/niclas/osgi/console/socket/src/main/net/dpml/console/socket/SocketActivator.java
Wed Jun 15 07:05:09 2005
@@ -0,0 +1,89 @@
+package net.dpml.console.socket;
+
+import net.dpml.console.CommandConnectionListener;
+import net.dpml.console.MinimalLogger;
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
+import org.osgi.service.log.LogService;
+import org.osgi.util.tracker.ServiceTracker;
+import org.osgi.util.tracker.ServiceTrackerCustomizer;
+
+public class SocketActivator
+ implements BundleActivator
+{
+ static final LogService MINIMAL_LOGGER = new MinimalLogger();
+
+ private BundleContext m_BundleContext;
+ private ServiceTracker m_LogTracker;
+ private ServiceTracker m_ConsoleTracker;
+
+ private SocketProvider m_Provider;
+
+ public SocketActivator()
+ {
+ m_Provider = new SocketProvider();
+ }
+
+ public void start( BundleContext bundleContext )
+ throws Exception
+ {
+ m_BundleContext = bundleContext;
+ m_LogTracker = new ServiceTracker( bundleContext,
"org.osgi.service.log.LogService", new LogServiceTracking() );
+ m_LogTracker.open();
+
+ m_ConsoleTracker = new ServiceTracker( bundleContext,
"net.dpml.console.CommandConnectionListener", new
ConnectionListenerTracking() );
+ m_ConsoleTracker.open();
+
+ m_Provider.start();
+ }
+
+ public void stop( BundleContext bundleContext )
+ throws Exception
+ {
+ m_Provider.stop();
+ }
+
+ private class LogServiceTracking
+ implements ServiceTrackerCustomizer
+ {
+ public Object addingService( ServiceReference serviceReference )
+ {
+ LogService logger = (LogService) m_BundleContext.getService(
serviceReference );
+ m_Provider.setLogger( logger );
+ return logger;
+ }
+
+ public void modifiedService( ServiceReference serviceReference,
Object value )
+ {
+
+ }
+
+ public void removedService( ServiceReference serviceReference,
Object value )
+ {
+ m_Provider.setLogger( null );
+ }
+ }
+
+ private class ConnectionListenerTracking
+ implements ServiceTrackerCustomizer
+ {
+ public Object addingService( ServiceReference serviceReference )
+ {
+ CommandConnectionListener listener = (CommandConnectionListener)
m_BundleContext.getService( serviceReference );
+ m_Provider.addCommandConnectionListener( listener );
+ return listener;
+ }
+
+ public void modifiedService( ServiceReference serviceReference,
Object value )
+ {
+
+ }
+
+ public void removedService( ServiceReference serviceReference,
Object value )
+ {
+ CommandConnectionListener listener = (CommandConnectionListener)
value;
+ m_Provider.removeCommandConnectionListener( listener );
+ }
+ }
+}
Modified:
development/laboratory/users/niclas/osgi/console/socket/src/main/net/dpml/console/socket/SocketCommandConnection.java
==============================================================================
---
development/laboratory/users/niclas/osgi/console/socket/src/main/net/dpml/console/socket/SocketCommandConnection.java
(original)
+++
development/laboratory/users/niclas/osgi/console/socket/src/main/net/dpml/console/socket/SocketCommandConnection.java
Wed Jun 15 07:05:09 2005
@@ -34,8 +34,8 @@
private BufferedReader m_Input;
private BufferedWriter m_Output;
private LogService m_Logger;
-
- SocketCommandConnection( LogService logger, Socket socket )
+
+ SocketCommandConnection( Socket socket )
throws IOException
{
m_Socket = socket;
@@ -47,8 +47,6 @@
OutputStream out = socket.getOutputStream();
OutputStreamWriter osr = new OutputStreamWriter( out );
m_Output = new BufferedWriter( osr );
-
- m_Logger = logger;
}
public String getUser()
@@ -76,14 +74,14 @@
m_Input.close();
} catch( IOException e )
{
- m_Logger.log( LogService.LOG_WARNING, "Unable to close Reader: "
+ m_Input, e );
+ getLogger().log( LogService.LOG_WARNING, "Unable to close
Reader: " + m_Input, e );
}
try
{
m_Output.close();
} catch( IOException e )
{
- m_Logger.log( LogService.LOG_WARNING, "Unable to close Writer: "
+ m_Output, e );
+ getLogger().log( LogService.LOG_WARNING, "Unable to close
Writer: " + m_Output, e );
}
try
{
@@ -93,7 +91,7 @@
}
} catch( IOException e )
{
- m_Logger.log( LogService.LOG_WARNING, "Unable to close Socket: "
+ m_Socket, e );
+ getLogger().log( LogService.LOG_WARNING, "Unable to close
Socket: " + m_Socket, e );
}
}
@@ -105,7 +103,7 @@
m_Output.newLine();
} catch( IOException e )
{
- m_Logger.log( LogService.LOG_WARNING, "[busy]: Can not write to
connection: " + m_Socket, e );
+ getLogger().log( LogService.LOG_WARNING, "[busy]: Can not write
to connection: " + m_Socket, e );
}
}
@@ -117,8 +115,18 @@
m_Output.newLine();
} catch( IOException e )
{
- m_Logger.log( LogService.LOG_WARNING, "[available]: Can not
write to connection: " + m_Socket, e );
+ getLogger().log( LogService.LOG_WARNING, "[available]: Can not
write to connection: " + m_Socket, e );
}
}
+
+ LogService getLogger()
+ {
+ return m_Logger;
+ }
+
+ void setLogger( LogService logger )
+ {
+ m_Logger = logger;
+ }
}
Modified:
development/laboratory/users/niclas/osgi/console/socket/src/main/net/dpml/console/socket/SocketProvider.java
==============================================================================
---
development/laboratory/users/niclas/osgi/console/socket/src/main/net/dpml/console/socket/SocketProvider.java
(original)
+++
development/laboratory/users/niclas/osgi/console/socket/src/main/net/dpml/console/socket/SocketProvider.java
Wed Jun 15 07:05:09 2005
@@ -15,43 +15,45 @@
*/
package net.dpml.console.socket;
-import net.dpml.console.CommandConnection;
import net.dpml.console.CommandConnectionListener;
import net.dpml.console.CommandConnectionProvider;
+import org.osgi.service.cm.ConfigurationException;
+import org.osgi.service.cm.ManagedService;
import org.osgi.service.log.LogService;
import java.io.IOException;
import java.net.InetAddress;
import java.net.ServerSocket;
import java.net.Socket;
+import java.net.UnknownHostException;
import java.util.ArrayList;
+import java.util.Dictionary;
import java.util.Iterator;
/** Server Socket provider.
*
*/
public class SocketProvider
- implements CommandConnectionProvider, Runnable
+ implements CommandConnectionProvider, Runnable, ManagedService
{
private ServerSocket m_ServerSocket;
private Thread m_Thread;
private int m_Port;
-
private ArrayList m_Listeners;
-
private LogService m_Logger;
+ private ArrayList m_Connections;
- public SocketProvider( LogService logger, int port )
- throws IOException
+ public SocketProvider()
{
- m_Logger = logger;
- m_Port = port;
- m_ServerSocket = new ServerSocket( m_Port );
+ m_Connections = new ArrayList();
m_Listeners = new ArrayList();
+ setPort( 3333 ); // default
}
public void start()
+ throws IOException
{
+ m_ServerSocket = new ServerSocket( getPort() );
m_Thread = new Thread( this );
m_Thread.start();
}
@@ -64,7 +66,7 @@
m_ServerSocket.close();
} catch( IOException e )
{
- m_Logger.log( LogService.LOG_WARNING, e.getMessage(), e );
+ getLogger().log( LogService.LOG_WARNING, e.getMessage(), e );
}
}
@@ -84,17 +86,17 @@
running = false;
} catch( DeniedHostException e )
{
- m_Logger.log( LogService.LOG_INFO, e.getMessage(), e );
+ getLogger().log( LogService.LOG_INFO, e.getMessage(), e );
try
{
socket.close();
} catch( IOException ioe )
{
- m_Logger.log( LogService.LOG_WARNING, ioe.getMessage(),
ioe );
+ getLogger().log( LogService.LOG_WARNING,
ioe.getMessage(), ioe );
}
} catch( Exception e )
{
- m_Logger.log( LogService.LOG_WARNING, e.getMessage(), e );
+ getLogger().log( LogService.LOG_WARNING, e.getMessage(), e );
try
{
Thread.sleep( 60000 );
@@ -135,16 +137,24 @@
private void validateHost( InetAddress host )
throws DeniedHostException
{
- if( "127.0.0.1".equals( host.getHostName()) == false )
+ try
{
- throw new DeniedHostException( "Only localhost is allowed at the
moment." );
+ if( InetAddress.getLocalHost().equals( host ) == false )
+ {
+ throw new DeniedHostException( "Only localhost is allowed at
the moment." );
+ }
+ } catch( UnknownHostException e )
+ {
+ throw new DeniedHostException( "Unknown local host. Internal
Error?" );
}
}
private void fireConnection( Socket socket )
throws IOException
{
- CommandConnection cc = new SocketCommandConnection( m_Logger, socket
);
+ getLogger().log( LogService.LOG_DEBUG, "fireConnection(): " + socket
);
+ SocketCommandConnection cc = new SocketCommandConnection( socket );
+ cc.setLogger( m_Logger );
synchronized( m_Listeners )
{
Iterator list = m_Listeners.iterator();
@@ -152,8 +162,60 @@
{
CommandConnectionListener listener =
(CommandConnectionListener) list.next();
listener.connected( cc );
+ getLogger().log( LogService.LOG_DEBUG, "connected: " +
listener );
}
}
+ synchronized( this )
+ {
+ m_Connections.add( cc );
+ }
+ }
+
+ LogService getLogger()
+ {
+ synchronized( this )
+ {
+ if( m_Logger == null )
+ return SocketActivator.MINIMAL_LOGGER;
+ return m_Logger;
+ }
+ }
+
+ void setLogger( LogService logger )
+ {
+ synchronized( this )
+ {
+ m_Logger = logger;
+
+ Iterator list = m_Connections.iterator();
+ while( list.hasNext() )
+ {
+ SocketCommandConnection scc = (SocketCommandConnection)
list.next();
+ scc.setLogger( logger );
+ }
+ }
+ }
+
+ int getPort()
+ {
+ synchronized( this )
+ {
+ return m_Port;
+ }
+ }
+
+ void setPort( int port )
+ {
+ synchronized( this )
+ {
+ m_Port = port;
+ }
+ }
+
+ public void updated( Dictionary dictionary )
+ throws ConfigurationException
+ {
+ Integer port = (Integer) dictionary.get( "port" );
+ setPort( port.intValue() );
}
-
}
Modified: development/laboratory/users/niclas/osgi/console/xmpp/build.xml
==============================================================================
--- development/laboratory/users/niclas/osgi/console/xmpp/build.xml
(original)
+++ development/laboratory/users/niclas/osgi/console/xmpp/build.xml Wed
Jun 15 07:05:09 2005
@@ -6,9 +6,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.dpml.net/central/about/legal/
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -17,8 +17,67 @@
-->
<project name="dpml-console-xmpp" default="install" basedir="."
- xmlns:transit="antlib:net.dpml.transit"
xmlns:x="plugin:dpml/magic/dpml-magic-core">
+ xmlns:transit="antlib:net.dpml.transit"
+ xmlns:x="plugin:dpml/magic/dpml-magic-core"
+>
<transit:import uri="artifact:template:dpml/magic/standard"/>
+ <target name="build" depends="standard.build">
+ <mkdir dir="target/manifest/" />
+ <x:property name="version" feature="version" />
+ <tstamp/>
+ <x:path mode="runtime" id="runtime-path" />
+ <pathconvert
+ dirsep="/"
+ pathsep=","
+ property="classpath"
+ refid="runtime-path"
+ >
+ <mapper type="flatten"/>
+ </pathconvert>
+ <manifest file="target/manifest/MANIFEST.MF" >
+ <attribute name="Built-By" value="${user.name}"/>
+ <attribute name="Specification-Title" value=""/>
+ <attribute name="Specification-Version" value="1.0"/>
+ <attribute name="Specification-Vendor" value="Digital Product Meta
Library"/>
+ <attribute name="Implementation-Title" value="DPML Console OSGi
Bundle"/>
+ <attribute name="Implementation-Version" value="${version}
${DSTAMP}"/>
+ <attribute name="Implementation-Vendor" value="Digital Product Meta
Library"/>
+
+ <attribute name="Bundle-Activator"
value="net.dpml.console.xmpp.XmppActivator" />
+ <attribute name="Bundle-Category" value="management, dpml-console"/>
+ <attribute name="Bundle-ClassPath" value=".,${classpath}"/>
+ <attribute name="Bundle-ContactAddress"
value="http://www.dpml.net/about"/>
+ <attribute name="Bundle-Copyright" value="Copyright 2005 Digital
Product Meta Library"/>
+ <attribute name="Bundle-Description" value="DPML command console for
management of running Metro instances."/>
+ <attribute name="Bundle-DocURL"
value="http://planet.dpml.net/osgi/console"/>
+ <attribute name="Bundle-Name" value="DPML Console XMPP Connection"/>
+ <!--
+ <attribute name="Bundle-RequiredExecutionEnvironment" value="J2SE"/>
+ -->
+ <attribute name="Bundle-UpdateLocation"
value="file:///home/niclas/.dpml/data/cache/dpml/planet/console/xmpp/jars/dpml-console-xmpp-SNAPSHOT.jar"/>
+ <attribute name="Bundle-Vendor" value="DPML"/>
+ <attribute name="Bundle-Version" value="${version}"/>
+ <attribute name="Import-Package" value="org.osgi.service.log,
net.dpml.console"/>
+ <attribute name="Export-Package" value="net.dpml.console"/>
+ </manifest>
+ </target>
+
+ <target name="package" depends="standard.package">
+ <x:replicate todir="target/bundle-content/" flatten="true"/>
+ <x:property name="jarfilename" feature="filename" />
+ <x:property name="transitdir" feature="spec" key="dpml-transit-main" />
+ <jar destfile="target/deliverables/jars/${jarfilename}"
+ manifest="target/manifest/MANIFEST.MF" >
+ <fileset dir="target/classes/" >
+ <include name="**" />
+ </fileset>
+ <fileset dir="target/bundle-content/" >
+ <include name="**/*.jar" />
+ </fileset>
+ </jar>
+ </target>
+
+
</project>
- svn commit: r2862 - in development/laboratory/users/niclas/osgi/console: . api/src/main/net/dpml/console commands commands/src/main/net/dpml/console/commands commands/src/main/net/dpml/console/commands/bundle commands/src/test/net/dpml/console/test impl impl/src/main/net/dpml/console/impl socket socket/src/main/net/dpml/console/socket xmpp, niclas, 06/15/2005
Archive powered by MHonArc 2.6.24.