|
From: Bob J. <jac...@us...> - 2002-03-30 06:05:00
|
Update of /cvsroot/jmri/jmri/jmrix/loconet/locormi
In directory usw-pr-cvs1:/tmp/cvs-serv2048/locormi
Modified Files:
LnMessageClient.java LnMessageServer.java
Log Message:
added some more debugging info when the RMI startup fails
Index: LnMessageClient.java
===================================================================
RCS file: /cvsroot/jmri/jmri/jmrix/loconet/locormi/LnMessageClient.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -r1.2 -r1.3
*** LnMessageClient.java 30 Mar 2002 00:38:06 -0000 1.2
--- LnMessageClient.java 30 Mar 2002 06:04:57 -0000 1.3
***************
*** 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());
}
--- 1,117 ----
! 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());
! log.debug("security manager set, set interface to //"
! +remoteHostName+"//"
! +LnMessageServer.serviceName );
! LnMessageServerInterface lnServer = (LnMessageServerInterface) java.rmi.Naming.lookup(
! "//" + serverName + "/" + LnMessageServer.serviceName );
!
! lnMessageBuffer = lnServer.getMessageBuffer() ;
! lnMessageBuffer.enable( 0 );
! pollThread = new LnMessageClientPollThread( this ) ;
! }
! catch( Exception ex ){
! log.error( "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: LnMessageServer.java
===================================================================
RCS file: /cvsroot/jmri/jmri/jmrix/loconet/locormi/LnMessageServer.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -r1.3 -r1.4
*** LnMessageServer.java 30 Mar 2002 00:38:06 -0000 1.3
--- LnMessageServer.java 30 Mar 2002 06:04:57 -0000 1.4
***************
*** 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 );
! }
! }
}
--- 1,73 ----
! 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
! {
! log.debug("attempt rebind for "+serviceName);
! Naming.rebind( serviceName, self ) ;
! log.debug("rebind completed");
! }
! catch( Exception ex )
! {
! log.warn( "Exception during enable: " + ex );
! }
! }
!
! public synchronized void disable()
! {
! try
! {
! Naming.unbind( serviceName ) ;
! }
! catch( Exception ex )
! {
! log.fatal( "Exception during disable: " + ex );
! }
! }
}
|