Refactored EvAServer + RMIServer(EvA) to use a logger. Syntax clean up and variable naming according to Java conventions.
This commit is contained in:
parent
df39ab0152
commit
e8b560a478
@ -10,6 +10,8 @@ import eva2.EvAInfo;
|
||||
import java.io.*;
|
||||
import java.net.InetAddress;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
/**
|
||||
*
|
||||
@ -24,16 +26,15 @@ public class EvAServer {
|
||||
public static String m_UserName;
|
||||
public static int m_NumberOfVM = 0;
|
||||
private RMIServerEvA m_RMIServer;
|
||||
private static final Logger logger = Logger.getLogger(EvAInfo.defaultLogger);
|
||||
|
||||
/**
|
||||
* Constructor of EvAServer. Calls RMIConnection().
|
||||
*/
|
||||
public EvAServer(boolean insideClient, boolean Restart) {
|
||||
System.out.println("Number of CPUs :" + Runtime.getRuntime().availableProcessors());
|
||||
System.out.println("*******************************************************************************");
|
||||
System.out.println("This is EvA Server Version: " + EvAInfo.getVersion());
|
||||
//System.out.println ("Java Version: " + System.getProperty("java.version") );
|
||||
System.out.println("*******************************************************************************");
|
||||
logger.log(Level.INFO, "Number of CPUs :" + Runtime.getRuntime().availableProcessors());
|
||||
logger.log(Level.INFO, "This is EvA Server Version: " + EvAInfo.getVersion());
|
||||
logger.log(Level.INFO, "Java Version: " + System.getProperty("java.version"));
|
||||
m_UserName = System.getProperty("user.name");
|
||||
// RMIConnection();
|
||||
// m_ComAdapter = new EvAComAdapter();
|
||||
|
@ -13,6 +13,7 @@ package eva2.server;
|
||||
*==========================================================================*/
|
||||
import eva2.tools.jproxy.RMIProxyLocal;
|
||||
import eva2.tools.jproxy.RMIServer;
|
||||
import java.util.logging.Level;
|
||||
|
||||
/**
|
||||
*
|
||||
@ -20,22 +21,22 @@ import eva2.tools.jproxy.RMIServer;
|
||||
public class RMIServerEvA extends RMIServer {
|
||||
|
||||
public static RMIServerEvA getInstance() {
|
||||
if (m_instance==null) {
|
||||
m_instance = new RMIServerEvA();
|
||||
if (instance==null) {
|
||||
instance = new RMIServerEvA();
|
||||
}
|
||||
return (RMIServerEvA)m_instance;
|
||||
return (RMIServerEvA)instance;
|
||||
}
|
||||
|
||||
protected void createMainRemoteObject(String mainAdapterName) {
|
||||
try {
|
||||
m_MainRemoteObject = new EvAMainAdapterImpl();
|
||||
m_MainRemoteObject =
|
||||
mainRemoteObject = new EvAMainAdapterImpl();
|
||||
mainRemoteObject =
|
||||
(EvAMainAdapter) RMIProxyLocal.newInstance(
|
||||
m_MainRemoteObject,
|
||||
mainAdapterName + "_" + m_NumberOfVM);
|
||||
m_MainRemoteObject.setRemoteThis(m_MainRemoteObject);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
mainRemoteObject,
|
||||
mainAdapterName + "_" + numberOfVM);
|
||||
mainRemoteObject.setRemoteThis(mainRemoteObject);
|
||||
} catch (Exception ex) {
|
||||
logger.log(Level.WARNING, "Could not create main remote object!", ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -9,60 +9,61 @@ package eva2.tools.jproxy;
|
||||
* $Author: ulmerh $
|
||||
*/
|
||||
|
||||
import eva2.EvAInfo;
|
||||
import java.net.InetAddress;
|
||||
import java.net.MalformedURLException;
|
||||
import java.rmi.Naming;
|
||||
import java.rmi.RemoteException;
|
||||
import java.rmi.registry.Registry;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public class RMIServer {
|
||||
/* Version string of the server application. */
|
||||
public static boolean TRACE = false;
|
||||
// public static Registry m_Registry;
|
||||
protected static RMIServer m_instance;
|
||||
protected static RMIServer instance;
|
||||
/* Name of host on which the server is running. */
|
||||
private String m_MyHostName = "undefined";
|
||||
private String myHostName = "undefined";
|
||||
/* IP of host on which the server is running. */
|
||||
private String m_MyHostIP = "undefined";
|
||||
private String myHostIP = "undefined";
|
||||
/* MainAdapterImp object. This is need for the first
|
||||
connection between the server and the client program. */
|
||||
public MainAdapter m_MainRemoteObject;
|
||||
protected MainAdapter mainRemoteObject;
|
||||
/* String describing the properties of the enviroment. */
|
||||
// private ComAdapter m_ComAdapter;
|
||||
public static String m_UserName;
|
||||
public static int m_NumberOfVM = 0;
|
||||
Registry m_Registry = null;
|
||||
protected static String userName;
|
||||
protected static int numberOfVM = 0;
|
||||
private Registry myRegistry = null;
|
||||
|
||||
protected static final Logger logger = Logger.getLogger(EvAInfo.defaultLogger);
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public static RMIServer getInstance() {
|
||||
if (m_instance == null) {
|
||||
m_instance = new RMIServer();
|
||||
}
|
||||
return m_instance;
|
||||
}
|
||||
public static RMIServer getInstance() {
|
||||
if (instance == null) {
|
||||
instance = new RMIServer();
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
/**
|
||||
* Constructor of EvAServer.
|
||||
* Calls RMIConnection().
|
||||
*/
|
||||
protected RMIServer() {
|
||||
m_UserName = System.getProperty("user.name");
|
||||
//System.out.println(EVAHELP.getSystemPropertyString());
|
||||
userName = System.getProperty("user.name");
|
||||
initConnection();
|
||||
// m_ComAdapter = ComAdapter.getInstance();
|
||||
}
|
||||
|
||||
/**
|
||||
* Main method of this class.
|
||||
* Is the starting point of the server application.
|
||||
*/
|
||||
static public void main(String[] args) {
|
||||
System.out.println("Start RMIServer !");
|
||||
RMIServer Application = RMIServer.getInstance();
|
||||
public static void main(String[] args) {
|
||||
logger.log(Level.INFO, "Start RMIServer !");
|
||||
RMIServer application = RMIServer.getInstance();
|
||||
}
|
||||
|
||||
|
||||
@ -72,99 +73,70 @@ public class RMIServer {
|
||||
* @param
|
||||
*/
|
||||
private void initConnection() {
|
||||
String MainAdapterName = m_UserName + MainAdapterImpl.MAIN_ADAPTER_NAME;
|
||||
String mainAdapterName = userName + MainAdapterImpl.MAIN_ADAPTER_NAME;
|
||||
System.setProperty("java.security.policy", "server.policy");
|
||||
launchRMIRegistry();
|
||||
try {
|
||||
m_MyHostIP = InetAddress.getLocalHost().getHostAddress();
|
||||
m_MyHostName = InetAddress.getLocalHost().getHostName();
|
||||
myHostIP = InetAddress.getLocalHost().getHostAddress();
|
||||
myHostName = InetAddress.getLocalHost().getHostName();
|
||||
} catch (Exception e) {
|
||||
System.out.println("ERROR getting HostName (RMIServer.initConnection)" + e.getMessage());
|
||||
logger.log(Level.SEVERE, "Error getting HostName " + e.getMessage(), e);
|
||||
}
|
||||
System.out.println("Start of EvA RMI-Server on host " + m_MyHostName + " = " + m_MyHostIP);
|
||||
// Object test = null;
|
||||
logger.log(Level.INFO, "Start of EvA RMI-Server on host " + myHostName + " = " + myHostIP);
|
||||
|
||||
try {
|
||||
try {
|
||||
String[] list =
|
||||
Naming.list("rmi://localhost:" + MainAdapterImpl.PORT);
|
||||
// System.out.println("-->list");
|
||||
// for (int i = 0; i < list.length; i++)
|
||||
// System.out.println("-->RMIName" + list[i]);
|
||||
m_NumberOfVM = getNumberOfVM(list);
|
||||
} catch (RemoteException e) {
|
||||
System.err.println("no RMI registry available yet...");
|
||||
if (TRACE)
|
||||
System.out.println(
|
||||
"RemoteException OK IAM the first server for this rmiregistry: "
|
||||
+ e.getMessage());
|
||||
}
|
||||
} catch (MalformedURLException ex) {
|
||||
System.out.println(
|
||||
"MalformedURLException: Error while looking up "
|
||||
+ ex.getMessage());
|
||||
}
|
||||
createMainRemoteObject(MainAdapterName);
|
||||
String[] list = Naming.list("rmi://localhost:" + MainAdapterImpl.PORT);
|
||||
numberOfVM = getNumberOfVM(list);
|
||||
} catch (RemoteException e) {
|
||||
logger.log(Level.WARNING, "No RMI registry available yet");
|
||||
} catch (MalformedURLException ex) {
|
||||
logger.log(Level.SEVERE, "MalformedURLException: Error while looking up " + ex.getMessage(), ex);
|
||||
}
|
||||
createMainRemoteObject(mainAdapterName);
|
||||
|
||||
System.out.println("End of RMI-Server Initialisation");
|
||||
System.out.println(" --> OK on Host: " + m_MyHostName + " = " + m_MyHostIP + ", adapter name is " + MainAdapterName);
|
||||
System.out.println("Waiting for a client ..............");
|
||||
logger.log(Level.INFO, "End of RMI-Server Initialisation");
|
||||
logger.log(Level.INFO, "Host: " + myHostName + " = " + myHostIP + ", adapter name is " + mainAdapterName);
|
||||
logger.log(Level.INFO, "Waiting for a client.");
|
||||
}
|
||||
|
||||
protected void createMainRemoteObject(String mainAdapterName) {
|
||||
try {
|
||||
m_MainRemoteObject = new MainAdapterImpl();
|
||||
m_MainRemoteObject =
|
||||
(MainAdapter) RMIProxyLocal.newInstance(m_MainRemoteObject,mainAdapterName + "_" + m_NumberOfVM);
|
||||
m_MainRemoteObject.setRemoteThis(m_MainRemoteObject);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
mainRemoteObject = new MainAdapterImpl();
|
||||
mainRemoteObject =
|
||||
(MainAdapter) RMIProxyLocal.newInstance(mainRemoteObject,mainAdapterName + "_" + numberOfVM);
|
||||
mainRemoteObject.setRemoteThis(mainRemoteObject);
|
||||
} catch (Exception ex) {
|
||||
logger.log(Level.WARNING, "Could not create main remote object!", ex);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public MainAdapter getMainRemoteObject() {
|
||||
return m_MainRemoteObject;
|
||||
return mainRemoteObject;
|
||||
}
|
||||
|
||||
/**
|
||||
* Install RMIregistry on default port !!
|
||||
*/
|
||||
private void launchRMIRegistry() {
|
||||
if (TRACE)
|
||||
System.out.println(
|
||||
"LaunchRMIRegistry on Server on PORT " + MainAdapterImpl.PORT);
|
||||
try {
|
||||
m_Registry =
|
||||
java.rmi.registry.LocateRegistry.createRegistry(
|
||||
MainAdapterImpl.PORT);
|
||||
} catch (Throwable e) {
|
||||
if (TRACE)
|
||||
System.out.println("Registry not created !!" + e.getMessage());
|
||||
m_Registry = null;
|
||||
}
|
||||
if (m_Registry == null) {
|
||||
System.out.println(
|
||||
"Try to get registry with getRegistry on PORT "
|
||||
+ MainAdapterImpl.PORT);
|
||||
try {
|
||||
m_Registry =
|
||||
java.rmi.registry.LocateRegistry.getRegistry(
|
||||
MainAdapterImpl.PORT);
|
||||
if (TRACE)
|
||||
System.out.println(
|
||||
"m_Registry.REGISTRY_PORT=" + m_Registry.REGISTRY_PORT);
|
||||
} catch (Throwable e) {
|
||||
if (TRACE)
|
||||
System.out.println(
|
||||
"registry notcreated !!" + e.getMessage());
|
||||
m_Registry = null;
|
||||
}
|
||||
}
|
||||
if (m_Registry == null) {
|
||||
System.err.println("--> got no RMIREGISTRY");
|
||||
} else if (TRACE) System.out.println("--> got RMIREGISTRY");
|
||||
myRegistry = java.rmi.registry.LocateRegistry.createRegistry(MainAdapterImpl.PORT);
|
||||
} catch (Throwable e) {
|
||||
myRegistry = null;
|
||||
}
|
||||
if (myRegistry == null) {
|
||||
logger.log(Level.INFO, "Try to get registry with getRegistry on port " + MainAdapterImpl.PORT);
|
||||
try {
|
||||
myRegistry = java.rmi.registry.LocateRegistry.getRegistry(MainAdapterImpl.PORT);
|
||||
} catch (RemoteException e) {
|
||||
myRegistry = null;
|
||||
}
|
||||
}
|
||||
if (myRegistry == null) {
|
||||
logger.log(Level.WARNING, "Got no RMIREGISTRY");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -176,8 +148,6 @@ public class RMIServer {
|
||||
if (list[i].indexOf(MainAdapterImpl.MAIN_ADAPTER_NAME) != -1)
|
||||
ret++;
|
||||
}
|
||||
if (TRACE)
|
||||
System.out.println(" getNumberOfVM() NumberOfVM =" + ret);
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user