Skip to Content.
Sympa Menu

notify-dpml - svn commit: r2866 - in development/laboratory/users/niclas/osgi/console: api/src/main/net/dpml/console commands commands/src/main/net/dpml/console/commands commands/src/test/net/dpml/console/test impl/src/main/net/dpml/console/impl socket/src/main/net/dpml/console/socket xmpp/src/main/net/dpml/console/xmpp

notify-dpml AT lists.ibiblio.org

Subject: DPML Notify

List archive

Chronological Thread  
  • From: niclas AT hedhman.org
  • To: notify-dpml AT lists.ibiblio.org
  • Subject: svn commit: r2866 - in development/laboratory/users/niclas/osgi/console: api/src/main/net/dpml/console commands commands/src/main/net/dpml/console/commands commands/src/test/net/dpml/console/test impl/src/main/net/dpml/console/impl socket/src/main/net/dpml/console/socket xmpp/src/main/net/dpml/console/xmpp
  • Date: Fri, 17 Jun 2005 08:23:23 -0400

Author: niclas AT hedhman.org
Date: Fri Jun 17 08:23:22 2005
New Revision: 2866

Modified:

development/laboratory/users/niclas/osgi/console/api/src/main/net/dpml/console/CommandConnection.java

development/laboratory/users/niclas/osgi/console/api/src/main/net/dpml/console/CommandConnectionProvider.java

development/laboratory/users/niclas/osgi/console/api/src/main/net/dpml/console/CommandInterpreter.java

development/laboratory/users/niclas/osgi/console/api/src/main/net/dpml/console/Console.java
development/laboratory/users/niclas/osgi/console/commands/build.xml

development/laboratory/users/niclas/osgi/console/commands/src/main/net/dpml/console/commands/CommandActivator.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/UndeployCmd.java

development/laboratory/users/niclas/osgi/console/commands/src/test/net/dpml/console/test/TestConsole.java

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/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/src/main/net/dpml/console/xmpp/XmppProvider.java

development/laboratory/users/niclas/osgi/console/xmpp/src/main/net/dpml/console/xmpp/XmppReader.java
Log:


Modified:
development/laboratory/users/niclas/osgi/console/api/src/main/net/dpml/console/CommandConnection.java
==============================================================================
---
development/laboratory/users/niclas/osgi/console/api/src/main/net/dpml/console/CommandConnection.java
(original)
+++
development/laboratory/users/niclas/osgi/console/api/src/main/net/dpml/console/CommandConnection.java
Fri Jun 17 08:23:22 2005
@@ -30,8 +30,4 @@
throws IOException;

void close();
-
- void busy( String message );
-
- void available( String message );
}

Modified:
development/laboratory/users/niclas/osgi/console/api/src/main/net/dpml/console/CommandConnectionProvider.java
==============================================================================
---
development/laboratory/users/niclas/osgi/console/api/src/main/net/dpml/console/CommandConnectionProvider.java
(original)
+++
development/laboratory/users/niclas/osgi/console/api/src/main/net/dpml/console/CommandConnectionProvider.java
Fri Jun 17 08:23:22 2005
@@ -19,6 +19,8 @@
*/
public interface CommandConnectionProvider
{
+ void stop();
+
void busy( String message );

void available( String message );

Modified:
development/laboratory/users/niclas/osgi/console/api/src/main/net/dpml/console/CommandInterpreter.java
==============================================================================
---
development/laboratory/users/niclas/osgi/console/api/src/main/net/dpml/console/CommandInterpreter.java
(original)
+++
development/laboratory/users/niclas/osgi/console/api/src/main/net/dpml/console/CommandInterpreter.java
Fri Jun 17 08:23:22 2005
@@ -22,7 +22,7 @@
void addCommand( ConsoleCommand cmd );
void removeCommand( ConsoleCommand cmd );
void removeCommand( String commandname );
-
+
void close();
}


Modified:
development/laboratory/users/niclas/osgi/console/api/src/main/net/dpml/console/Console.java
==============================================================================
---
development/laboratory/users/niclas/osgi/console/api/src/main/net/dpml/console/Console.java
(original)
+++
development/laboratory/users/niclas/osgi/console/api/src/main/net/dpml/console/Console.java
Fri Jun 17 08:23:22 2005
@@ -15,7 +15,7 @@
*/
package net.dpml.console;

-import java.util.Collection;
+

/** Interface for the console.
*/
@@ -29,5 +29,5 @@

ConsoleCommand getCommand( String name );

- Collection getCommandNames();
+ String[] getCommandNames();
}

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 Fri
Jun 17 08:23:22 2005
@@ -66,6 +66,7 @@
<x:replicate todir="target/bundle-content/" flatten="true"/>
<x:property name="jarfilename" feature="filename" />
<x:property name="transitdir" feature="spec" key="dpml-transit-main" />
+ <echo message="${transitdir}" />
<jar destfile="target/deliverables/jars/${jarfilename}"
manifest="target/manifest/MANIFEST.MF" >
<fileset dir="target/classes/" >

Modified:
development/laboratory/users/niclas/osgi/console/commands/src/main/net/dpml/console/commands/CommandActivator.java
==============================================================================
---
development/laboratory/users/niclas/osgi/console/commands/src/main/net/dpml/console/commands/CommandActivator.java
(original)
+++
development/laboratory/users/niclas/osgi/console/commands/src/main/net/dpml/console/commands/CommandActivator.java
Fri Jun 17 08:23:22 2005
@@ -58,7 +58,7 @@
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_Login = register( new LoginCmd( "login" ) );
m_Redploy = register( new RedeployCmd( "redeploy" ));
m_Select = register( new SelectCmd( "select" ) );
m_Cd = register( new SelectCmd( "cd" ) );

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
Fri Jun 17 08:23:22 2005
@@ -22,7 +22,6 @@

import java.io.BufferedReader;
import java.io.BufferedWriter;
-import java.util.Iterator;
import java.util.Map;

/**
@@ -53,7 +52,7 @@
throws Exception
{
m_Logger.log( LogService.LOG_DEBUG, "HelpCmd.execute() " );
- Console console = (Console) context.get( "Console" );
+ Console currentConsole = (Console) context.get( "Console" );
output.newLine();
if( arguments.length == 0 )
{
@@ -61,17 +60,17 @@
output.newLine();
output.write( "===================" );
output.newLine();
- Iterator list = console.getCommandNames().iterator();
- while( list.hasNext() )
+ String[] names = currentConsole.getCommandNames();
+ for( int i = 0; i < names.length; i++ )
{
- output.write( list.next().toString() );
+ output.write( names[ i ] );
output.newLine();
}
} else
{
for( int i=0 ; i < arguments.length ; i++ )
{
- ConsoleCommand cmd = console.getCommand( arguments[i] );
+ ConsoleCommand cmd = currentConsole.getCommand( arguments[ i
] );
if( cmd != null )
{
String descr = cmd.getDescription();

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
Fri Jun 17 08:23:22 2005
@@ -54,24 +54,26 @@
m_Logger.log( LogService.LOG_DEBUG, "ListCmd.execute() " );
output.newLine();
ContainmentModel current = (ContainmentModel) context.get(
"CurrentContainer" );
- String path;
- if( arguments.length == 0 )
- path = current.getQualifiedName();
- else
- path = arguments[0];
-
- DeploymentModel model = current.getModel( path );
- if( model instanceof ContainmentModel )
+ if( current != null )
{
- DeploymentModel[] models = ((ContainmentModel)
model).getModels();
- for( int i=0; i<models.length; i++ )
+ String path;
+ if( arguments.length == 0 )
+ path = current.getQualifiedName();
+ else
+ path = arguments[0];
+
+ DeploymentModel model = current.getModel( path );
+ if( model instanceof ContainmentModel )
{
- DeploymentModel m = models[i];
- output.write( m.toString() );
- output.newLine();
+ DeploymentModel[] models = ((ContainmentModel)
model).getModels();
+ for( int i=0; i<models.length; i++ )
+ {
+ DeploymentModel m = models[i];
+ output.write( m.toString() );
+ output.newLine();
+ }
}
}
-
output.newLine();
output.flush();
}

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
Fri Jun 17 08:23:22 2005
@@ -18,6 +18,11 @@
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.util.Map;
+import java.util.Dictionary;
+import java.util.Iterator;
+import java.util.Enumeration;
+import java.util.StringTokenizer;
+import java.util.HashMap;

import net.dpml.console.CommandInterpreter;
import net.dpml.console.Console;
@@ -33,20 +38,24 @@
import net.dpml.service.ServiceException;
import net.dpml.service.ServiceManager;
import org.osgi.service.log.LogService;
+import org.osgi.service.cm.ManagedService;
+import org.osgi.service.cm.ConfigurationException;

/**
*/
public class LoginCmd
- implements LogEnabled, ConsoleCommand
+ implements LogEnabled, ConsoleCommand, ManagedService
{
- private String m_Password;
+ private String m_RootPassword;
private String m_Name;
private LogService m_Logger;
+ private HashMap m_Users;
+ private HashMap m_Groups;

- public LoginCmd( String name, String rootPassword )
+ public LoginCmd( String name )
{
m_Name = name;
- m_Password = rootPassword;
+ m_RootPassword = "yabadabadoo";
}

public String getName()
@@ -69,7 +78,7 @@
String password = input.readLine();
if( password != null )
{
- if( ! password.trim().equals( m_Password ) )
+ if( ! password.trim().equals( m_RootPassword ) )
throw new LoginException();
}
output.newLine();
@@ -88,4 +97,38 @@
{
m_Logger = logger;
}
+
+ public void updated( Dictionary dictionary )
+ throws ConfigurationException
+ {
+ synchronized( this )
+ {
+ m_RootPassword = (String) dictionary.get( "Root Password");
+ m_Groups = new HashMap();
+ m_Users = new HashMap();
+ Enumeration list = dictionary.keys();
+ while( list.hasMoreElements() )
+ {
+ String key = (String) list.nextElement();
+ if( key.startsWith( "user." ) )
+ processUser( key, dictionary );
+ if( key.startsWith( "group." ) )
+ processGroup( key, dictionary );
+ }
+ }
+ }
+
+ private void processUser( String key, Dictionary dictionary )
+ {
+ String username = key.substring( 5 ); // removes "user."
+ String password = (String) dictionary.get( key );
+ m_Users.put( username, password );
+ }
+
+ private void processGroup( String key, Dictionary dictionary )
+ {
+ String groupname = key.substring( 6 ); // remove "group."
+ String users = (String) dictionary.get( key );
+ m_Groups.put( groupname, users );
+ }
}

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
Fri Jun 17 08:23:22 2005
@@ -58,6 +58,10 @@

String target = arguments[0];
ContainmentModel current = (ContainmentModel) context.get(
"CurrentContainer" );
+ if( current == null )
+ {
+ throw new CommandException( "No ContainmentModel available yet."
);
+ }
ContainmentModel root = (ContainmentModel) current.getModel( "/" );

DeploymentModel dm = current.getModel( target );

Modified:
development/laboratory/users/niclas/osgi/console/commands/src/test/net/dpml/console/test/TestConsole.java
==============================================================================
---
development/laboratory/users/niclas/osgi/console/commands/src/test/net/dpml/console/test/TestConsole.java
(original)
+++
development/laboratory/users/niclas/osgi/console/commands/src/test/net/dpml/console/test/TestConsole.java
Fri Jun 17 08:23:22 2005
@@ -18,8 +18,8 @@
import net.dpml.console.Console;
import net.dpml.console.ConsoleCommand;

-import java.util.Collection;
import java.util.HashMap;
+import java.util.Set;

class TestConsole
implements Console
@@ -53,8 +53,12 @@
return (ConsoleCommand) m_Commands.get( name );
}

- public Collection getCommandNames()
+ public String[] getCommandNames()
{
- return m_Commands.keySet();
+ int size = m_Commands.size();
+ String[] names = new String[ size ];
+ Set set = m_Commands.keySet();
+ set.toArray( names );
+ return names;
}
}

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
Fri Jun 17 08:23:22 2005
@@ -15,61 +15,52 @@
*/
package net.dpml.console.impl;

+import net.dpml.composition.model.ContainmentModel;
+import net.dpml.console.CommandConnection;
import net.dpml.console.CommandInterpreter;
+import net.dpml.console.Console;
import net.dpml.console.ConsoleCommand;
import net.dpml.console.LoginException;
import org.osgi.service.log.LogService;

-import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
+import java.net.SocketException;
import java.util.HashMap;
-import java.util.StringTokenizer;
import java.util.Hashtable;
-import java.net.SocketException;
+import java.util.Set;
+import java.util.StringTokenizer;
+import java.util.TreeMap;

class CommandInterpreterImpl
- implements CommandInterpreter, Runnable
+ implements CommandInterpreter, Runnable, Console
{
private boolean m_Login;
- private HashMap m_Commands;
+ private TreeMap m_Commands;
private Thread m_Thread;
private HashMap m_Context;
- private BufferedWriter m_Output;
- private BufferedReader m_Input;
private LogService m_Logger;
private String m_Name;
+ private CommandConnection m_Connection;

- CommandInterpreterImpl( String name, BufferedReader input,
BufferedWriter output, Hashtable commands )
+ CommandInterpreterImpl( String name, CommandConnection connection,
Hashtable commands, ContainmentModel model )
{
m_Name = name;
- m_Input = input;
- m_Output = output;
- m_Commands = new HashMap( commands );
+ m_Connection = connection;
+ m_Commands = new TreeMap( commands );
m_Context = new HashMap();
- m_Context.put( "CurrentNode", "<none>" );
+ m_Context.put( "CurrentContainer", model );
+ m_Context.put( "Console", this );
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 )
- {
- getLogger().log( LogService.LOG_WARNING, "Can not close the
Writer: " + m_Name );
- }
- try
- {
- m_Input.close();
- } catch( IOException e )
- {
- getLogger().log( LogService.LOG_WARNING, "Can not close the
Reader: " + m_Name );
- }
+ m_Connection.close();
m_Login = false;
}

@@ -92,7 +83,28 @@
getLogger().log( LogService.LOG_DEBUG, "Removing Command: " +
commandname );
m_Commands.remove( commandname );
}
-
+
+ public ConsoleCommand getCommand( String name )
+ {
+ synchronized( m_Commands )
+ {
+ ConsoleCommand cmd = (ConsoleCommand) m_Commands.get( name );
+ return cmd;
+ }
+ }
+
+ public String[] getCommandNames()
+ {
+ synchronized( m_Commands )
+ {
+ int size = m_Commands.size();
+ String[] names = new String[ size ];
+ Set set = m_Commands.keySet();
+ set.toArray( names );
+ return names;
+ }
+ }
+
public void run()
{
boolean running = true;
@@ -109,6 +121,8 @@
errorMessage( "wrong password" );
} catch( InterruptedException e )
{
+ getLogger().log( LogService.LOG_INFO, "Shutting down: " +
m_Name );
+ m_Connection.close();
running = false;
} catch( SocketException e )
{
@@ -144,7 +158,7 @@
if( cc != null )
{
String[] args = parseArguments( st );
- cc.execute( m_Context, m_Input, m_Output, args );
+ cc.execute( m_Context, m_Connection.getInputReader(),
m_Connection.getOutputWriter(), args );
return;
}
}
@@ -157,9 +171,10 @@
String cmdline = "";
while( cmdline.length() == 0 )
{
- m_Output.write( "[" + m_Name + " " + m_Context.get(
"CurrentNode" ) + "]$ " );
- m_Output.flush();
- cmdline = m_Input.readLine().trim();
+ BufferedWriter output = m_Connection.getOutputWriter();
+ output.write( "[" + m_Name + " " + m_Context.get( "CurrentNode"
) + "]$ " );
+ output.flush();
+ cmdline = m_Connection.getInputReader().readLine().trim();
}
return cmdline;
}
@@ -176,9 +191,10 @@
{
try
{
- m_Output.write( message );
- m_Output.newLine();
- m_Output.flush();
+ BufferedWriter output = m_Connection.getOutputWriter();
+ output.write( message );
+ output.newLine();
+ output.flush();
} catch( IOException e )
{
e.printStackTrace( System.out );

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
Fri Jun 17 08:23:22 2005
@@ -16,15 +16,16 @@

package net.dpml.console.impl;

+import net.dpml.composition.model.ContainmentModel;
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;
+import org.osgi.service.log.LogService;
import org.osgi.util.tracker.ServiceTracker;
import org.osgi.util.tracker.ServiceTrackerCustomizer;
-import org.osgi.service.log.LogService;

import java.util.ArrayList;

@@ -33,11 +34,13 @@
{
static final LogService MINIMAL_LOGGER = new MinimalLogger();

+ private ServiceTracker m_CommandTracker;
private ServiceTracker m_LogTracker;
+ private ServiceTracker m_ProviderTracker;
+ private ServiceTracker m_MetroTracker;
+
private ConsoleImpl m_Console;
- private ServiceTracker m_CommandTracker;
private BundleContext m_BundleContext;
- private ServiceTracker m_ProviderTracker;
private ArrayList m_Providers;

public void start( BundleContext bundleContext )
@@ -54,6 +57,9 @@
m_LogTracker = new ServiceTracker( bundleContext,
"org.osgi.service.log.LogService", new LogServiceTracking() );
m_LogTracker.open();

+ m_MetroTracker = new ServiceTracker( bundleContext,
"net.dpml.composition.model.ContainmentModel", new MetroTracking() );
+ m_MetroTracker.open();
+
m_CommandTracker = new ServiceTracker( bundleContext,
"net.dpml.console.ConsoleCommand", new CommandTracking() );
m_CommandTracker.open();

@@ -65,6 +71,9 @@
throws Exception
{
m_LogTracker.close();
+ m_CommandTracker.close();
+ m_ProviderTracker.close();
+ m_MetroTracker.close();
m_Console.dispose();
}

@@ -133,4 +142,27 @@
}
}

+ private class MetroTracking
+ implements ServiceTrackerCustomizer
+ {
+ public Object addingService( ServiceReference reference )
+ {
+ Object service = m_BundleContext.getService( reference );
+ ContainmentModel model = (ContainmentModel) service;
+ m_Console.addRootContainmentModel( model );
+ return model;
+ }
+
+ public void modifiedService( ServiceReference serviceReference,
Object value )
+ {
+
+ }
+
+ public void removedService( ServiceReference serviceReference,
Object value )
+ {
+ ContainmentModel model = (ContainmentModel) value;
+ m_Console.removeRootContainmentModel( model );
+ }
+ }
+
}

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
Fri Jun 17 08:23:22 2005
@@ -15,6 +15,8 @@
*/
package net.dpml.console.impl;

+import net.dpml.composition.model.ContainmentModel;
+import net.dpml.composition.model.DeploymentModel;
import net.dpml.console.CommandConnection;
import net.dpml.console.CommandConnectionListener;
import net.dpml.console.CommandConnectionProvider;
@@ -28,12 +30,13 @@
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Collection;
import java.util.Dictionary;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.Iterator;
+import java.util.Map;
+import java.util.Set;
+import java.util.ArrayList;

/**
*/
@@ -41,25 +44,39 @@
implements Console, CommandConnectionListener, ManagedService
{
private LogService m_Logger;
- private ArrayList m_Interpreters;
+ private ArrayList m_Roots;
private Hashtable m_Commands;
private HashMap m_Connections;
private String m_Welcome;
-
private CommandConnectionProvider m_ConnectionProvider;
- private CommandInterpreterImpl m_Interpreter;

/**
*/
public ConsoleImpl()
{
- m_Interpreters = new ArrayList();
m_Connections = new HashMap();
m_Commands = new Hashtable();
+ m_Roots = new ArrayList();
m_Welcome = "Welcome to the DPML Console.\nAfter login, type\n\n
help[enter]\n\nfor list of commands";
}


+ void addRootContainmentModel( ContainmentModel root )
+ {
+ synchronized( this )
+ {
+ m_Roots.add( root );
+ }
+ }
+
+ void removeRootContainmentModel( ContainmentModel root )
+ {
+ synchronized( this )
+ {
+ m_Roots.remove( root );
+ }
+ }
+
public void updated( Dictionary dictionary )
throws ConfigurationException
{
@@ -82,10 +99,13 @@
{
m_ConnectionProvider.removeCommandConnectionListener( this );
}
- Iterator list = m_Interpreters.iterator();
+ Iterator list = m_Connections.entrySet().iterator();
while( list.hasNext() )
{
- CommandInterpreter intp = (CommandInterpreter) list.next();
+ Map.Entry entry = (Map.Entry) list.next();
+ CommandConnection connection = (CommandConnection)
entry.getKey();
+ connection.close();
+ CommandInterpreter intp = (CommandInterpreter) entry.getValue();
intp.close();
}
}
@@ -98,19 +118,50 @@
{
BufferedReader input = connection.getInputReader();
BufferedWriter output = connection.getOutputWriter();
- welcomeMessage( output, name );
-
+ ContainmentModel root = selectRoot( input, output, name );
synchronized( m_Connections )
{
- m_Interpreter = new CommandInterpreterImpl( name, input,
output, m_Commands );
- m_Connections.put( connection, m_Interpreter );
+ CommandInterpreterImpl intp = new CommandInterpreterImpl(
name, connection, m_Commands, root );
+ m_Connections.put( connection, intp );
}
} catch( IOException e )
{
getLogger().log( LogService.LOG_ERROR, e.getMessage(), e );
}
}
-
+
+ private ContainmentModel selectRoot( BufferedReader input,
BufferedWriter output, String name )
+ throws IOException
+ {
+ ContainmentModel root = null;
+ while( root == null )
+ {
+ welcomeMessage( output, name );
+ if( m_Roots.size() > 1 )
+ {
+ String selection = input.readLine();
+ try
+ {
+ int number = Integer.parseInt( selection );
+ root = (ContainmentModel) m_Roots.get( number );
+ } catch( NumberFormatException e )
+ {
+ output.write( "Please enter a number." );
+ output.flush();
+ }
+ }
+ else if( m_Roots.size() == 1 )
+ {
+ root = (ContainmentModel) m_Roots.get( 0 );
+ }
+ else
+ {
+ return null;
+ }
+ }
+ return root;
+ }
+
public void connectionLost( CommandConnection connection )
{
getLogger().log( LogService.LOG_INFO, "ConsoleImpl.connectionLost()
: " + connection );
@@ -126,9 +177,9 @@
getLogger().log( LogService.LOG_INFO, "ConsoleImpl.addCommand() : "
+ cmd.getName() );
String name = cmd.getName();
m_Commands.put( name, cmd );
- synchronized( m_Interpreters )
+ synchronized( m_Connections )
{
- Iterator list = m_Interpreters.iterator();
+ Iterator list = m_Connections.values().iterator();
while( list.hasNext() )
{
CommandInterpreter intp = (CommandInterpreter) list.next();
@@ -141,9 +192,9 @@
{
getLogger().log( LogService.LOG_INFO, "ConsoleImpl.removeCommand() :
" + cmd.getName() );
m_Commands.remove( cmd.getName() );
- synchronized( m_Interpreters )
+ synchronized( m_Connections )
{
- Iterator list = m_Interpreters.iterator();
+ Iterator list = m_Connections.values().iterator();
while( list.hasNext() )
{
CommandInterpreter intp = (CommandInterpreter) list.next();
@@ -156,9 +207,9 @@
{
getLogger().log( LogService.LOG_INFO, "ConsoleImpl.addCommand() : "
+ commandname );
m_Commands.remove( commandname );
- synchronized( m_Interpreters )
+ synchronized( m_Connections )
{
- Iterator list = m_Interpreters.iterator();
+ Iterator list = m_Connections.values().iterator();
while( list.hasNext() )
{
CommandInterpreter intp = (CommandInterpreter) list.next();
@@ -173,10 +224,17 @@
return (ConsoleCommand) m_Commands.get( name );
}

- public Collection getCommandNames()
+ public String[] getCommandNames()
{
getLogger().log( LogService.LOG_INFO, "ConsoleImpl.getCommandNames()
: " );
- return m_Commands.keySet();
+ synchronized( m_Commands )
+ {
+ int size = m_Commands.size();
+ String[] names = new String[ size ];
+ Set set = m_Commands.keySet();
+ set.toArray( names );
+ return names;
+ }
}

private void welcomeMessage( BufferedWriter output, String name )
@@ -191,12 +249,47 @@
output.newLine();
output.write( m_Welcome);
output.newLine();
+ String message = m_Roots.size() + " Metro containers are
installed on the platform.";
+ output.write( message );
+ output.newLine();
+ for( int i = 0; i < message.length(); i++ )
+ output.write( "-" );
+ output.newLine();
+ for( int i = 0; i < m_Roots.size(); i++ )
+ {
+ ContainmentModel model = (ContainmentModel) m_Roots.get( i );
+ String compound = getCompound( model );
+ output.write( compound );
+ }
+ output.newLine();
+ if( m_Roots.size() > 1 )
+ {
+ output.write( "Select one:" );
+ }
output.flush();
} catch( IOException e )
{
throw e;
}
- }
+ }
+
+ private String getCompound( ContainmentModel root )
+ {
+ StringBuffer result = new StringBuffer();
+ result.append( "[ " );
+ DeploymentModel[] models = root.getModels();
+ for( int i = 0; i < models.length; i++ )
+ {
+ if( i != 0 )
+ result.append( ", " );
+ DeploymentModel model = models[ i ];
+ result.append( i );
+ result.append( " : " );
+ result.append( model );
+ }
+ result.append( " ]" );
+ return result.toString();
+ }

public CommandConnectionProvider getConnectionProvider()
{
@@ -219,9 +312,9 @@

void setLogger( LogService logger )
{
- synchronized( m_Interpreters )
+ synchronized( m_Connections )
{
- Iterator list = m_Interpreters.iterator();
+ Iterator list = m_Connections.values().iterator();
while( list.hasNext() )
{
CommandInterpreterImpl intp = (CommandInterpreterImpl)
list.next();

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
Fri Jun 17 08:23:22 2005
@@ -71,28 +71,36 @@
{
try
{
- m_Input.close();
+ if( m_Socket.isClosed() == false )
+ {
+ m_Socket.close();
+ }
} catch( IOException e )
{
- getLogger().log( LogService.LOG_WARNING, "Unable to close
Reader: " + m_Input, e );
+ getLogger().log( LogService.LOG_WARNING, "Unable to close
Socket: " + m_Socket, e );
}
try
{
- m_Output.close();
+ if( m_Input != null )
+ {
+ m_Input.close();
+ }
} catch( IOException e )
{
- getLogger().log( LogService.LOG_WARNING, "Unable to close
Writer: " + m_Output, e );
+ getLogger().log( LogService.LOG_WARNING, "Unable to close
Reader: " + m_Input, e );
}
+ m_Input = null;
try
{
- if( m_Socket.isClosed() == false )
+ if( m_Output != null )
{
- m_Socket.close();
+ m_Output.close();
}
} catch( IOException e )
{
- getLogger().log( LogService.LOG_WARNING, "Unable to close
Socket: " + m_Socket, e );
+ getLogger().log( LogService.LOG_WARNING, "Unable to close
Writer: " + m_Output, e );
}
+ m_Output = null;
}

public void busy( String message )

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
Fri Jun 17 08:23:22 2005
@@ -17,6 +17,7 @@

import net.dpml.console.CommandConnectionListener;
import net.dpml.console.CommandConnectionProvider;
+import net.dpml.console.CommandConnection;
import org.osgi.service.cm.ConfigurationException;
import org.osgi.service.cm.ManagedService;
import org.osgi.service.log.LogService;
@@ -63,7 +64,17 @@
try
{
m_Thread.interrupt();
- m_ServerSocket.close();
+ synchronized( this )
+ {
+ m_ServerSocket.close();
+ Iterator connList = m_Connections.iterator();
+ while( connList.hasNext() )
+ {
+ CommandConnection connection = (CommandConnection)
connList.next();
+ connection.close();
+ fireConnectionLost( connection );
+ }
+ }
} catch( IOException e )
{
getLogger().log( LogService.LOG_WARNING, e.getMessage(), e );
@@ -161,7 +172,13 @@
while( list.hasNext() )
{
CommandConnectionListener listener =
(CommandConnectionListener) list.next();
- listener.connected( cc );
+ try
+ {
+ listener.connected( cc );
+ } catch( Exception e )
+ {
+ m_Logger.log( LogService.LOG_WARNING, "Exception in
listener. Ignored.", e );
+ }
getLogger().log( LogService.LOG_DEBUG, "connected: " +
listener );
}
}
@@ -171,6 +188,25 @@
}
}

+ private void fireConnectionLost( CommandConnection connection )
+ {
+ synchronized( m_Listeners )
+ {
+ Iterator list = m_Listeners.iterator();
+ while( list.hasNext() )
+ {
+ CommandConnectionListener listener =
(CommandConnectionListener) list.next();
+ try
+ {
+ listener.connectionLost( connection );
+ } catch( Exception e )
+ {
+ m_Logger.log( LogService.LOG_WARNING, "Exception in
listener. Ignored.", e );
+ }
+ }
+ }
+ }
+
LogService getLogger()
{
synchronized( this )

Modified:
development/laboratory/users/niclas/osgi/console/xmpp/src/main/net/dpml/console/xmpp/XmppProvider.java
==============================================================================
---
development/laboratory/users/niclas/osgi/console/xmpp/src/main/net/dpml/console/xmpp/XmppProvider.java
(original)
+++
development/laboratory/users/niclas/osgi/console/xmpp/src/main/net/dpml/console/xmpp/XmppProvider.java
Fri Jun 17 08:23:22 2005
@@ -15,7 +15,6 @@
*/
package net.dpml.console.xmpp;

-import net.dpml.console.CommandConnection;
import net.dpml.console.CommandConnectionListener;
import net.dpml.console.CommandConnectionProvider;
import org.jivesoftware.smack.PacketListener;
@@ -78,31 +77,18 @@
m_Listeners.add( listener );
}
}
-
+
+ public void stop()
+ {
+ m_Connection.close();
+ }
+
public void busy( String message )
{
- synchronized( m_ConnectedUsers )
- {
- Iterator list = m_ConnectedUsers.values().iterator();
- while( list.hasNext() )
- {
- CommandConnection cc = (CommandConnection) list.next();
- cc.busy( message );
- }
- }
}

public void available( String message )
{
- synchronized( m_ConnectedUsers )
- {
- Iterator list = m_ConnectedUsers.values().iterator();
- while( list.hasNext() )
- {
- CommandConnection cc = (CommandConnection) list.next();
- cc.available( message );
- }
- }
}

public void processPacket( Packet packet )
@@ -123,7 +109,6 @@

private void processPacket( Message message )
{
- String tCommand = message.getBody();
String user = message.getFrom();
synchronized( m_ConnectedUsers )
{

Modified:
development/laboratory/users/niclas/osgi/console/xmpp/src/main/net/dpml/console/xmpp/XmppReader.java
==============================================================================
---
development/laboratory/users/niclas/osgi/console/xmpp/src/main/net/dpml/console/xmpp/XmppReader.java
(original)
+++
development/laboratory/users/niclas/osgi/console/xmpp/src/main/net/dpml/console/xmpp/XmppReader.java
Fri Jun 17 08:23:22 2005
@@ -32,7 +32,6 @@
{
m_Buffer = new StringBuffer();
m_Chat = chat;
- String from = chat.getParticipant();
m_Chat.addMessageListener( this );
}




  • svn commit: r2866 - in development/laboratory/users/niclas/osgi/console: api/src/main/net/dpml/console commands commands/src/main/net/dpml/console/commands commands/src/test/net/dpml/console/test impl/src/main/net/dpml/console/impl socket/src/main/net/dpml/console/socket xmpp/src/main/net/dpml/console/xmpp, niclas, 06/17/2005

Archive powered by MHonArc 2.6.24.

Top of Page