Removed unused class LogProxy

Refactored tools package and removed debugging statements / replaced them with proper calls to the logger.
This commit is contained in:
Fabian Becker 2012-04-23 13:36:56 +00:00
parent e8b560a478
commit 17061b1475
5 changed files with 165 additions and 357 deletions

View File

@ -87,7 +87,6 @@ public class EvAComAdapter extends ComAdapter {
*/
public String[] getModuleNameList() {
String[] list;
if (TRACE) System.out.println("ComAdapter.GetModuleNameList()");
if ((m_RMIServer == null) && isRunLocally()) {
list = getLocalMainAdapter().getModuleNameList();
@ -117,12 +116,7 @@ public class EvAComAdapter extends ComAdapter {
}
return (MainAdapter) invocHandler.getWrapper();
}
protected void logInfo(String msg) {
if (m_LogPanel != null) {
m_LogPanel.logMessage(msg);
} else super.logInfo(msg);
}
protected RMIConnection createRMIConnection(String Host, MainAdapter mainRemoteObject, MainAdapterClient client) {
return new RMIConnectionEvA(Host, mainRemoteObject, client);

View File

@ -19,31 +19,31 @@ import eva2.tools.jproxy.MainAdapterClient;
import eva2.tools.jproxy.RMIProxyLocal;
import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import java.util.List;
import java.util.ArrayList;
import java.util.Properties;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
* Collect available ModuleAdapter implementations and load them on request.
*/
public class ModuleServer {
public static boolean TRACE = false;
private static final Logger logger = Logger.getLogger(eva2.EvAInfo.defaultLogger);
private int m_InstanceCounter = 0;
private ArrayList<Class<?>> m_ModuleClassList;
private List<Class<?>> moduleClassList;
// private ArrayList m_RunnungModules;
private ModuleAdapter m_ModuleAdapter;
private int m_ModuleAdapterCounter = 0;
private ModuleAdapter moduleAdapter;
private int moduleAdapterCounter = 0;
/**
*
*/
public ModuleServer(Properties EvAProps) {
if (TRACE)
System.out.println("Constructor ModuleServer():");
if (m_InstanceCounter > 0) {
EVAERROR.EXIT("ModuleServer twice created");
EVAERROR.EXIT("ModuleServer created twice");
}
// m_RunnungModules = new ArrayList();
m_ModuleClassList = new ArrayList<Class<?>>();
moduleClassList = new ArrayList<Class<?>>();
String modulePckg = null;
Class<?> filterBy = null;
@ -60,8 +60,7 @@ public class ModuleServer {
// this gets a list of all valid modules from the package
Class<?>[] classes = ReflectPackage.getAssignableClassesInPackage(modulePckg, filterBy, true, true);
for (Object cls : classes) {
if (TRACE) System.out.println("- " + ((Class<?>)cls).getName());
m_ModuleClassList.add((Class<?>)cls);
moduleClassList.add((Class<?>) cls);
}
m_InstanceCounter++;
@ -71,16 +70,16 @@ public class ModuleServer {
*
*/
public String[] getModuleNameList() {
ArrayList<String> ModuleNameList = new ArrayList<String>();
for (int i = 0; i < m_ModuleClassList.size(); i++) {
List<String> moduleNameList = new ArrayList<String>();
for (int i = 0; i < moduleClassList.size(); i++) {
try {
Class<?> Modul = (Class<?>) m_ModuleClassList.get(i);
Class<?> Modul = (Class<?>) moduleClassList.get(i);
Method[] methods = Modul.getDeclaredMethods();
for (int ii = 0; ii < methods.length; ii++) {
if (methods[ii].getName().equals("getName") == true) {
//System.out.println("name is =="+methods[ii].invoke(null,null));
String name = (String)methods[ii].invoke((Object[])null, (Object[])null);
if (name != null) ModuleNameList.add(name);
if (name != null) moduleNameList.add(name);
break;
}
}
@ -105,8 +104,8 @@ public class ModuleServer {
// ModuleNameList.add(AdapterName);
// }
String[] x = new String[ModuleNameList.size()];
ModuleNameList.toArray(x);
String[] x = new String[moduleNameList.size()];
moduleNameList.toArray(x);
return x;
}
@ -120,47 +119,40 @@ public class ModuleServer {
public ModuleAdapter createModuleAdapter(String selectedModuleName,
MainAdapterClient Client, boolean runWithoutRMI,
String hostAddress, InterfaceGOParameters goParams, String noGuiLogFile) {
m_ModuleAdapterCounter++;
String adapterName = new String("ERROR MODULADAPTER !!");
if (TRACE) {
System.out.println("ModuleServer.CreateModuleAdapter()");
System.out.println(" ModuleServer.CreateModuleAdapter for:" +
selectedModuleName);
System.out.println(" m_ModulAdapterCounter =" + m_ModuleAdapterCounter);
System.out.println(" Start of EvA RMI-ModulAdapter for Module: " +
selectedModuleName);
}
String moduleName;
moduleAdapterCounter++;
String adapterName = "ERROR MODULADAPTER !!";
String moduleName = null;
Class<?> module;
Method[] methods;
for (int i = 0; i < m_ModuleClassList.size(); i++) {
moduleName = null;
module = m_ModuleClassList.get(i);
for (int i = 0; i < moduleClassList.size(); i++) {
module = moduleClassList.get(i);
try {
methods = module.getDeclaredMethods();
for (int ii = 0; ii < methods.length; ii++) {
if (methods[ii].getName().equals("getName") == true)
moduleName = (String) methods[ii].invoke((Object[])null, (Object[])null);
if (methods[ii].getName().equals("getName") == true) {
moduleName = (String) methods[ii].invoke((Object[]) null, (Object[]) null);
}
}
}
catch (Exception e) {
System.err.println("ModuleServer.createModuleAdapter() " + e.getMessage());
e.printStackTrace();
catch (Exception ex) {
logger.log(Level.WARNING, ex.getMessage(), ex);
}
if ((moduleName != null) && (selectedModuleName.equals(moduleName))) {
if (TRACE) System.out.println("ModuleName: " + moduleName);
try {
adapterName = new String(m_ModuleAdapterCounter + "_Running_" +
selectedModuleName);
adapterName = moduleAdapterCounter + "_Running_" + selectedModuleName;
Constructor<?>[] constructorArr = module.getConstructors();
// create a module instance
int constrIndex=0;
/* create a module instance */
int constrIndex = 0;
if ((goParams==null && noGuiLogFile==null) || !module.equals(GOModuleAdapter.class)) {
if (goParams!=null) System.err.println("Cant set params - no matching constructor found for " + adapterName + " (ModuleServer)");
if (noGuiLogFile!=null) System.err.println("Cant deactivate GUI - no matching constructor found for " + adapterName + " (ModuleServer)");
if (goParams != null) {
System.err.println("Cant set params - no matching constructor found for " + adapterName + " (ModuleServer)");
}
if (noGuiLogFile != null) {
System.err.println("Cant deactivate GUI - no matching constructor found for " + adapterName + " (ModuleServer)");
}
Object[] Para = new Object[2];
while ((constructorArr[constrIndex].getParameterTypes().length!=2) && (constrIndex < constructorArr.length)) {
constrIndex++;
@ -168,35 +160,35 @@ public class ModuleServer {
Class<?> paramTypes[] = (constructorArr[constrIndex]).getParameterTypes();
Para[0] = paramTypes[0].cast(adapterName);
Para[1] = paramTypes[1].cast(Client);
m_ModuleAdapter = (ModuleAdapter) constructorArr[constrIndex].newInstance(Para);
moduleAdapter = (ModuleAdapter) constructorArr[constrIndex].newInstance(Para);
} else {
Object[] Para = new Object[4];
Para[0] = (String)adapterName;
Para[1] = (InterfaceGOParameters)goParams;
Para[2] = (String)noGuiLogFile;
Para[3] = (MainAdapterClient)Client;
Object[] param = new Object[4];
param[0] = (String)adapterName;
param[1] = (InterfaceGOParameters)goParams;
param[2] = (String)noGuiLogFile;
param[3] = (MainAdapterClient)Client;
while ((constructorArr[constrIndex].getParameterTypes().length!=4) && (constrIndex < constructorArr.length)) {
constrIndex++;
}
m_ModuleAdapter = (ModuleAdapter) constructorArr[constrIndex].newInstance(Para);
moduleAdapter = (ModuleAdapter) constructorArr[constrIndex].newInstance(param);
}
if (!runWithoutRMI) { // if we're using RMI, send the object to a remote server
// for this to work the class of m_ModuleAdapter itself must implement the ModuleAdapter interface
// for a strange reason, it is _not_ enough if a superclass implements the same interface!
m_ModuleAdapter = (ModuleAdapter)RMIProxyLocal.newInstance(m_ModuleAdapter, adapterName);
(m_ModuleAdapter).setRemoteThis(m_ModuleAdapter);
if (!runWithoutRMI) {
/* if we're using RMI, send the object to a remote server
* for this to work the class of moduleAdapter itself must
* implement the ModuleAdapter interface for a strange reason,
* it is _not_ enough if a superclass implements the same interface!
*/
moduleAdapter = (ModuleAdapter)RMIProxyLocal.newInstance(moduleAdapter, adapterName);
(moduleAdapter).setRemoteThis(moduleAdapter);
}
// m_RunnungModules.add(m_ModuleAdapter);
}
catch (Exception e) {
System.err.println("CLASSPATH " +
System.getProperty("java.class.path"));
e.printStackTrace();
EVAERROR.EXIT("Error in RMI-Moduladapter initialization: " + e.getMessage());
catch (Exception ex) {
logger.log(Level.SEVERE, "Error in RMI-Moduladapter initialization", ex);
EVAERROR.EXIT("Error in RMI-Moduladapter initialization: " + ex.getMessage());
return null;
}
if (TRACE) System.out.println("End of RMI-Moduladapter initialization !");
return (ModuleAdapter) m_ModuleAdapter;
}
return (ModuleAdapter) moduleAdapter;
}
}
// // @todo running modules sind gerade noch abgeschaltet
@ -215,7 +207,7 @@ public class ModuleServer {
// }
// }
System.err.println("NO VALID MODULE DEFINED: " + selectedModuleName);
logger.log(Level.SEVERE, "No valid module defined: {0}", selectedModuleName);
return null;
}
}

View File

@ -1,102 +0,0 @@
package eva2.tools;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
/*==========================================================================*
* CLASS DECLARATION
*==========================================================================*/
/**
*
*/
public class LogProxy implements InvocationHandler
{
//~ Static fields/initializers /////////////////////////////////////////////
public static final boolean TRACE = false;
//~ Instance fields ////////////////////////////////////////////////////////
private Object m_Object;
private String m_ObjectName;
private double m_timeges = 0;
private long m_counter = 0;
private long m_timestart = 0;
//~ Constructors ///////////////////////////////////////////////////////////
/**
*
*/
public LogProxy(Object obj)
{
m_Object = obj;
m_ObjectName = obj.getClass().getName();
m_timestart = System.currentTimeMillis();
}
//~ Methods ////////////////////////////////////////////////////////////////
/**
*
*/
public static Object newInstance(Object obj)
{
return Proxy.newProxyInstance(obj.getClass().getClassLoader(),
obj.getClass().getInterfaces(), new LogProxy(obj));
}
/**
*
*/
public Object invoke(Object proxy, Method m, Object[] args)
throws Throwable
{
long start = System.currentTimeMillis();
++m_counter;
Object ret = null;
try
{
//if (TRACE)System.out.println("Before invoke:" +m.getName());
long t = System.currentTimeMillis();
ret = m.invoke(m_Object, args);
long t2 = System.currentTimeMillis();
t = t2 - t;
m_timeges = m_timeges + t;
double x = m_timeges / ((double) (t2 - m_timestart));
System.out.println("x=" + x + "timeges" + m_timeges);
}
catch (InvocationTargetException e)
{
System.out.println("LogProxy: InvocationTargetException" +
e.getMessage());
}
catch (Exception e)
{
System.out.println("Exception" + e.getMessage());
}
finally
{
//long finish = System.currentTimeMillis();
//System.out.println("Calling :"+m.getName()+" of "+m_ObjectName+ " time :"+(finish-start));
}
if (ret == m_Object)
{
return this;
}
return ret;
}
}

View File

@ -22,24 +22,27 @@ import java.util.Properties;
import java.util.StringTokenizer;
import eva2.tools.Serializer;
import java.security.AccessControlException;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
*
*/
public class ComAdapter {
static final public boolean TRACE = false;
static final public int PORT = 1099;
static final public String SEP = "_";
private static final Logger logger = Logger.getLogger(eva2.EvAInfo.defaultLogger);
public static final int PORT = 1099;
public static final String SEP = "_";
static protected ComAdapter m_instance = null;
public Registry m_Registry = null;
private ArrayList<RMIConnection> m_Connections = new ArrayList<RMIConnection>();
private String m_ownHostName;
private String hostName;
private ArrayList<String> m_HostNameList = new ArrayList<String>();
private ArrayList<String> m_AvailableHostNameList = new ArrayList<String>();
// private String m_RemoteAdapterName;
private String m_UserName;
private String userName;
private int m_ownHostIndex = 0;
protected RMIServer m_RMIServer;
private String serverListSeparator = ",";
@ -59,12 +62,22 @@ public class ComAdapter {
*
*/
protected ComAdapter() {
if (TRACE) System.out.println("constructor ComAdapter");
m_UserName = System.getProperty("user.name");
m_ownHostName = "localhost"; //"192.168.0.1";
try {
userName = System.getProperty("user.name");
} catch(SecurityException ex) {
/* This exception is expected to happen when
* we are using Java WebStart.
*/
logger.log(Level.INFO, "Username set to: WebStart", ex);
userName = "Webstart";
}
hostName = "localhost"; //"192.168.0.1";
System.setProperty("java.security.policy", "server.policy");
try {
System.setProperty("java.security.policy", "server.policy");
} catch(AccessControlException ex) {
// ToDo: This happens using webstart - what to do now?
}
launchRMIRegistry(false);
if (!m_HostNameList.contains("localhost")) {
// make sure localhost is in the list
@ -85,10 +98,9 @@ public class ComAdapter {
while (st.hasMoreTokens()) {
String current = st.nextToken().trim();
if (!m_HostNameList.contains(current)) {
if (TRACE) System.out.println("adding server " + current);
m_HostNameList.add(current);
} else {
if (TRACE) System.out.println("server " + current + " was already in list");
logger.log(Level.FINER, "Server " + current + " was already in list");
}
}
}
@ -107,7 +119,7 @@ public class ComAdapter {
/**
* Set the separator for the server list string.
*
* @return
* @param sep List separator
*/
public void setServerListSeparator(String sep) {
serverListSeparator = sep;
@ -116,7 +128,7 @@ public class ComAdapter {
/**
* The separator for the server list string.
*
* @return
* @return The list separator
*/
public String getServerListSeparator() {
return serverListSeparator;
@ -124,9 +136,7 @@ public class ComAdapter {
/**
*
* @param c
* @param host
* @return
* @param server An array of servers
*/
public void setServerList(String[] server){
m_HostNameList.clear();
@ -140,10 +150,10 @@ public class ComAdapter {
*/
public RMIInvocationHandler getRMIHandler(Object c, String host) {
System.out.println("ComAdapter.getRMIHandler() for host " + host);
m_ownHostName = host;
hostName = host;
RMIInvocationHandler ret = null;
while (ret == null) {
ret = getConnection(m_ownHostName).getRMIHandler(c);
ret = getConnection(hostName).getRMIHandler(c);
if (ret == null)
System.out.println("Error in getRMIHandler");
}
@ -155,16 +165,15 @@ public class ComAdapter {
*
*/
public RMIThreadInvocationHandler getRMIThreadHandler(Object c, String host) {
if (TRACE)
System.out.println("ComAdapter.getRMIThreadHandler()");
int cnt=0;
m_ownHostName = host;
hostName = host;
RMIThreadInvocationHandler ret = null;
while (cnt<100) { //ret == null) {
cnt++;
ret = getConnection(m_ownHostName).getRMIThreadHandler(c);
if (ret == null)
System.err.println("Error in getRMIThreadHandler");
ret = getConnection(hostName).getRMIThreadHandler(c);
if (ret == null) {
logger.log(Level.WARNING, "Error in getRMIThreadHandler");
}
}
return ret;
}
@ -174,18 +183,17 @@ public class ComAdapter {
*
*/
public RMIThreadInvocationHandler getRMIThreadHandler(Object c) {
if (TRACE)
System.out.println("RMIThreadInvokationHandler getRMIThreadHandler");
RMIThreadInvocationHandler ret = null;
if (m_AvailableHostNameList.size() == 0) {
evalAvailableHostNameList();
m_ownHostIndex = 0;
}
m_ownHostIndex++;
if (m_ownHostIndex >= m_AvailableHostNameList.size())
if (m_ownHostIndex >= m_AvailableHostNameList.size()) {
m_ownHostIndex = 0;
m_ownHostName = (String) m_AvailableHostNameList.get(m_ownHostIndex);
ret = getRMIThreadHandler(c, m_ownHostName);
}
hostName = (String) m_AvailableHostNameList.get(m_ownHostIndex);
ret = getRMIThreadHandler(c, hostName);
return ret;
}
@ -194,20 +202,20 @@ public class ComAdapter {
*
*/
public RMIInvocationHandler getRMIHandler(Object c) {
if (TRACE)
System.out.println("RMIThreadInvokationHandler getRMIHandler");
RMIInvocationHandler ret = null;
while (m_AvailableHostNameList.size() == 0) {
evalAvailableHostNameList();
if (m_AvailableHostNameList.size() == 0)
System.err.println("no host availabe waiting !!");
if (m_AvailableHostNameList.size() == 0) {
logger.log(Level.WARNING, "No host availabe waiting..");
}
m_ownHostIndex = 0;
}
m_ownHostIndex++;
if (m_ownHostIndex >= m_AvailableHostNameList.size())
if (m_ownHostIndex >= m_AvailableHostNameList.size()) {
m_ownHostIndex = 0;
m_ownHostName = (String) m_AvailableHostNameList.get(m_ownHostIndex);
ret = getRMIHandler(c, m_ownHostName);
}
hostName = (String) m_AvailableHostNameList.get(m_ownHostIndex);
ret = getRMIHandler(c, hostName);
return ret;
}
@ -251,22 +259,20 @@ public class ComAdapter {
*/
public void evalAvailableHostNameList() {
long time = System.currentTimeMillis();
if (TRACE)
System.out.println("ComAdapter.getAvailableHostNameList()");
m_AvailableHostNameList.clear();
for (int i = 0; i < m_HostNameList.size(); i++) {
if (rmiPing((String) m_HostNameList.get(i)) == true)
if (rmiPing((String) m_HostNameList.get(i)) == true) {
m_AvailableHostNameList.add((String) m_HostNameList.get(i));
}
String testurl = (String) m_HostNameList.get(i);
for (int j = 1; j < 3; j++) {
if (rmiPing(testurl + "_" + j) == true) {
if (TRACE) System.out.println("found EvAServer on: " + testurl);
logger.log(Level.INFO, "Found EvAServer on: " + testurl);
m_AvailableHostNameList.add(testurl + "_" + j);
}
}
}
time = System.currentTimeMillis() - time;
if (TRACE) System.out.println("getAvailableHostNameList: " + m_AvailableHostNameList.size() + " found time " + time);
time = System.currentTimeMillis() - time;
}
@ -294,15 +300,15 @@ public class ComAdapter {
*
*/
public String getHostName() {
return m_ownHostName;
return hostName;
}
/**
*
*/
public void setHostName(String newHost) {
m_ownHostName = newHost;
Serializer.storeString("hostname.ser", m_ownHostName);
hostName = newHost;
Serializer.storeString("hostname.ser", hostName);
}
@ -311,8 +317,6 @@ public class ComAdapter {
* @return
*/
protected MainAdapter createRMIMainConnect(String HostToConnect) {
if (TRACE)
System.out.println("RMIMainConnect.RMIMainConnect() =" + HostToConnect);
int len = HostToConnect.indexOf(SEP);
String Host = HostToConnect;
String Number = SEP + "0";
@ -321,48 +325,24 @@ public class ComAdapter {
Host = st.nextToken().trim();
Number = SEP + st.nextToken().trim();
}
String MainAdapterName = m_UserName + MainAdapterImpl.MAIN_ADAPTER_NAME + Number; // attention
String MainAdapterName = userName + MainAdapterImpl.MAIN_ADAPTER_NAME + Number; // attention
logInfo(" RMIConnect to " + HostToConnect);
logger.info("RMIConnect to " + HostToConnect);
MainAdapter MainRemoteObject = null;
try {
try {
try {
//System.out.println("--> ComAdapter: "+"rmi://"+Host+":"+MainAdapterImpl.PORT+"/"+MainAdapterName);
// String[] list = Naming.list("rmi://" + Host + ":" +
// MainAdapterImpl.PORT);
//for (int i=0;i<list.length;i++)
// System.out.println("RMIName: "+list[i]);
//m_NumberOfVM = getNumberOfVM(list);
if (TRACE) System.out.println("getMain:" + "rmi://" + Host + ":" +
MainAdapterImpl.PORT + "/" + MainAdapterName);
RMIInvocationHandler invocHandler = (RMIInvocationHandler) Naming.lookup(
"rmi://" + Host + ":" + MainAdapterImpl.PORT + "/" +
MainAdapterName);
//System.out.println(" x ="+x.getClass().getName());
MainRemoteObject = getMainAdapter(invocHandler);
RMIInvocationHandler invocHandler = (RMIInvocationHandler) Naming.lookup(
"rmi://" + Host + ":" + MainAdapterImpl.PORT + "/"
+ MainAdapterName);
MainRemoteObject = getMainAdapter(invocHandler);
//MainRemoteObject = (MainAdapter)Naming.lookup("rmi://"+HostToConnect+":"+MainAdapterImpl.PORT+"/"+MainAdapterImpl.MAIN_ADAPTER_NAME);
//MainRemoteObject = (MainAdapter)LogProxy.newInstance(MainRemoteObject);
MainRemoteObject.setBuf("Ok.");
logInfo(" RMIConnect " + MainRemoteObject.getBuf());
} catch (MalformedURLException ex) {
System.err.println("MalformedURLException: Error while looking up " +
ex.getMessage());
}
} catch (NotBoundException ex) {
System.err.println("NotBoundException: Error while looking up " +
ex.getMessage());
ex.printStackTrace();
}
if (TRACE)
System.out.println("Connect to " + HostToConnect + " works fine");
} catch (RemoteException e) {
logInfo("Error while connecting Host: " + HostToConnect +
" \n ERROR: " + e.getMessage());
System.err.println("Error while connecting Host: " + HostToConnect +
" \n ERROR: " + e.getMessage());
MainRemoteObject.setBuf("Ok.");
logger.info("RMIConnect " + MainRemoteObject.getBuf());
} catch (MalformedURLException ex) {
logger.log(Level.WARNING, "MalformedURLException: Error while looking up " + ex.getMessage(), ex);
} catch (NotBoundException ex) {
logger.log(Level.WARNING, "NotBoundException: Error while looking up " + ex.getMessage(), ex);
} catch (RemoteException ex) {
logger.log(Level.WARNING, "Error while connecting Host: " + HostToConnect, ex);
return null;
}
return MainRemoteObject;
@ -372,10 +352,6 @@ public class ComAdapter {
return (MainAdapter) invocHandler.getWrapper();
}
protected void logInfo(String msg) {
System.out.println("ComAdapter-Log: " + msg);
}
/**
*
*/
@ -385,8 +361,6 @@ public class ComAdapter {
try {
list = Naming.list("rmi://" + testurl + ":" + MainAdapterImpl.PORT);
} catch (Exception e) {
//if (TRACE && m_LogPanel!=null) m_LogPanel.logMessage ("No connecting to : "+testurl );
//if (TRACE) System.out.println ("No connecting to : "+testurl );
System.err.println ("Exception : "+testurl );
return 0;
}
@ -404,10 +378,7 @@ public class ComAdapter {
*
*/
private boolean rmiPing(String testurl) {
if (TRACE)
System.out.println("ComAdapter.rmiPing " + testurl);
MainAdapter Test = null;
// String Load = null;
int len = testurl.indexOf(SEP);
String Host = testurl;
String Number = "_0";
@ -416,30 +387,16 @@ public class ComAdapter {
Host = st.nextToken().trim();
Number = SEP + st.nextToken().trim();
}
String MainAdapterName = m_UserName + MainAdapterImpl.MAIN_ADAPTER_NAME +
String mainAdapterName = userName + MainAdapterImpl.MAIN_ADAPTER_NAME +
Number;
try {
if (TRACE)
System.out.println("ping:" + "rmi://" + Host + ":" +
MainAdapterImpl.PORT + "/" + MainAdapterName);
RMIInvocationHandler x = (RMIInvocationHandler) Naming.lookup("rmi://" +
Host + ":" + MainAdapterImpl.PORT + "/" + MainAdapterName); // attention !!
Host + ":" + MainAdapterImpl.PORT + "/" + mainAdapterName); // attention !!
Test = (MainAdapter) x.getWrapper();
// if (Test != null) {
// Load = Test.getExecOutput("rup " + testurl);
// }
} catch (Exception e) {
if (TRACE) {
logInfo("No connection to : " + testurl);
System.out.println("ComAdapter.rmiPing false " + e.getMessage());
}
} catch (Exception ex) {
logger.log(Level.INFO, "No connection to : " + testurl, ex);
return false;
}
if (Test != null) {
if (TRACE) logInfo("ping succeeded");
}
if (TRACE)
System.out.println("ComAdapter.rmiPing true");
return true;
}
@ -447,8 +404,6 @@ public class ComAdapter {
*
*/
public void killServer(String ServerToKill) {
if (TRACE)
System.out.println("ComAdapter.Killing Server :" + ServerToKill);
RMIConnection myConnection = getConnection(ServerToKill);
myConnection.killServer();
this.m_Connections.remove(myConnection);
@ -458,8 +413,6 @@ public class ComAdapter {
*
*/
public void killAllServers() {
if (TRACE)
System.out.println("ComAdapter.Killing All Servers :");
for (int i = 0; i < m_AvailableHostNameList.size(); i++) {
RMIConnection myConnection = getConnection((String)
m_AvailableHostNameList.get(i));
@ -472,7 +425,6 @@ public class ComAdapter {
*
*/
public void restartServerAllServer() {
if (TRACE) System.out.println("ComAdapter.restartServerAllServer :");
for (int i = 0; i < m_AvailableHostNameList.size(); i++) {
RMIConnection myConnection = getConnection((String)
m_AvailableHostNameList.get(i));
@ -485,7 +437,7 @@ public class ComAdapter {
*
*/
public void restartServer(String host) {
m_ownHostName = host;
hostName = host;
restartServer();
}
@ -493,17 +445,10 @@ public class ComAdapter {
*
*/
public void restartServer() {
if (TRACE)
System.out.println("ComAdapter.restartServer");
if (TRACE)
System.out.println("m_ActualHostName = " + m_ownHostName);
// System.out.println("m_ActualHostName = " + m_ActualHostName);
if (m_ownHostName.equals("localhost")) { // TODO whats this?
if (hostName.equals("localhost")) { // TODO whats this?
return;
}
if (TRACE == true)
System.out.println("ComAdapter.restartServer Server :" + m_ownHostName);
RMIConnection x = getConnection(m_ownHostName);
RMIConnection x = getConnection(hostName);
x.restartServer();
m_Connections.remove(x);
try {
@ -553,7 +498,6 @@ public class ComAdapter {
*
*/
protected RMIConnection getConnection(String Host) {
if (TRACE) System.out.println("ComAdapter.getConnection for host :" + Host);
for (int i = 0; i < this.m_Connections.size(); i++) {
// search for an already established connection to the given host
// and return it if found

View File

@ -814,25 +814,26 @@ public class Mathematics {
* @return the closest value to v within [min,max]
*/
public static double projectValue(double v, double min, double max) {
double value;
if (v < min) {
return min;
value = min;
} else if (v > max) {
return max;
} else
return v;
value = max;
} else {
value = v;
}
return value;
}
/**
* Create a random vector, the components will be set to gaussian
* Create a random vector, the components will be set to Gaussian
* distributed values with mean zero and the given standard deviation.
*
* @param dim
* the desired dimension
* @param stdDev
* the gaussian standard deviation
*
* @param dim The desired dimension
* @param stdDev The Gaussian standard deviation
* @return random vector
*/
public static double[] randomVector(int dim, double stdDev) {
public static double[] randomVector(final int dim, final double stdDev) {
double[] vect = new double[dim];
for (int j = 0; j < vect.length; j++) {
vect[j] = RNG.gaussianDouble(stdDev);
@ -843,10 +844,10 @@ public class Mathematics {
/**
* Reflect the entries of x which violate the bounds to within the range.
* Return the number of violating dimensions.
*
*
* @param x
* @param range
* @return the number of violating dimensions
* @return The number of violating dimensions
*/
public static int reflectBounds(double[] x, double[][] range) {
int viols = 0;
@ -854,8 +855,7 @@ public class Mathematics {
for (int i = 0; i < x.length; i++) {
double dimLen = range[i][1] - range[i][0];
if (dimLen <= 0.) {
EVAERROR
.errorMsgOnce("Error in reflectBounds: empty range! (possibly multiple errors)");
EVAERROR.errorMsgOnce("Error in reflectBounds: empty range! (possibly multiple errors)");
} else {
if (x[i] < range[i][0]) {
viols++;
@ -867,8 +867,9 @@ public class Mathematics {
} else if (x[i] > range[i][1]) {
viols++;
d = x[i] - range[i][1];
while (d > dimLen)
while (d > dimLen) {
d -= dimLen; // avoid violating the other bound
}
// immediately
x[i] = range[i][1] - d;
}
@ -890,12 +891,15 @@ public class Mathematics {
*/
public static double reflectValue(double val, double step, double min,
double max) {
while (step > (max - min))
while (step > (max - min)) {
step -= (max - min);
if ((val + step) > max)
}
if ((val + step) > max) {
return (2 * max - val - step);
if ((val + step) < min)
}
if ((val + step) < min) {
return (2 * min - val - step);
}
return (val += step);
}
@ -916,15 +920,17 @@ public class Mathematics {
*/
public static double relDist(double[] x, double[] y, double def)
throws Exception {
if (x.length != y.length)
throw new Exception(
"The vectors x and y must have the same dimension");
if (x.length != y.length) {
throw new Exception("The vectors x and y must have the same dimension");
}
double d = 0;
for (int i = 0; i < x.length; i++)
if (y[i] != 0)
for (int i = 0; i < x.length; i++) {
if (y[i] != 0) {
d += Math.pow(((x[i] - y[i]) / y[i]), 2);
else
} else {
d += def;
}
}
return d;
}
@ -943,8 +949,9 @@ public class Mathematics {
for (int i = 0; i < src.length; i++) {
dst[src.length - i - 1] = src[i];
}
} else
} else {
System.err.println("Mismatching array lengths!");
}
}
/**
@ -1015,7 +1022,7 @@ public class Mathematics {
/**
* Scale a range by the given factor, meaning that the interval in each
* dimension is extended (fact>1) or reduced (fact<1) by the defined ratio
* dimension is extended (fact>1) or reduced (fact < 1) by the defined ratio
* around the center.
*
* @param rangeScaleFact
@ -1059,33 +1066,6 @@ public class Mathematics {
}
}
// <<<<<<< .working
// /**
// * Computes a spline interpolation of the two point (x0,f0) and (x1,f1).
// *
// * @param x
// * @param x0
// * @param x1
// * @param f0
// * @param f1
// * @return If an error with the spline occurs, a linear interpolation will
// be
// * returned.
// */
// /* public static double splineInterpolation(double x, double x0, double
// x1,
// double f0, double f1) {
// try {
// double[] t = { x0, x1 }, f = { f0, f1 };
// SplineInterpolation spline = new SplineInterpolation(new BasicDataSet(t,
// f, 1));
// return spline.getY(x);
// } catch (InterpolationException e) {
// e.printStackTrace();
// }
// return linearInterpolation(x, x0, x1, f0, f1);
// }*/
// =======
/**
* Computes a spline interpolation of the two point (x0,f0) and (x1,f1).
*