Update of /cvsroot/jmri/jmri/jmrix/loconet/locormi
In directory usw-pr-cvs1:/tmp/cvs-serv13437
Modified Files:
LnMessageBuffer.java LnMessageBufferInterface.java
LnMessageClient.java LnMessageClientAction.java
LnMessageServer.java LnMessageServerInterface.java
Log Message:
LnMessageClient ready for testing
Index: LnMessageBuffer.java
===================================================================
RCS file: /cvsroot/jmri/jmri/jmrix/loconet/locormi/LnMessageBuffer.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -r1.3 -r1.4
*** LnMessageBuffer.java 28 Mar 2002 04:21:19 -0000 1.3
--- LnMessageBuffer.java 30 Mar 2002 00:38:06 -0000 1.4
***************
*** 1,76 ****
! package jmri.jmrix.loconet.locormi;
!
! /**
! * Handle a RMI connection for a single remote client.
! * Description:
! * Copyright: Copyright (c) 2002
! * @author Alex Shepherd
! * @version $Id$
! */
!
! import com.sun.java.util.collections.LinkedList;
! import java.rmi.server.UnicastRemoteObject;
! import java.rmi.RemoteException ;
! import jmri.jmrix.loconet.*;
!
! public class LnMessageBuffer extends UnicastRemoteObject implements LnMessageBufferInterface, LocoNetListener
! {
! LinkedList messageList = null ;
!
! public LnMessageBuffer() throws RemoteException
! {
! super() ;
! }
!
! public void enable( int mask ) throws RemoteException
! {
! if( messageList == null )
! messageList = new LinkedList() ;
!
! LnTrafficController.instance().addLocoNetListener( mask, this);
! }
!
! public void disable( int mask ) throws RemoteException
! {
! LnTrafficController.instance().removeLocoNetListener( mask, this);
! }
!
! public void clear() throws RemoteException
! {
! messageList.clear() ;
! }
!
! public void message(LocoNetMessage msg)
! {
! synchronized( messageList )
! {
! messageList.add( msg ) ;
! messageList.notify();
! }
! }
!
! public LocoNetMessage[] getMessages( long timeout )
! {
! LocoNetMessage[] messageArray = null ;
!
! synchronized( messageList )
! {
! if( messageList.size() == 0 )
! {
! try
! {
! messageList.wait( timeout );
! }
! catch( InterruptedException ex ){}
! }
!
! if( messageList.size() > 0 )
! {
! messageArray = (LocoNetMessage[])messageList.toArray() ;
! messageList.clear();
! }
! }
!
! return messageArray ;
! }
}
--- 1,80 ----
! package jmri.jmrix.loconet.locormi;
!
! /**
! * Handle a RMI connection for a single remote client.
! * Description:
! * Copyright: Copyright (c) 2002
! * @author Alex Shepherd
! * @version $Id$
! */
!
! import com.sun.java.util.collections.LinkedList;
! import java.rmi.server.UnicastRemoteObject;
! import java.rmi.RemoteException ;
! import jmri.jmrix.loconet.*;
!
! public class LnMessageBuffer extends UnicastRemoteObject implements LnMessageBufferInterface, LocoNetListener
! {
! LinkedList messageList = null ;
!
! public LnMessageBuffer() throws RemoteException
! {
! super() ;
! }
!
! public void enable( int mask ) throws RemoteException
! {
! if( messageList == null )
! messageList = new LinkedList() ;
!
! LnTrafficController.instance().addLocoNetListener( mask, this);
! }
!
! public void disable( int mask ) throws RemoteException
! {
! LnTrafficController.instance().removeLocoNetListener( mask, this);
! }
!
! public void clear() throws RemoteException
! {
! messageList.clear() ;
! }
!
! public void message(LocoNetMessage msg)
! {
! synchronized( messageList )
! {
! messageList.add( msg ) ;
! messageList.notify();
! }
! }
!
! public Object[] getMessages( long timeout )
! {
! Object[] messagesArray = null ;
!
! synchronized( messageList )
! {
! if( messageList.size() == 0 )
! {
! try
! {
! messageList.wait( timeout );
! }
! catch( InterruptedException ex ){}
! }
!
! if( messageList.size() > 0 )
! {
! messagesArray = messageList.toArray() ;
! messageList.clear();
! }
! }
!
! return messagesArray ;
! }
!
! public void sendLocoNetMessage(LocoNetMessage m){
! LnTrafficController.instance().sendLocoNetMessage( m );
! }
}
Index: LnMessageBufferInterface.java
===================================================================
RCS file: /cvsroot/jmri/jmri/jmrix/loconet/locormi/LnMessageBufferInterface.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -r1.2 -r1.3
*** LnMessageBufferInterface.java 28 Mar 2002 02:25:24 -0000 1.2
--- LnMessageBufferInterface.java 30 Mar 2002 00:38:06 -0000 1.3
***************
*** 1,24 ****
! package jmri.jmrix.loconet.locormi;
!
! /**
! * Title:
! * Description:
! * Copyright: Copyright (c) 2002
! * Company:
! * @author
! * @version $Id$
! */
!
! import java.rmi.RemoteException;
! import jmri.jmrix.loconet.*;
!
! public interface LnMessageBufferInterface
! {
! public void enable( int mask ) throws RemoteException ;
!
! public void disable( int mask ) throws RemoteException ;
!
! public void clear() throws RemoteException ;
!
! public LocoNetMessage[] getMessages( long timeout ) throws RemoteException ;
}
--- 1,27 ----
! package jmri.jmrix.loconet.locormi;
!
! /**
! * Title:
! * Description:
! * Copyright: Copyright (c) 2002
! * Company:
! * @author
! * @version $Id$
! */
!
! import java.rmi.Remote;
! import java.rmi.RemoteException;
! import jmri.jmrix.loconet.*;
!
! public interface LnMessageBufferInterface extends Remote
! {
! public void enable( int mask ) throws RemoteException ;
!
! public void disable( int mask ) throws RemoteException ;
!
! public void clear() throws RemoteException ;
!
! public Object[] getMessages( long timeout ) throws RemoteException ;
!
! public void sendLocoNetMessage(LocoNetMessage m) throws RemoteException ;
}
Index: LnMessageClient.java
===================================================================
RCS file: /cvsroot/jmri/jmri/jmrix/loconet/locormi/LnMessageClient.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -r1.1 -r1.2
*** LnMessageClient.java 28 Mar 2002 04:21:19 -0000 1.1
--- LnMessageClient.java 30 Mar 2002 00:38:06 -0000 1.2
***************
*** 1,67 ****
! package jmri.jmrix.loconet.locormi;
!
! import jmri.jmrix.loconet.*;
!
! /**
! * Client for the RMI LocoNet server.
! * <p>Copyright: Copyright (c) 2002</p>
! * @author Bob Jacobsen
! * @version $Id$
! */
!
! public class LnMessageClient extends LnTrafficRouter {
!
! public LnMessageClient() {
! super();
! }
!
! /**
! * Forward messages to the server.
! */
! public void sendLocoNetMessage(LocoNetMessage m) {
! // Implement this with code to forward m
! // to the server.
! }
!
! // messages that are received from the server should
! // be passed to this.notify(LocoNetMessage m);
!
! /**
! * Start the connection to the server. This is invoked
! * once.
! */
! void configureRemoteConnection(String remoteHostName, int timeoutSec) {
! if (log.isDebugEnabled()) log.debug("configureRemoteConnection: "
! +remoteHostName+" "+timeoutSec);
! }
!
! /**
! * set up all of the other objects to operate with a server
! * connected to this application
! */
! public void configureLocalServices() {
! // This is invoked on the LnMessageClient after it's
! // ready to go, connection running, etc.
!
! // If a jmri.Programmer instance doesn't exist, create a
! // loconet.SlotManager to do that
! if (jmri.InstanceManager.programmerInstance() == null)
! jmri.jmrix.loconet.SlotManager.instance();
!
! // If a jmri.PowerManager instance doesn't exist, create a
! // loconet.LnPowerManager to do that
! if (jmri.InstanceManager.powerManagerInstance() == null)
! jmri.InstanceManager.setPowerManager(new jmri.jmrix.loconet.LnPowerManager());
!
! // If a jmri.TurnoutManager instance doesn't exist, create a
! // loconet.LnTurnoutManager to do that
! if (jmri.InstanceManager.turnoutManagerInstance() == null)
! jmri.InstanceManager.setTurnoutManager(new jmri.jmrix.loconet.LnTurnoutManager());
!
! // the serial connections (LocoBuffer et al) start
! // various threads here.
! }
!
!
! static org.apache.log4j.Category log = org.apache.log4j.Category.getInstance(LnMessageClient.class.getName());
}
--- 1,115 ----
! package jmri.jmrix.loconet.locormi;
!
! import jmri.jmrix.loconet.*;
! import com.sun.java.util.collections.LinkedList;
!
! /**
! * Client for the RMI LocoNet server.
! * <p>Copyright: Copyright (c) 2002</p>
! * @author Bob Jacobsen
! * @version $Id$
! */
!
! public class LnMessageClient extends LnTrafficRouter {
!
! String serverName = null ;
! int pollTimeout ;
! LnMessageServerInterface lnServer = null ;
! LnMessageBufferInterface lnMessageBuffer = null ;
! LnMessageClientPollThread pollThread = null ;
!
! public LnMessageClient() {
! super();
! }
!
! /**
! * Forward messages to the server.
! */
! public void sendLocoNetMessage(LocoNetMessage m) {
! }
!
! // messages that are received from the server should
! // be passed to this.notify(LocoNetMessage m);
!
! /**
! * Start the connection to the server. This is invoked
! * once.
! */
! void configureRemoteConnection(String remoteHostName, int timeoutSec) throws LocoNetException {
! serverName = remoteHostName ;
! pollTimeout = timeoutSec * 1000 ; // convert to ms
!
! if (log.isDebugEnabled()) log.debug("configureRemoteConnection: "
! +remoteHostName+" "+timeoutSec);
!
! try{
! System.setSecurityManager(new java.rmi.RMISecurityManager());
!
! LnMessageServerInterface lnServer = (LnMessageServerInterface) java.rmi.Naming.lookup(
! "//" + serverName + "/" + LnMessageServer.serviceName );
!
! lnMessageBuffer = lnServer.getMessageBuffer() ;
! lnMessageBuffer.enable( 0 );
! pollThread = new LnMessageClientPollThread( this ) ;
! }
! catch( Exception ex ){
! System.out.println( "Exception: " + ex ) ;
! throw new LocoNetException( "Failed to Connect to Server: " + serverName ) ;
! }
! }
!
! /**
! * set up all of the other objects to operate with a server
! * connected to this application
! */
! public void configureLocalServices() {
! // This is invoked on the LnMessageClient after it's
! // ready to go, connection running, etc.
!
! // If a jmri.Programmer instance doesn't exist, create a
! // loconet.SlotManager to do that
! if (jmri.InstanceManager.programmerInstance() == null)
! jmri.jmrix.loconet.SlotManager.instance();
!
! // If a jmri.PowerManager instance doesn't exist, create a
! // loconet.LnPowerManager to do that
! if (jmri.InstanceManager.powerManagerInstance() == null)
! jmri.InstanceManager.setPowerManager(new jmri.jmrix.loconet.LnPowerManager());
!
! // If a jmri.TurnoutManager instance doesn't exist, create a
! // loconet.LnTurnoutManager to do that
! if (jmri.InstanceManager.turnoutManagerInstance() == null)
! jmri.InstanceManager.setTurnoutManager(new jmri.jmrix.loconet.LnTurnoutManager());
!
! // the serial connections (LocoBuffer et al) start
! // various threads here.
! }
!
! public static void main( String[] args ){
! String logFile = "default.lcf";
! try {
! if (new java.io.File(logFile).canRead()) {
! org.apache.log4j.PropertyConfigurator.configure("default.lcf");
! } else {
! org.apache.log4j.BasicConfigurator.configure();
! }
! }
! catch (java.lang.NoSuchMethodError e) { System.out.println("Exception starting logging: "+e); }
!
! try{
! String serverName = java.net.InetAddress.getLocalHost().getHostName();
! LnMessageClient lnClient = new LnMessageClient() ;
! lnClient.configureRemoteConnection( serverName, 60 );
!
! // Now just site and wait for the Thread to read
! synchronized( lnClient ){
! lnClient.wait() ;
! }
! }
! catch( Exception ex ){
! System.out.println( "Exception: " + ex ) ;
! }
! }
!
! static org.apache.log4j.Category log = org.apache.log4j.Category.getInstance(LnMessageClient.class.getName());
}
Index: LnMessageClientAction.java
===================================================================
RCS file: /cvsroot/jmri/jmri/jmrix/loconet/locormi/LnMessageClientAction.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -r1.1 -r1.2
*** LnMessageClientAction.java 28 Mar 2002 04:21:19 -0000 1.1
--- LnMessageClientAction.java 30 Mar 2002 00:38:06 -0000 1.2
***************
*** 1,46 ****
! package jmri.jmrix.loconet.locormi;
!
! /**
! * Opens a connection with a LnMessageServer on a remote machine.
! * The remote machine IP address is specified via a dialog box.
! * Description:
! * Copyright: Copyright (c) 2002
! * Company:
! * @author Bob Jacobsen
! * @version $Id$
! */
!
! import javax.swing.*;
! import jmri.jmrix.loconet.*;
! import javax.swing.AbstractAction;
! import java.awt.event.ActionEvent;
! import java.rmi.RemoteException;
!
! public class LnMessageClientAction extends AbstractAction
! {
! static org.apache.log4j.Category log = org.apache.log4j.Category.getInstance(LnMessageClientAction.class.getName());
!
! public LnMessageClientAction( String s )
! {
! super( s ) ;
! }
!
! public void actionPerformed( ActionEvent e)
! {
! // get the portname and timeout
! String remoteHostName = JOptionPane.showInputDialog("Remote host name?");
!
! int timeoutMSec = 500; // this is temporarily fixed, until
! // I understand how best to present it
! // to the user.
!
! // create the LnMessageClient
! LnMessageClient client = new LnMessageClient();
!
! // start the connection
! client.configureRemoteConnection(remoteHostName, timeoutMSec);
!
! // configure the other instance objects
! client.configureLocalServices();
! }
}
--- 1,51 ----
! package jmri.jmrix.loconet.locormi;
!
! /**
! * Opens a connection with a LnMessageServer on a remote machine.
! * The remote machine IP address is specified via a dialog box.
! * Description:
! * Copyright: Copyright (c) 2002
! * Company:
! * @author Bob Jacobsen
! * @version $Id$
! */
!
! import javax.swing.*;
! import jmri.jmrix.loconet.*;
! import javax.swing.AbstractAction;
! import java.awt.event.ActionEvent;
! import java.rmi.RemoteException;
!
! public class LnMessageClientAction extends AbstractAction
! {
! static org.apache.log4j.Category log = org.apache.log4j.Category.getInstance(LnMessageClientAction.class.getName());
!
! public LnMessageClientAction( String s )
! {
! super( s ) ;
! }
!
! public void actionPerformed( ActionEvent e)
! {
! try{
! // get the portname and timeout
! String remoteHostName = JOptionPane.showInputDialog("Remote host name?");
!
! int timeoutMSec = 500; // this is temporarily fixed, until
! // I understand how best to present it
! // to the user.
!
! // create the LnMessageClient
! LnMessageClient client = new LnMessageClient();
!
! // start the connection
! client.configureRemoteConnection(remoteHostName, timeoutMSec);
!
! // configure the other instance objects
! client.configureLocalServices();
! }
! catch( LocoNetException ex ){
! log.warn( "Exception: " + ex );
! }
! }
}
Index: LnMessageServer.java
===================================================================
RCS file: /cvsroot/jmri/jmri/jmrix/loconet/locormi/LnMessageServer.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -r1.2 -r1.3
*** LnMessageServer.java 28 Mar 2002 02:25:24 -0000 1.2
--- LnMessageServer.java 30 Mar 2002 00:38:06 -0000 1.3
***************
*** 1,69 ****
! package jmri.jmrix.loconet.locormi;
!
! /**
! * Title:
! * Description:
! * Copyright: Copyright (c) 2002
! * Company:
! * @author
! * @version $Id$
! */
!
! import java.rmi.server.UnicastRemoteObject;
! import java.rmi.RemoteException ;
! import java.rmi.Naming ;
! import jmri.jmrix.loconet.*;
! import java.io.Serializable;
!
! public class LnMessageServer extends UnicastRemoteObject implements LnMessageServerInterface
! {
! private static LnMessageServer self = null ;
! static final String serviceName = "LocoNetServer" ;
! static org.apache.log4j.Category log = org.apache.log4j.Category.getInstance(LnMessageServer.class.getName());
!
! private LnMessageServer() throws RemoteException
! {
! super() ;
! }
!
! public LnMessageBufferInterface getMessageBuffer() throws RemoteException
! {
! return new LnMessageBuffer() ;
! }
!
! public static synchronized LnMessageServer getInstance() throws RemoteException
! {
! if( self == null )
! {
! System.setSecurityManager( new java.rmi.RMISecurityManager() );
!
! self = new LnMessageServer() ;
! }
!
! return self ;
! }
!
! public synchronized void enable()
! {
! try
! {
! Naming.rebind( serviceName, self ) ;
! }
! catch( Exception ex )
! {
! log.warn( "Exception: " + ex );
! }
! }
!
! public synchronized void disable()
! {
! try
! {
! Naming.unbind( serviceName ) ;
! }
! catch( Exception ex )
! {
! log.fatal( "LnMessageBufferServer Exception: " + ex );
! }
! }
}
--- 1,71 ----
! package jmri.jmrix.loconet.locormi;
!
! /**
! * Title:
! * Description:
! * Copyright: Copyright (c) 2002
! * Company:
! * @author
! * @version $Id$
! */
!
! // -Djava.security.policy=lib/security.policy
!
! import java.rmi.server.UnicastRemoteObject;
! import java.rmi.RemoteException ;
! import java.rmi.Naming ;
! import jmri.jmrix.loconet.*;
! import java.io.Serializable;
!
! public class LnMessageServer extends UnicastRemoteObject implements LnMessageServerInterface
! {
! private static LnMessageServer self = null ;
! static final String serviceName = "LocoNetServer" ;
! static org.apache.log4j.Category log = org.apache.log4j.Category.getInstance(LnMessageServer.class.getName());
!
! private LnMessageServer() throws RemoteException
! {
! super() ;
! }
!
! public LnMessageBufferInterface getMessageBuffer() throws RemoteException
! {
! return new LnMessageBuffer() ;
! }
!
! public static synchronized LnMessageServer getInstance() throws RemoteException
! {
! if( self == null )
! {
! System.setSecurityManager( new java.rmi.RMISecurityManager() );
!
! self = new LnMessageServer() ;
! }
!
! return self ;
! }
!
! public synchronized void enable()
! {
! try
! {
! Naming.rebind( serviceName, self ) ;
! }
! catch( Exception ex )
! {
! log.warn( "Exception: " + ex );
! }
! }
!
! public synchronized void disable()
! {
! try
! {
! Naming.unbind( serviceName ) ;
! }
! catch( Exception ex )
! {
! log.fatal( "LnMessageBufferServer Exception: " + ex );
! }
! }
}
Index: LnMessageServerInterface.java
===================================================================
RCS file: /cvsroot/jmri/jmri/jmrix/loconet/locormi/LnMessageServerInterface.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -r1.2 -r1.3
*** LnMessageServerInterface.java 28 Mar 2002 02:25:24 -0000 1.2
--- LnMessageServerInterface.java 30 Mar 2002 00:38:06 -0000 1.3
***************
*** 1,20 ****
! package jmri.jmrix.loconet.locormi;
!
! /**
! * Title:
! * Description:
! * Copyright: Copyright (c) 2002
! * Company:
! * @author
! * @version $Id$
! */
!
! import java.rmi.Remote;
! import java.rmi.RemoteException;
! import jmri.jmrix.loconet.*;
!
! interface LnMessageServerInterface extends Remote
! {
! public LnMessageBufferInterface getMessageBuffer() throws RemoteException ;
!
}
--- 1,19 ----
! package jmri.jmrix.loconet.locormi;
!
! /**
! * Title:
! * Description:
! * Copyright: Copyright (c) 2002
! * Company:
! * @author
! * @version $Id$
! */
!
! import java.rmi.Remote;
! import java.rmi.RemoteException;
! import jmri.jmrix.loconet.*;
!
! interface LnMessageServerInterface extends Remote
! {
! public LnMessageBufferInterface getMessageBuffer() throws RemoteException ;
}
|