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() { public String[] getModuleNameList() {
String[] list; String[] list;
if (TRACE) System.out.println("ComAdapter.GetModuleNameList()");
if ((m_RMIServer == null) && isRunLocally()) { if ((m_RMIServer == null) && isRunLocally()) {
list = getLocalMainAdapter().getModuleNameList(); list = getLocalMainAdapter().getModuleNameList();
@ -118,11 +117,6 @@ public class EvAComAdapter extends ComAdapter {
return (MainAdapter) invocHandler.getWrapper(); 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) { protected RMIConnection createRMIConnection(String Host, MainAdapter mainRemoteObject, MainAdapterClient client) {
return new RMIConnectionEvA(Host, mainRemoteObject, client); return new RMIConnectionEvA(Host, mainRemoteObject, client);

View File

@ -19,31 +19,31 @@ import eva2.tools.jproxy.MainAdapterClient;
import eva2.tools.jproxy.RMIProxyLocal; import eva2.tools.jproxy.RMIProxyLocal;
import java.lang.reflect.Constructor; import java.lang.reflect.Constructor;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.util.List;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Properties; import java.util.Properties;
import java.util.logging.Level;
import java.util.logging.Logger;
/** /**
* Collect available ModuleAdapter implementations and load them on request. * Collect available ModuleAdapter implementations and load them on request.
*/ */
public class ModuleServer { public class ModuleServer {
public static boolean TRACE = false; private static final Logger logger = Logger.getLogger(eva2.EvAInfo.defaultLogger);
private int m_InstanceCounter = 0; private int m_InstanceCounter = 0;
private ArrayList<Class<?>> m_ModuleClassList; private List<Class<?>> moduleClassList;
// private ArrayList m_RunnungModules; // private ArrayList m_RunnungModules;
private ModuleAdapter m_ModuleAdapter; private ModuleAdapter moduleAdapter;
private int m_ModuleAdapterCounter = 0; private int moduleAdapterCounter = 0;
/** /**
* *
*/ */
public ModuleServer(Properties EvAProps) { public ModuleServer(Properties EvAProps) {
if (TRACE)
System.out.println("Constructor ModuleServer():");
if (m_InstanceCounter > 0) { if (m_InstanceCounter > 0) {
EVAERROR.EXIT("ModuleServer twice created"); EVAERROR.EXIT("ModuleServer created twice");
} }
// m_RunnungModules = new ArrayList(); moduleClassList = new ArrayList<Class<?>>();
m_ModuleClassList = new ArrayList<Class<?>>();
String modulePckg = null; String modulePckg = null;
Class<?> filterBy = null; Class<?> filterBy = null;
@ -60,8 +60,7 @@ public class ModuleServer {
// this gets a list of all valid modules from the package // this gets a list of all valid modules from the package
Class<?>[] classes = ReflectPackage.getAssignableClassesInPackage(modulePckg, filterBy, true, true); Class<?>[] classes = ReflectPackage.getAssignableClassesInPackage(modulePckg, filterBy, true, true);
for (Object cls : classes) { for (Object cls : classes) {
if (TRACE) System.out.println("- " + ((Class<?>)cls).getName()); moduleClassList.add((Class<?>) cls);
m_ModuleClassList.add((Class<?>)cls);
} }
m_InstanceCounter++; m_InstanceCounter++;
@ -71,16 +70,16 @@ public class ModuleServer {
* *
*/ */
public String[] getModuleNameList() { public String[] getModuleNameList() {
ArrayList<String> ModuleNameList = new ArrayList<String>(); List<String> moduleNameList = new ArrayList<String>();
for (int i = 0; i < m_ModuleClassList.size(); i++) { for (int i = 0; i < moduleClassList.size(); i++) {
try { try {
Class<?> Modul = (Class<?>) m_ModuleClassList.get(i); Class<?> Modul = (Class<?>) moduleClassList.get(i);
Method[] methods = Modul.getDeclaredMethods(); Method[] methods = Modul.getDeclaredMethods();
for (int ii = 0; ii < methods.length; ii++) { for (int ii = 0; ii < methods.length; ii++) {
if (methods[ii].getName().equals("getName") == true) { if (methods[ii].getName().equals("getName") == true) {
//System.out.println("name is =="+methods[ii].invoke(null,null)); //System.out.println("name is =="+methods[ii].invoke(null,null));
String name = (String)methods[ii].invoke((Object[])null, (Object[])null); String name = (String)methods[ii].invoke((Object[])null, (Object[])null);
if (name != null) ModuleNameList.add(name); if (name != null) moduleNameList.add(name);
break; break;
} }
} }
@ -105,8 +104,8 @@ public class ModuleServer {
// ModuleNameList.add(AdapterName); // ModuleNameList.add(AdapterName);
// } // }
String[] x = new String[ModuleNameList.size()]; String[] x = new String[moduleNameList.size()];
ModuleNameList.toArray(x); moduleNameList.toArray(x);
return x; return x;
} }
@ -120,47 +119,40 @@ public class ModuleServer {
public ModuleAdapter createModuleAdapter(String selectedModuleName, public ModuleAdapter createModuleAdapter(String selectedModuleName,
MainAdapterClient Client, boolean runWithoutRMI, MainAdapterClient Client, boolean runWithoutRMI,
String hostAddress, InterfaceGOParameters goParams, String noGuiLogFile) { String hostAddress, InterfaceGOParameters goParams, String noGuiLogFile) {
m_ModuleAdapterCounter++; moduleAdapterCounter++;
String adapterName = new String("ERROR MODULADAPTER !!"); String adapterName = "ERROR MODULADAPTER !!";
if (TRACE) { String moduleName = null;
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;
Class<?> module; Class<?> module;
Method[] methods; Method[] methods;
for (int i = 0; i < m_ModuleClassList.size(); i++) { for (int i = 0; i < moduleClassList.size(); i++) {
moduleName = null; module = moduleClassList.get(i);
module = m_ModuleClassList.get(i);
try { try {
methods = module.getDeclaredMethods(); methods = module.getDeclaredMethods();
for (int ii = 0; ii < methods.length; ii++) { for (int ii = 0; ii < methods.length; ii++) {
if (methods[ii].getName().equals("getName") == true) if (methods[ii].getName().equals("getName") == true) {
moduleName = (String) methods[ii].invoke((Object[]) null, (Object[]) null); moduleName = (String) methods[ii].invoke((Object[]) null, (Object[]) null);
} }
} }
catch (Exception e) { }
System.err.println("ModuleServer.createModuleAdapter() " + e.getMessage()); catch (Exception ex) {
e.printStackTrace(); logger.log(Level.WARNING, ex.getMessage(), ex);
} }
if ((moduleName != null) && (selectedModuleName.equals(moduleName))) { if ((moduleName != null) && (selectedModuleName.equals(moduleName))) {
if (TRACE) System.out.println("ModuleName: " + moduleName);
try { try {
adapterName = new String(m_ModuleAdapterCounter + "_Running_" + adapterName = moduleAdapterCounter + "_Running_" + selectedModuleName;
selectedModuleName);
Constructor<?>[] constructorArr = module.getConstructors(); Constructor<?>[] constructorArr = module.getConstructors();
// create a module instance /* create a module instance */
int constrIndex = 0; int constrIndex = 0;
if ((goParams==null && noGuiLogFile==null) || !module.equals(GOModuleAdapter.class)) { 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 (goParams != null) {
if (noGuiLogFile!=null) System.err.println("Cant deactivate GUI - no matching constructor found for " + adapterName + " (ModuleServer)"); 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]; Object[] Para = new Object[2];
while ((constructorArr[constrIndex].getParameterTypes().length!=2) && (constrIndex < constructorArr.length)) { while ((constructorArr[constrIndex].getParameterTypes().length!=2) && (constrIndex < constructorArr.length)) {
constrIndex++; constrIndex++;
@ -168,35 +160,35 @@ public class ModuleServer {
Class<?> paramTypes[] = (constructorArr[constrIndex]).getParameterTypes(); Class<?> paramTypes[] = (constructorArr[constrIndex]).getParameterTypes();
Para[0] = paramTypes[0].cast(adapterName); Para[0] = paramTypes[0].cast(adapterName);
Para[1] = paramTypes[1].cast(Client); Para[1] = paramTypes[1].cast(Client);
m_ModuleAdapter = (ModuleAdapter) constructorArr[constrIndex].newInstance(Para); moduleAdapter = (ModuleAdapter) constructorArr[constrIndex].newInstance(Para);
} else { } else {
Object[] Para = new Object[4]; Object[] param = new Object[4];
Para[0] = (String)adapterName; param[0] = (String)adapterName;
Para[1] = (InterfaceGOParameters)goParams; param[1] = (InterfaceGOParameters)goParams;
Para[2] = (String)noGuiLogFile; param[2] = (String)noGuiLogFile;
Para[3] = (MainAdapterClient)Client; param[3] = (MainAdapterClient)Client;
while ((constructorArr[constrIndex].getParameterTypes().length!=4) && (constrIndex < constructorArr.length)) { while ((constructorArr[constrIndex].getParameterTypes().length!=4) && (constrIndex < constructorArr.length)) {
constrIndex++; 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 if (!runWithoutRMI) {
// for this to work the class of m_ModuleAdapter itself must implement the ModuleAdapter interface /* if we're using RMI, send the object to a remote server
// for a strange reason, it is _not_ enough if a superclass implements the same interface! * for this to work the class of moduleAdapter itself must
m_ModuleAdapter = (ModuleAdapter)RMIProxyLocal.newInstance(m_ModuleAdapter, adapterName); * implement the ModuleAdapter interface for a strange reason,
(m_ModuleAdapter).setRemoteThis(m_ModuleAdapter); * 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); // m_RunnungModules.add(m_ModuleAdapter);
} }
catch (Exception e) { catch (Exception ex) {
System.err.println("CLASSPATH " + logger.log(Level.SEVERE, "Error in RMI-Moduladapter initialization", ex);
System.getProperty("java.class.path")); EVAERROR.EXIT("Error in RMI-Moduladapter initialization: " + ex.getMessage());
e.printStackTrace();
EVAERROR.EXIT("Error in RMI-Moduladapter initialization: " + e.getMessage());
return null; return null;
} }
if (TRACE) System.out.println("End of RMI-Moduladapter initialization !"); return (ModuleAdapter) moduleAdapter;
return (ModuleAdapter) m_ModuleAdapter;
} }
} }
// // @todo running modules sind gerade noch abgeschaltet // // @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; 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 java.util.StringTokenizer;
import eva2.tools.Serializer; import eva2.tools.Serializer;
import java.security.AccessControlException;
import java.util.logging.Level;
import java.util.logging.Logger;
/** /**
* *
*/ */
public class ComAdapter { public class ComAdapter {
static final public boolean TRACE = false; private static final Logger logger = Logger.getLogger(eva2.EvAInfo.defaultLogger);
static final public int PORT = 1099; public static final int PORT = 1099;
static final public String SEP = "_"; public static final String SEP = "_";
static protected ComAdapter m_instance = null; static protected ComAdapter m_instance = null;
public Registry m_Registry = null; public Registry m_Registry = null;
private ArrayList<RMIConnection> m_Connections = new ArrayList<RMIConnection>(); 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_HostNameList = new ArrayList<String>();
private ArrayList<String> m_AvailableHostNameList = new ArrayList<String>(); private ArrayList<String> m_AvailableHostNameList = new ArrayList<String>();
// private String m_RemoteAdapterName; // private String m_RemoteAdapterName;
private String m_UserName; private String userName;
private int m_ownHostIndex = 0; private int m_ownHostIndex = 0;
protected RMIServer m_RMIServer; protected RMIServer m_RMIServer;
private String serverListSeparator = ","; private String serverListSeparator = ",";
@ -59,12 +62,22 @@ public class ComAdapter {
* *
*/ */
protected ComAdapter() { protected ComAdapter() {
if (TRACE) System.out.println("constructor ComAdapter"); try {
m_UserName = System.getProperty("user.name"); userName = System.getProperty("user.name");
} catch(SecurityException ex) {
m_ownHostName = "localhost"; //"192.168.0.1"; /* 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";
try {
System.setProperty("java.security.policy", "server.policy"); System.setProperty("java.security.policy", "server.policy");
} catch(AccessControlException ex) {
// ToDo: This happens using webstart - what to do now?
}
launchRMIRegistry(false); launchRMIRegistry(false);
if (!m_HostNameList.contains("localhost")) { if (!m_HostNameList.contains("localhost")) {
// make sure localhost is in the list // make sure localhost is in the list
@ -85,10 +98,9 @@ public class ComAdapter {
while (st.hasMoreTokens()) { while (st.hasMoreTokens()) {
String current = st.nextToken().trim(); String current = st.nextToken().trim();
if (!m_HostNameList.contains(current)) { if (!m_HostNameList.contains(current)) {
if (TRACE) System.out.println("adding server " + current);
m_HostNameList.add(current); m_HostNameList.add(current);
} else { } 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. * Set the separator for the server list string.
* *
* @return * @param sep List separator
*/ */
public void setServerListSeparator(String sep) { public void setServerListSeparator(String sep) {
serverListSeparator = sep; serverListSeparator = sep;
@ -116,7 +128,7 @@ public class ComAdapter {
/** /**
* The separator for the server list string. * The separator for the server list string.
* *
* @return * @return The list separator
*/ */
public String getServerListSeparator() { public String getServerListSeparator() {
return serverListSeparator; return serverListSeparator;
@ -124,9 +136,7 @@ public class ComAdapter {
/** /**
* *
* @param c * @param server An array of servers
* @param host
* @return
*/ */
public void setServerList(String[] server){ public void setServerList(String[] server){
m_HostNameList.clear(); m_HostNameList.clear();
@ -140,10 +150,10 @@ public class ComAdapter {
*/ */
public RMIInvocationHandler getRMIHandler(Object c, String host) { public RMIInvocationHandler getRMIHandler(Object c, String host) {
System.out.println("ComAdapter.getRMIHandler() for host " + host); System.out.println("ComAdapter.getRMIHandler() for host " + host);
m_ownHostName = host; hostName = host;
RMIInvocationHandler ret = null; RMIInvocationHandler ret = null;
while (ret == null) { while (ret == null) {
ret = getConnection(m_ownHostName).getRMIHandler(c); ret = getConnection(hostName).getRMIHandler(c);
if (ret == null) if (ret == null)
System.out.println("Error in getRMIHandler"); System.out.println("Error in getRMIHandler");
} }
@ -155,16 +165,15 @@ public class ComAdapter {
* *
*/ */
public RMIThreadInvocationHandler getRMIThreadHandler(Object c, String host) { public RMIThreadInvocationHandler getRMIThreadHandler(Object c, String host) {
if (TRACE)
System.out.println("ComAdapter.getRMIThreadHandler()");
int cnt=0; int cnt=0;
m_ownHostName = host; hostName = host;
RMIThreadInvocationHandler ret = null; RMIThreadInvocationHandler ret = null;
while (cnt<100) { //ret == null) { while (cnt<100) { //ret == null) {
cnt++; cnt++;
ret = getConnection(m_ownHostName).getRMIThreadHandler(c); ret = getConnection(hostName).getRMIThreadHandler(c);
if (ret == null) if (ret == null) {
System.err.println("Error in getRMIThreadHandler"); logger.log(Level.WARNING, "Error in getRMIThreadHandler");
}
} }
return ret; return ret;
} }
@ -174,18 +183,17 @@ public class ComAdapter {
* *
*/ */
public RMIThreadInvocationHandler getRMIThreadHandler(Object c) { public RMIThreadInvocationHandler getRMIThreadHandler(Object c) {
if (TRACE)
System.out.println("RMIThreadInvokationHandler getRMIThreadHandler");
RMIThreadInvocationHandler ret = null; RMIThreadInvocationHandler ret = null;
if (m_AvailableHostNameList.size() == 0) { if (m_AvailableHostNameList.size() == 0) {
evalAvailableHostNameList(); evalAvailableHostNameList();
m_ownHostIndex = 0; m_ownHostIndex = 0;
} }
m_ownHostIndex++; m_ownHostIndex++;
if (m_ownHostIndex >= m_AvailableHostNameList.size()) if (m_ownHostIndex >= m_AvailableHostNameList.size()) {
m_ownHostIndex = 0; 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; return ret;
} }
@ -194,20 +202,20 @@ public class ComAdapter {
* *
*/ */
public RMIInvocationHandler getRMIHandler(Object c) { public RMIInvocationHandler getRMIHandler(Object c) {
if (TRACE)
System.out.println("RMIThreadInvokationHandler getRMIHandler");
RMIInvocationHandler ret = null; RMIInvocationHandler ret = null;
while (m_AvailableHostNameList.size() == 0) { while (m_AvailableHostNameList.size() == 0) {
evalAvailableHostNameList(); evalAvailableHostNameList();
if (m_AvailableHostNameList.size() == 0) if (m_AvailableHostNameList.size() == 0) {
System.err.println("no host availabe waiting !!"); logger.log(Level.WARNING, "No host availabe waiting..");
}
m_ownHostIndex = 0; m_ownHostIndex = 0;
} }
m_ownHostIndex++; m_ownHostIndex++;
if (m_ownHostIndex >= m_AvailableHostNameList.size()) if (m_ownHostIndex >= m_AvailableHostNameList.size()) {
m_ownHostIndex = 0; 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; return ret;
} }
@ -251,22 +259,20 @@ public class ComAdapter {
*/ */
public void evalAvailableHostNameList() { public void evalAvailableHostNameList() {
long time = System.currentTimeMillis(); long time = System.currentTimeMillis();
if (TRACE)
System.out.println("ComAdapter.getAvailableHostNameList()");
m_AvailableHostNameList.clear(); m_AvailableHostNameList.clear();
for (int i = 0; i < m_HostNameList.size(); i++) { 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)); m_AvailableHostNameList.add((String) m_HostNameList.get(i));
}
String testurl = (String) m_HostNameList.get(i); String testurl = (String) m_HostNameList.get(i);
for (int j = 1; j < 3; j++) { for (int j = 1; j < 3; j++) {
if (rmiPing(testurl + "_" + j) == true) { 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); m_AvailableHostNameList.add(testurl + "_" + j);
} }
} }
} }
time = System.currentTimeMillis() - time; time = System.currentTimeMillis() - time;
if (TRACE) System.out.println("getAvailableHostNameList: " + m_AvailableHostNameList.size() + " found time " + time);
} }
@ -294,15 +300,15 @@ public class ComAdapter {
* *
*/ */
public String getHostName() { public String getHostName() {
return m_ownHostName; return hostName;
} }
/** /**
* *
*/ */
public void setHostName(String newHost) { public void setHostName(String newHost) {
m_ownHostName = newHost; hostName = newHost;
Serializer.storeString("hostname.ser", m_ownHostName); Serializer.storeString("hostname.ser", hostName);
} }
@ -311,8 +317,6 @@ public class ComAdapter {
* @return * @return
*/ */
protected MainAdapter createRMIMainConnect(String HostToConnect) { protected MainAdapter createRMIMainConnect(String HostToConnect) {
if (TRACE)
System.out.println("RMIMainConnect.RMIMainConnect() =" + HostToConnect);
int len = HostToConnect.indexOf(SEP); int len = HostToConnect.indexOf(SEP);
String Host = HostToConnect; String Host = HostToConnect;
String Number = SEP + "0"; String Number = SEP + "0";
@ -321,48 +325,24 @@ public class ComAdapter {
Host = st.nextToken().trim(); Host = st.nextToken().trim();
Number = SEP + 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; MainAdapter MainRemoteObject = null;
try { 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( RMIInvocationHandler invocHandler = (RMIInvocationHandler) Naming.lookup(
"rmi://" + Host + ":" + MainAdapterImpl.PORT + "/" + "rmi://" + Host + ":" + MainAdapterImpl.PORT + "/"
MainAdapterName); + MainAdapterName);
//System.out.println(" x ="+x.getClass().getName());
MainRemoteObject = getMainAdapter(invocHandler); MainRemoteObject = getMainAdapter(invocHandler);
//MainRemoteObject = (MainAdapter)Naming.lookup("rmi://"+HostToConnect+":"+MainAdapterImpl.PORT+"/"+MainAdapterImpl.MAIN_ADAPTER_NAME);
//MainRemoteObject = (MainAdapter)LogProxy.newInstance(MainRemoteObject);
MainRemoteObject.setBuf("Ok."); MainRemoteObject.setBuf("Ok.");
logInfo(" RMIConnect " + MainRemoteObject.getBuf()); logger.info("RMIConnect " + MainRemoteObject.getBuf());
} catch (MalformedURLException ex) { } catch (MalformedURLException ex) {
System.err.println("MalformedURLException: Error while looking up " + logger.log(Level.WARNING, "MalformedURLException: Error while looking up " + ex.getMessage(), ex);
ex.getMessage());
}
} catch (NotBoundException ex) { } catch (NotBoundException ex) {
System.err.println("NotBoundException: Error while looking up " + logger.log(Level.WARNING, "NotBoundException: Error while looking up " + ex.getMessage(), ex);
ex.getMessage()); } catch (RemoteException ex) {
ex.printStackTrace(); logger.log(Level.WARNING, "Error while connecting Host: " + HostToConnect, ex);
}
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());
return null; return null;
} }
return MainRemoteObject; return MainRemoteObject;
@ -372,10 +352,6 @@ public class ComAdapter {
return (MainAdapter) invocHandler.getWrapper(); return (MainAdapter) invocHandler.getWrapper();
} }
protected void logInfo(String msg) {
System.out.println("ComAdapter-Log: " + msg);
}
/** /**
* *
*/ */
@ -385,8 +361,6 @@ public class ComAdapter {
try { try {
list = Naming.list("rmi://" + testurl + ":" + MainAdapterImpl.PORT); list = Naming.list("rmi://" + testurl + ":" + MainAdapterImpl.PORT);
} catch (Exception e) { } 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 ); System.err.println ("Exception : "+testurl );
return 0; return 0;
} }
@ -404,10 +378,7 @@ public class ComAdapter {
* *
*/ */
private boolean rmiPing(String testurl) { private boolean rmiPing(String testurl) {
if (TRACE)
System.out.println("ComAdapter.rmiPing " + testurl);
MainAdapter Test = null; MainAdapter Test = null;
// String Load = null;
int len = testurl.indexOf(SEP); int len = testurl.indexOf(SEP);
String Host = testurl; String Host = testurl;
String Number = "_0"; String Number = "_0";
@ -416,30 +387,16 @@ public class ComAdapter {
Host = st.nextToken().trim(); Host = st.nextToken().trim();
Number = SEP + st.nextToken().trim(); Number = SEP + st.nextToken().trim();
} }
String MainAdapterName = m_UserName + MainAdapterImpl.MAIN_ADAPTER_NAME + String mainAdapterName = userName + MainAdapterImpl.MAIN_ADAPTER_NAME +
Number; Number;
try { try {
if (TRACE)
System.out.println("ping:" + "rmi://" + Host + ":" +
MainAdapterImpl.PORT + "/" + MainAdapterName);
RMIInvocationHandler x = (RMIInvocationHandler) Naming.lookup("rmi://" + RMIInvocationHandler x = (RMIInvocationHandler) Naming.lookup("rmi://" +
Host + ":" + MainAdapterImpl.PORT + "/" + MainAdapterName); // attention !! Host + ":" + MainAdapterImpl.PORT + "/" + mainAdapterName); // attention !!
Test = (MainAdapter) x.getWrapper(); Test = (MainAdapter) x.getWrapper();
// if (Test != null) { } catch (Exception ex) {
// Load = Test.getExecOutput("rup " + testurl); logger.log(Level.INFO, "No connection to : " + testurl, ex);
// }
} catch (Exception e) {
if (TRACE) {
logInfo("No connection to : " + testurl);
System.out.println("ComAdapter.rmiPing false " + e.getMessage());
}
return false; return false;
} }
if (Test != null) {
if (TRACE) logInfo("ping succeeded");
}
if (TRACE)
System.out.println("ComAdapter.rmiPing true");
return true; return true;
} }
@ -447,8 +404,6 @@ public class ComAdapter {
* *
*/ */
public void killServer(String ServerToKill) { public void killServer(String ServerToKill) {
if (TRACE)
System.out.println("ComAdapter.Killing Server :" + ServerToKill);
RMIConnection myConnection = getConnection(ServerToKill); RMIConnection myConnection = getConnection(ServerToKill);
myConnection.killServer(); myConnection.killServer();
this.m_Connections.remove(myConnection); this.m_Connections.remove(myConnection);
@ -458,8 +413,6 @@ public class ComAdapter {
* *
*/ */
public void killAllServers() { public void killAllServers() {
if (TRACE)
System.out.println("ComAdapter.Killing All Servers :");
for (int i = 0; i < m_AvailableHostNameList.size(); i++) { for (int i = 0; i < m_AvailableHostNameList.size(); i++) {
RMIConnection myConnection = getConnection((String) RMIConnection myConnection = getConnection((String)
m_AvailableHostNameList.get(i)); m_AvailableHostNameList.get(i));
@ -472,7 +425,6 @@ public class ComAdapter {
* *
*/ */
public void restartServerAllServer() { public void restartServerAllServer() {
if (TRACE) System.out.println("ComAdapter.restartServerAllServer :");
for (int i = 0; i < m_AvailableHostNameList.size(); i++) { for (int i = 0; i < m_AvailableHostNameList.size(); i++) {
RMIConnection myConnection = getConnection((String) RMIConnection myConnection = getConnection((String)
m_AvailableHostNameList.get(i)); m_AvailableHostNameList.get(i));
@ -485,7 +437,7 @@ public class ComAdapter {
* *
*/ */
public void restartServer(String host) { public void restartServer(String host) {
m_ownHostName = host; hostName = host;
restartServer(); restartServer();
} }
@ -493,17 +445,10 @@ public class ComAdapter {
* *
*/ */
public void restartServer() { public void restartServer() {
if (TRACE) if (hostName.equals("localhost")) { // TODO whats this?
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?
return; return;
} }
if (TRACE == true) RMIConnection x = getConnection(hostName);
System.out.println("ComAdapter.restartServer Server :" + m_ownHostName);
RMIConnection x = getConnection(m_ownHostName);
x.restartServer(); x.restartServer();
m_Connections.remove(x); m_Connections.remove(x);
try { try {
@ -553,7 +498,6 @@ public class ComAdapter {
* *
*/ */
protected RMIConnection getConnection(String Host) { 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++) { for (int i = 0; i < this.m_Connections.size(); i++) {
// search for an already established connection to the given host // search for an already established connection to the given host
// and return it if found // and return it if found

View File

@ -814,25 +814,26 @@ public class Mathematics {
* @return the closest value to v within [min,max] * @return the closest value to v within [min,max]
*/ */
public static double projectValue(double v, double min, double max) { public static double projectValue(double v, double min, double max) {
double value;
if (v < min) { if (v < min) {
return min; value = min;
} else if (v > max) { } else if (v > max) {
return max; value = max;
} else } else {
return v; 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. * distributed values with mean zero and the given standard deviation.
* *
* @param dim * @param dim The desired dimension
* the desired dimension * @param stdDev The Gaussian standard deviation
* @param stdDev
* the gaussian standard deviation
* @return random vector * @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]; double[] vect = new double[dim];
for (int j = 0; j < vect.length; j++) { for (int j = 0; j < vect.length; j++) {
vect[j] = RNG.gaussianDouble(stdDev); vect[j] = RNG.gaussianDouble(stdDev);
@ -846,7 +847,7 @@ public class Mathematics {
* *
* @param x * @param x
* @param range * @param range
* @return the number of violating dimensions * @return The number of violating dimensions
*/ */
public static int reflectBounds(double[] x, double[][] range) { public static int reflectBounds(double[] x, double[][] range) {
int viols = 0; int viols = 0;
@ -854,8 +855,7 @@ public class Mathematics {
for (int i = 0; i < x.length; i++) { for (int i = 0; i < x.length; i++) {
double dimLen = range[i][1] - range[i][0]; double dimLen = range[i][1] - range[i][0];
if (dimLen <= 0.) { if (dimLen <= 0.) {
EVAERROR EVAERROR.errorMsgOnce("Error in reflectBounds: empty range! (possibly multiple errors)");
.errorMsgOnce("Error in reflectBounds: empty range! (possibly multiple errors)");
} else { } else {
if (x[i] < range[i][0]) { if (x[i] < range[i][0]) {
viols++; viols++;
@ -867,8 +867,9 @@ public class Mathematics {
} else if (x[i] > range[i][1]) { } else if (x[i] > range[i][1]) {
viols++; viols++;
d = x[i] - range[i][1]; d = x[i] - range[i][1];
while (d > dimLen) while (d > dimLen) {
d -= dimLen; // avoid violating the other bound d -= dimLen; // avoid violating the other bound
}
// immediately // immediately
x[i] = range[i][1] - d; x[i] = range[i][1] - d;
} }
@ -890,12 +891,15 @@ public class Mathematics {
*/ */
public static double reflectValue(double val, double step, double min, public static double reflectValue(double val, double step, double min,
double max) { double max) {
while (step > (max - min)) while (step > (max - min)) {
step -= (max - min); step -= (max - min);
if ((val + step) > max) }
if ((val + step) > max) {
return (2 * max - val - step); return (2 * max - val - step);
if ((val + step) < min) }
if ((val + step) < min) {
return (2 * min - val - step); return (2 * min - val - step);
}
return (val += step); return (val += step);
} }
@ -916,15 +920,17 @@ public class Mathematics {
*/ */
public static double relDist(double[] x, double[] y, double def) public static double relDist(double[] x, double[] y, double def)
throws Exception { throws Exception {
if (x.length != y.length) if (x.length != y.length) {
throw new Exception( throw new Exception("The vectors x and y must have the same dimension");
"The vectors x and y must have the same dimension"); }
double d = 0; double d = 0;
for (int i = 0; i < x.length; i++) for (int i = 0; i < x.length; i++) {
if (y[i] != 0) if (y[i] != 0) {
d += Math.pow(((x[i] - y[i]) / y[i]), 2); d += Math.pow(((x[i] - y[i]) / y[i]), 2);
else } else {
d += def; d += def;
}
}
return d; return d;
} }
@ -943,9 +949,10 @@ public class Mathematics {
for (int i = 0; i < src.length; i++) { for (int i = 0; i < src.length; i++) {
dst[src.length - i - 1] = src[i]; dst[src.length - i - 1] = src[i];
} }
} else } else {
System.err.println("Mismatching array lengths!"); System.err.println("Mismatching array lengths!");
} }
}
/** /**
* Rotate the vector by angle alpha around axis i/j * Rotate the vector by angle alpha around axis i/j
@ -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). * Computes a spline interpolation of the two point (x0,f0) and (x1,f1).
* *