diff options
| author | abranson <andrew.branson@cern.ch> | 2011-08-04 00:42:34 +0200 |
|---|---|---|
| committer | abranson <andrew.branson@cern.ch> | 2011-08-04 00:42:34 +0200 |
| commit | 0ec8481c10cd8277d84c7c1a785483a0a739e5a0 (patch) | |
| tree | 5f6e5d9ae75193e67e6f3b3dfa488960c5cde1d5 /source/com/c2kernel/process | |
| parent | 036cbdba66f804743c4c838ed598d6972c4b3e17 (diff) | |
More code cleanup:
Refactored Entity Proxy Subscription to handle generics better
Rewrote RemoteMap to use TreeMap instead of the internal array for
order. It now sorts its keys by number if they parse, else as strings.
Removed a no-longer-in-progress outcome form class
Diffstat (limited to 'source/com/c2kernel/process')
| -rw-r--r--[-rwxr-xr-x] | source/com/c2kernel/process/AbstractMain.java | 12 | ||||
| -rw-r--r-- | source/com/c2kernel/process/Bootstrap.java | 86 | ||||
| -rw-r--r-- | source/com/c2kernel/process/Gateway.java | 132 | ||||
| -rw-r--r--[-rwxr-xr-x] | source/com/c2kernel/process/ItemHTTPBridge.java | 18 | ||||
| -rw-r--r-- | source/com/c2kernel/process/StandardClient.java | 2 | ||||
| -rw-r--r--[-rwxr-xr-x] | source/com/c2kernel/process/StandardServer.java | 39 | ||||
| -rw-r--r-- | source/com/c2kernel/process/UserCodeProcess.java | 71 |
7 files changed, 185 insertions, 175 deletions
diff --git a/source/com/c2kernel/process/AbstractMain.java b/source/com/c2kernel/process/AbstractMain.java index 97af4f8..9282d45 100755..100644 --- a/source/com/c2kernel/process/AbstractMain.java +++ b/source/com/c2kernel/process/AbstractMain.java @@ -53,10 +53,10 @@ abstract public class AbstractMain String configPath = null;
String connectPath = null;
java.util.Properties c2kProps = null;
- int logLevel = 0;
+ int logLevel = 0;
PrintStream logStream = System.out;
String centreId = null;
-
+
try
{
if( args != null )
@@ -125,12 +125,12 @@ abstract public class AbstractMain // Set up log stream
Logger.addLogStream(logStream, logLevel);
-
+
if (configPath == null) {
System.out.println("No config file specified");
usage();
}
-
+
// Load config & connect files into c2kprops
c2kProps = FileStringUtility.loadConfigFile( configPath );
@@ -167,7 +167,7 @@ abstract public class AbstractMain ex.printStackTrace();
usage();
}
-
+
Logger.msg(7, "AbstractMain::standardSetUp() - readC2KArgs() DONE.");
return c2kProps;
@@ -201,5 +201,5 @@ abstract public class AbstractMain Gateway.close();
Logger.msg(5, "AbstractMain::standardTearDown() - DONE.");
}
-
+
}
diff --git a/source/com/c2kernel/process/Bootstrap.java b/source/com/c2kernel/process/Bootstrap.java index 777568c..6ffdd01 100644 --- a/source/com/c2kernel/process/Bootstrap.java +++ b/source/com/c2kernel/process/Bootstrap.java @@ -3,12 +3,10 @@ package com.c2kernel.process; import java.net.InetAddress;
import java.util.Enumeration;
import java.util.HashMap;
-import java.util.Iterator;
import java.util.StringTokenizer;
import com.c2kernel.common.ObjectNotFoundException;
import com.c2kernel.entity.TraceableEntity;
-import com.c2kernel.entity.agent.ActiveEntity;
import com.c2kernel.entity.proxy.ItemProxy;
import com.c2kernel.events.Event;
import com.c2kernel.events.History;
@@ -56,18 +54,19 @@ public class Bootstrap checkAdminAgents();
// create the server's mother item
- createServerItem();
+ createServerItem();
new Thread(new Runnable() {
+ @Override
public void run() {
try {
Thread.currentThread().setName("Bootstrapper");
-
+
// make sure all of the boot items are up-to-date
verifyBootDataItems();
-
+
// verify the server item's wf
initServerItemWf();
-
+
// create the factories etc.
createBootstrapFactoryItems();
Logger.msg("Bootstrap.run() - Bootstrapping complete");
@@ -78,7 +77,7 @@ public class Bootstrap }
}).start();
}
-
+
/**************************************************************************
* Checks all kernel descriptions, stored in resources
**************************************************************************/
@@ -87,7 +86,7 @@ public class Bootstrap Logger.msg(1, "Verifying kernel boot items");
bootItems = FileStringUtility.url2String(Resource.getKernelResourceURL("boot/allbootitems.txt"));
verifyBootDataItems(bootItems, true);
- if (Resource.getDomainBaseURL() == null)
+ if (Resource.getDomainBaseURL() == null)
Logger.msg(1, "No Domain base URL. Skipping domain boot check.");
else {
try {
@@ -100,7 +99,7 @@ public class Bootstrap return;
}
Logger.msg(1, "Verifying domain agents");
-
+
try {
bootItems = FileStringUtility.url2String(Resource.getDomainResourceURL("boot/domainagents.txt"));
verifyDomainAgents(bootItems);
@@ -110,11 +109,11 @@ public class Bootstrap return;
}
}
-
+
Logger.msg(1, "Boot data items complete");
-
+
}
-
+
private static void verifyDomainAgents(String agentFile) throws Exception {
StringTokenizer str = new StringTokenizer(agentFile, "\n\r");
while (str.hasMoreTokens()) {
@@ -123,7 +122,7 @@ public class Bootstrap checkAgent(agent.nextToken(), agent.nextToken(), agent.nextToken(), agent.nextToken().equalsIgnoreCase("true"));
}
}
-
+
private static void verifyBootDataItems(String bootList, boolean isKernel) {
StringTokenizer str = new StringTokenizer(bootList, "\n\r");
while (str.hasMoreTokens()) {
@@ -139,9 +138,9 @@ public class Bootstrap bootstrapFactoryItems.put(itemName, data);
continue;
}
-
+
Logger.msg(1, "Bootstrap.verifyBootItems() - Verifying data of "+getDataType(itemType)+" "+itemName);
- Enumeration en = Gateway.getLDAPLookup().search(getTypeRoot(itemType), itemName);
+ Enumeration<?> en = Gateway.getLDAPLookup().search(getTypeRoot(itemType), itemName);
ItemProxy thisProxy;
if (!en.hasMoreElements()) {
@@ -156,7 +155,7 @@ public class Bootstrap String oldData = currentData.getOutcome().getData();
if (data.equals(oldData)) {
Logger.msg(5, "Bootstrap.verifyBootItems() - Data identical, no update required");
-
+
continue;
}
} catch (ObjectNotFoundException ex) {
@@ -191,12 +190,12 @@ public class Bootstrap PropertyDescriptionList pdList = (PropertyDescriptionList)CastorXMLUtility.unmarshall(Resource.getTextResource("boot/property/"+itemType+"Prop.xml"));
PropertyArrayList props = new PropertyArrayList();
for (int i = 0; i < pdList.list.size(); i++) {
- PropertyDescription pd = (PropertyDescription) pdList.list.get(i);
+ PropertyDescription pd = pdList.list.get(i);
String propName = pd.getName();
String propVal = propName.equals("Name")?itemName:pd.getDefaultValue();
- props.list.add(new Property(propName, propVal));
+ props.list.add(new Property(propName, propVal));
}
-
+
EntityPath entityPath = Gateway.getLDAPLookup().getNextKeyManager().generateNextEntityKey();
TraceableEntity newItem = (TraceableEntity)Gateway.getCorbaServer().createEntity(entityPath);
Gateway.getLDAPLookup().add(entityPath);
@@ -219,7 +218,7 @@ public class Bootstrap return new DomainPath("/desc/OutcomeDesc/");
throw new Exception("Unknown bootstrap item type: "+type);
}
-
+
private static String getDataType(String type) throws Exception {
if (type.equals("CA"))
return "CompositeActivityDef";
@@ -230,36 +229,36 @@ public class Bootstrap if (type.equals("SC"))
return "Script";
throw new Exception("Unknown bootstrap item type: "+type);
-
+
}
-
+
/**************************************************************************
* Checks for the existence of the admin users so you can use Cristal
**************************************************************************/
- private static void checkAgent(String name, String pass, String role, boolean joblist) throws Exception {
+ private static void checkAgent(String name, String pass, String role, boolean joblist) throws Exception {
Logger.msg(1, "Bootstrap.checkAgent() - Checking for existence of '"+name+"' user.");
LDAPLookup lookup = Gateway.getLDAPLookup();
try {
- AgentPath agentPath = lookup.getRoleManager().getAgentPath(name);
+ lookup.getRoleManager().getAgentPath(name);
Logger.msg(3, "Bootstrap.checkAgent() - User '"+name+"' found.");
return;
} catch (ObjectNotFoundException ex) { }
Logger.msg("Bootstrap.checkAgent() - User '"+name+"' not found. Creating.");
-
+
RolePath rolePath;
try {
rolePath = lookup.getRoleManager().getRolePath(role);
} catch (ObjectNotFoundException ex) {
rolePath = lookup.getRoleManager().createRole(role, joblist);
}
-
+
try {
EntityPath entityPath = lookup.getNextKeyManager().generateNextEntityKey();
AgentPath agentPath = new AgentPath(entityPath.getSysKey(), name);
agentPath.setPassword(pass);
- ActiveEntity adminAgent = (ActiveEntity)Gateway.getCorbaServer().createEntity(agentPath);
+ Gateway.getCorbaServer().createEntity(agentPath);
Gateway.getLDAPLookup().add(agentPath);
-
+
// assign admin role
Logger.msg("Bootstrap.checkAgent() - Assigning role '"+role+"'");
rolePath.addAgent(agentPath);
@@ -273,21 +272,21 @@ public class Bootstrap }
/**
- *
+ *
*/
public static void checkAdminAgents() throws Exception {
// check for administrative user
String adminPassword = Gateway.getProperty("AdminPassword", "admin12345");
-
+
checkAgent("admin", adminPassword, "Admin", false);
-
+
// check for import user
checkAgent("system", adminPassword, "Admin", false);
-
+
// check for local usercode user
checkAgent(InetAddress.getLocalHost().getHostName(), "uc", "UserCode", true);
- }
-
+ }
+
public static void createServerItem() throws Exception {
String serverName = Gateway.getProperty("ItemServer.name");
thisServerPath = new DomainPath("/servers/"+serverName);
@@ -297,7 +296,7 @@ public class Bootstrap } catch (ObjectNotFoundException ex) {
Logger.msg("Creating server item "+thisServerPath);
serverEntity = Gateway.getLDAPLookup().getNextKeyManager().generateNextEntityKey();
- TraceableEntity newItem = (TraceableEntity)Gateway.getCorbaServer().createEntity(serverEntity);
+ Gateway.getCorbaServer().createEntity(serverEntity);
Gateway.getLDAPLookup().add(serverEntity);
thisServerPath.setEntity(serverEntity);
Gateway.getLDAPLookup().add(thisServerPath);
@@ -306,15 +305,15 @@ public class Bootstrap Gateway.getStorage().put(serverEntity.getSysKey(), new Property("Type", "Server"), null);
Gateway.getStorage().put(serverEntity.getSysKey(), new Property("KernelVersion", Resource.getKernelVersion()), null);
if (Gateway.getProperty("ItemServer.Proxy.port") != null)
- Gateway.getStorage().put(serverEntity.getSysKey(),
+ Gateway.getStorage().put(serverEntity.getSysKey(),
new Property("ProxyPort", Gateway.getProperty("ItemServer.Proxy.port")), null);
if (Gateway.getProperty("ItemServer.Console.port") != null)
- Gateway.getStorage().put(serverEntity.getSysKey(),
+ Gateway.getStorage().put(serverEntity.getSysKey(),
new Property("ConsolePort", Gateway.getProperty("ItemServer.Console.port")), null);
Gateway.getProxyManager().connectToProxyServer(Gateway.getProperty("ItemServer.name"), Integer.parseInt(Gateway.getProperty("ItemServer.Proxy.port")));
}
-
+
public static void initServerItemWf() throws Exception {
CompositeActivityDef serverWfCa = (CompositeActivityDef)LocalObjectLoader.getActDef("ServerItemWorkflow", "last");
Workflow wf = new Workflow((CompositeActivity)serverWfCa.instantiate());
@@ -325,21 +324,20 @@ public class Bootstrap Gateway.getStorage().put(thisServerPath.getSysKey(), wf, null);
// add this proxy server in case it was just registered, or the port has changed
}
-
+
public static void createBootstrapFactoryItems() throws Exception {
Logger.msg(1, "Verifying local object factories");
- for (Iterator iter = bootstrapFactoryItems.keySet().iterator(); iter.hasNext();) {
- String itemName = (String) iter.next();
- String itemXML = (String)bootstrapFactoryItems.get(itemName);
+ for (String itemName : bootstrapFactoryItems.keySet()) {
+ String itemXML = bootstrapFactoryItems.get(itemName);
Logger.msg(2, "Verifying "+itemName);
NewItem item = (NewItem)CastorXMLUtility.unmarshall(itemXML);
DomainPath factPath = new DomainPath(new DomainPath(item.initialPath), item.name);
if (factPath.exists()) continue;
ItemProxy serverEntity = (ItemProxy)Gateway.getProxyManager().getProxy(thisServerPath);
serverEntity.requestAction(
- Gateway.getLDAPLookup().getRoleManager().getAgentPath("system").getSysKey(),
+ Gateway.getLDAPLookup().getRoleManager().getAgentPath("system").getSysKey(),
"workflow/predefined/CreateNewItem",
- Transitions.DONE,
+ Transitions.DONE,
itemXML);
Logger.msg("Bootstrap.createBootstrapFactoryItems() - Created factory item: "+itemName);
ItemProxy factProxy = (ItemProxy)Gateway.getProxyManager().getProxy(factPath);
diff --git a/source/com/c2kernel/process/Gateway.java b/source/com/c2kernel/process/Gateway.java index 276b7b4..3a03088 100644 --- a/source/com/c2kernel/process/Gateway.java +++ b/source/com/c2kernel/process/Gateway.java @@ -20,26 +20,30 @@ import com.c2kernel.lookup.LDAPLookup; import com.c2kernel.lookup.LDAPProperties;
import com.c2kernel.persistency.ClusterStorageException;
import com.c2kernel.persistency.TransactionManager;
-import com.c2kernel.utils.*;
+import com.c2kernel.utils.CastorXMLUtility;
+import com.c2kernel.utils.FileStringUtility;
+import com.c2kernel.utils.Language;
+import com.c2kernel.utils.Logger;
+import com.c2kernel.utils.Resource;
import com.c2kernel.utils.server.SimpleTCPIPServer;
/**************************************************************************
* The Gateway is the central object of a CRISTAL process. It initializes,
* maintains and shuts down every other subsystem in both the client and the
- * server.
- *
+ * server.
+ *
* Child objects:
* <ul>
- * <li>LDAPLookup - Provides access to the CRISTAL directory. Find or
+ * <li>LDAPLookup - Provides access to the CRISTAL directory. Find or
* search for Items or Agents.
- * <li>EntityProxyManager - Gives a local proxy object for Entities found
+ * <li>EntityProxyManager - Gives a local proxy object for Entities found
* in LDAP. Execute activities in Items, query or subscribe to Entity data.
* <li>TransactionManager - Access to the configured CRISTAL databases
* <li>CorbaServer - Manages the memory pool of active Entities
* <li>mORB - the Orbacus CORBA ORB
* </ul>
- *
+ *
* @author $Author: abranson $ $Date: 2005/10/12 12:51:54 $
* @version $Revision: 1.17 $
**************************************************************************/
@@ -58,26 +62,26 @@ public class Gateway private Gateway() { }
/**
- * Initialises the Gateway and all of the client objects it holds, with
+ * Initialises the Gateway and all of the client objects it holds, with
* the exception of the LDAPLookup, which is initialised during connect()
- *
- * @param props - java.util.Properties containing all application properties.
+ *
+ * @param props - java.util.Properties containing all application properties.
* If null, the java system properties are used
* @throws InvalidDataException - invalid properties caused a failure in initialisation
*/
static public void init(Properties props) throws InvalidDataException {
// if supplied props are null, use system props
- if (props == null) props = System.getProperties();
+ if (props == null) props = System.getProperties();
// set resource URLs from config
String resURL = props.getProperty("KernelResourceURL");
if (resURL != null && resURL.length()>0)
Resource.setKernelBaseURL(resURL);
-
+
resURL = props.getProperty("DomainResourceURL");
if (resURL != null && resURL.length()>0)
Resource.setDomainBaseURL(resURL);
-
+
// Start with default props from kernel jar
try {
mC2KProps = FileStringUtility.loadConfigFile( Resource.getKernelResourceURL("textFiles/defaultConf.properties").toString());
@@ -86,7 +90,7 @@ public class Gateway }
// Overwrite with supplied props
- for (Enumeration e = props.propertyNames(); e.hasMoreElements();) {
+ for (Enumeration<?> e = props.propertyNames(); e.hasMoreElements();) {
String propName = (String)e.nextElement();
mC2KProps.put(propName, props.get(propName));
}
@@ -109,7 +113,7 @@ public class Gateway //Initialise language file
String languageFile = getProperty("language.file");
- if (languageFile != null && languageFile.length() > 0) {
+ if (languageFile != null && languageFile.length() > 0) {
Language.isTranlated=true;
Language.mTableOfTranslation = FileStringUtility.loadLanguageFile(languageFile);
}
@@ -118,24 +122,24 @@ public class Gateway Resource.setImportURL(new URL("file:"+getProperty("Import.dir")));
} catch (MalformedURLException e) {
Logger.error("Import directory not set. "+getProperty("Import.dir"));
- }
+ }
}
-
+
/**
- * Makes this process capable of creating and managing server entities. Runs the
- * bootstrap to create the root LDAP contexts, initialises the CORBA server and
+ * Makes this process capable of creating and managing server entities. Runs the
+ * bootstrap to create the root LDAP contexts, initialises the CORBA server and
* time-out manager.
- *
+ *
* @throws InvalidDataException - error initialising
*/
static public void startServer() throws InvalidDataException {
try {
// check top level LDAP contexts
mLDAPLookup.install();
-
+
// start entity proxy server
EntityProxyManager.initServer();
-
+
// Init ORB - set various config to sys properties
java.util.Properties sysProps = System.getProperties();
String serverName = getProperty("ItemServer.name");
@@ -151,18 +155,18 @@ public class Gateway mORB = org.omg.CORBA.ORB.init(new String[0], sysProps);
Logger.msg("Gateway.init() - ORB initialised. ORB is " + mORB.getClass().getName() );
-
+
// start corba server components
mCorbaServer = new CorbaServer();
// start checking bootstrap items
Bootstrap.run();
-
+
} catch (Exception ex) {
Logger.error(ex);
Logger.die("Exception starting server components. Shutting down.");
}
-
+
// start the http server
try {
int httpPort = Integer.parseInt(Gateway.getProperty("ItemServer.HTTP.port"));
@@ -172,14 +176,14 @@ public class Gateway } catch (NumberFormatException ex) {
Logger.msg(3, "Invalid or no HTTP port defined. HTTP server not available.");
}
-
+
System.out.println("Server '"+Gateway.getCentreId()+"' initialised.");
}
-
+
/**
* Connects to the LDAP server in an administrative context - using the admin username and
* password given in the LDAP.user and LDAP.password props of the kernel properties.
- *
+ *
* @throws InvalidDataException - bad params
* @throws ClusterStorageException - error starting storages
*/
@@ -210,11 +214,11 @@ public class Gateway setup();
}
-
+
/**
- * Authenticates a user and returns and AgentProxy on them without overriding the system LDAP context.
+ * Authenticates a user and returns and AgentProxy on them without overriding the system LDAP context.
* Useful for handling multiple users in one context e.g. on a web server
- *
+ *
* @param agentName - username
* @param agentPassword - password
* @return AgentProxy on that user
@@ -233,7 +237,7 @@ public class Gateway String agentDN = agentPath.getFullDN();
ldapProps.mUser = agentDN;
ldapProps.mPassword = agentPassword;
-
+
try {
LDAPLookup.createConnection(ldapProps);
return (AgentProxy)getProxyManager().getProxy(mLDAPLookup.getRoleManager().getAgentPath(agentName));
@@ -242,11 +246,11 @@ public class Gateway throw new InvalidDataException("Could not log in", "");
}
}
-
+
/**
* Logs into the LDAP server with the given username and password, and initialises the lookup.
- *
+ *
* @param agentName - username
* @param agentPassword - password
* @return an AgentProxy on the requested user
@@ -254,25 +258,25 @@ public class Gateway */
static public AgentProxy connect(String agentName, String agentPassword)
throws InvalidDataException
- {
-
+ {
+
LDAPProperties ldapProps = new LDAPProperties();
if (ldapProps.mHost!=null && ldapProps.mPort!= null && ldapProps.mLocalPath!=null )
- {
+ {
try {
ldapProps.mUser = "";
ldapProps.mPassword = "";
mLDAPLookup = new LDAPLookup(ldapProps);
String agentDN = mLDAPLookup.getRoleManager().getAgentPath(agentName).getFullDN();
-
+
//found agentDN, try to log in with it
ldapProps.mUser = agentDN;
ldapProps.mPassword = agentPassword;
mLDAPLookup = new LDAPLookup(ldapProps);
-
+
// find agent proxy
AgentPath agentPath = mLDAPLookup.getRoleManager().getAgentPath(agentName);
-
+
if (agentPath!=null)
{
setup();
@@ -281,7 +285,7 @@ public class Gateway else
{
throw new InvalidDataException("The agentDN " +agentDN+ " is invalid.", "");
- }
+ }
} catch (ClusterStorageException e) {
Logger.error(e);
throw new InvalidDataException(Language.translate("Error initialising storage")+Language.translate(". See log."), "");
@@ -293,35 +297,35 @@ public class Gateway throw new InvalidDataException(Language.translate("Could not log in")+": "+Language.translate(e.getMessage()), "");
}
- }
+ }
else
{
throw new InvalidDataException("Cannot log in. Some connection properties are not set.", "");
- }
-
+ }
+
}
-
+
/**
* Initializes the storage and proxy manager, called during connect.
- *
+ *
* @throws InvalidDataException
* @throws ClusterStorageException
*/
- static private void setup()
+ static private void setup()
throws InvalidDataException,
- ClusterStorageException
+ ClusterStorageException
{
-
+
// Init storages
mStorage = new TransactionManager();
mProxyManager = new EntityProxyManager();
}
-
+
/**
* Shuts down all kernel api objects
*/
- public static void close()
+ public static void close()
{
// shut down servers if running
if (mCorbaServer != null)
@@ -330,17 +334,17 @@ public class Gateway if (mHTTPServer != null)
mHTTPServer.stopListening();
mHTTPServer = null;
-
+
// disconnect from storages
if (mStorage != null)
mStorage.close();
mStorage = null;
-
+
// disconnect from ldap
if (mLDAPLookup != null)
mLDAPLookup.disconnect();
mLDAPLookup = null;
-
+
// shut down proxy manager
if (mProxyManager != null)
mProxyManager.shutdown();
@@ -370,21 +374,21 @@ public class Gateway {
return mCorbaServer;
}
-
+
static public TransactionManager getStorage()
{
return mStorage;
}
-
+
static public EntityProxyManager getProxyManager()
{
return mProxyManager;
}
-
+
static public String getCentreId() {
return getProperty("LocalCentre");
- }
-
+ }
+
static public String getProperty(String propName) {
return getProperty(propName, null);
}
@@ -393,20 +397,20 @@ public class Gateway if (mC2KProps == null) return defaultValue;
return mC2KProps.getProperty(propName, defaultValue);
}
-
+
static public void setProperty(String propName, String propValue) {
if (mC2KProps == null) return;
mC2KProps.put(propName, propValue);
- }
-
- static public Enumeration propertyNames() {
+ }
+
+ static public Enumeration<?> propertyNames() {
return mC2KProps.propertyNames();
}
-
+
static public void dumpC2KProps(int logLevel) {
if (!Logger.doLog(logLevel)) return;
Logger.msg(logLevel, "C2K Properties:");
- for (Enumeration e = propertyNames(); e.hasMoreElements();) {
+ for (Enumeration<?> e = propertyNames(); e.hasMoreElements();) {
String name = (String) e.nextElement();
Logger.msg(" "+name+": "+getProperty(name));
}
diff --git a/source/com/c2kernel/process/ItemHTTPBridge.java b/source/com/c2kernel/process/ItemHTTPBridge.java index 8ef2e58..40f48f7 100755..100644 --- a/source/com/c2kernel/process/ItemHTTPBridge.java +++ b/source/com/c2kernel/process/ItemHTTPBridge.java @@ -3,8 +3,6 @@ package com.c2kernel.process; import java.util.StringTokenizer;
import com.c2kernel.entity.C2KLocalObject;
-import com.c2kernel.lookup.DomainPath;
-import com.c2kernel.lookup.EntityPath;
import com.c2kernel.utils.CastorXMLUtility;
import com.c2kernel.utils.server.HTTPRequestHandler;
@@ -19,22 +17,24 @@ public class ItemHTTPBridge extends HTTPRequestHandler { public ItemHTTPBridge() { }
- public String getName() {
+ @Override
+ public String getName() {
return "Item HTTP Server";
}
- public String processRequest() {
- System.out.println("ItemHTTPBridge::ProcessRequest()");
+ @Override
+ public String processRequest() {
+ System.out.println("ItemHTTPBridge::ProcessRequest()");
StringTokenizer tok = new StringTokenizer(resource, "?");
- String itemPath = tok.nextToken();
+ //String itemPath = tok.nextToken();
String query = tok.nextToken();
int sysKey = -1;
//Path path = Gateway.getLDAPLookup().;
if (method.equals("GET")) {
try {
- DomainPath domPath = new DomainPath(itemPath);
- EntityPath entityPath = domPath.getEntity();
-
+ //DomainPath domPath = new DomainPath(itemPath);
+ //EntityPath entityPath = domPath.getEntity();
+
if (sysKey > -1) {
C2KLocalObject response = Gateway.getStorage().get(sysKey, query, null);
return CastorXMLUtility.marshall(response);
diff --git a/source/com/c2kernel/process/StandardClient.java b/source/com/c2kernel/process/StandardClient.java index 2b04613..f6f48ed 100644 --- a/source/com/c2kernel/process/StandardClient.java +++ b/source/com/c2kernel/process/StandardClient.java @@ -12,7 +12,7 @@ package com.c2kernel.process; abstract public class StandardClient extends AbstractMain
{
-
+
//TODO: Auto-update from server
}
diff --git a/source/com/c2kernel/process/StandardServer.java b/source/com/c2kernel/process/StandardServer.java index 2c9bcaf..72b761e 100755..100644 --- a/source/com/c2kernel/process/StandardServer.java +++ b/source/com/c2kernel/process/StandardServer.java @@ -16,21 +16,21 @@ import org.tanukisoftware.wrapper.WrapperManager; import com.c2kernel.utils.Logger;
/**************************************************************************
- * Base class for all servers i.e. c2k processes that serve Entities
+ * Base class for all servers i.e. c2k processes that serve Entities
*
* @author $Author: abranson $ $Date: 2005/04/28 13:49:43 $
* @version $Revision: 1.47 $
**************************************************************************/
public class StandardServer extends AbstractMain implements WrapperListener
{
- protected static StandardServer server;
+ protected static StandardServer server;
/**************************************************************************
* C2KRootPOA suitable for Factory objects
**************************************************************************/
-
+
@@ -44,26 +44,27 @@ public class StandardServer extends AbstractMain implements WrapperListener {
// read args and init Gateway
standardSetUp(args);
-
+
// connect to LDAP as root
Gateway.connect();
-
+
//start console
Logger.initConsole("ItemServer");
-
+
//initialize the server objects
Gateway.startServer();
-
+
Logger.msg(5, "StandardServer::standardInitialisation - complete.");
}
-
+
/**************************************************************************
* Sets up and runs and item server
**************************************************************************/
- public Integer start(String[] args)
- {
+ @Override
+ public Integer start(String[] args)
+ {
try
{
//initialise everything
@@ -76,17 +77,18 @@ public class StandardServer extends AbstractMain implements WrapperListener }
return null;
}
-
+
public static void main(String[] args) {
server = new StandardServer();
AbstractMain.runningAsWrapper = true;
WrapperManager.start( server, args );
}
-
+
/**
*
*/
- public void controlEvent(int event) {
+ @Override
+ public void controlEvent(int event) {
if (WrapperManager.isControlledByNativeWrapper()) {
// The Wrapper will take care of this event
} else {
@@ -105,11 +107,12 @@ public class StandardServer extends AbstractMain implements WrapperListener * Closes all listeners, quits the VM.
* This method should be called to kill the server process
* e.g. from the NT service wrapper
- **************************************************************************/
- public int stop(int arg0) {
+ **************************************************************************/
+ @Override
+ public int stop(int arg0) {
try
- {
- // close gateway
+ {
+ // close gateway
standardTearDown();
}
catch( Exception ex )
@@ -117,7 +120,7 @@ public class StandardServer extends AbstractMain implements WrapperListener Logger.error(ex);
return 1;
}
-
+
Logger.msg("StandardServer::shutdown - complete. ");
return 0;
}
diff --git a/source/com/c2kernel/process/UserCodeProcess.java b/source/com/c2kernel/process/UserCodeProcess.java index 18fed06..9c2deab 100644 --- a/source/com/c2kernel/process/UserCodeProcess.java +++ b/source/com/c2kernel/process/UserCodeProcess.java @@ -4,7 +4,6 @@ import java.net.InetAddress; import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.HashMap;
-import java.util.Iterator;
import com.c2kernel.common.InvalidDataException;
import com.c2kernel.common.InvalidTransitionException;
@@ -12,7 +11,7 @@ import com.c2kernel.entity.C2KLocalObject; import com.c2kernel.entity.agent.Job;
import com.c2kernel.entity.proxy.AgentProxy;
import com.c2kernel.entity.proxy.EntityProxyObserver;
-import com.c2kernel.entity.proxy.MemberControl;
+import com.c2kernel.entity.proxy.MemberSubscription;
import com.c2kernel.lifecycle.instance.stateMachine.Transitions;
import com.c2kernel.persistency.ClusterStorage;
import com.c2kernel.utils.Logger;
@@ -25,12 +24,12 @@ import com.c2kernel.utils.Logger; * Copyright (C) 2003 CERN - European Organization for Nuclear Research
* All rights reserved.
**************************************************************************/
-public class UserCodeProcess extends StandardClient implements EntityProxyObserver, Runnable {
+public class UserCodeProcess extends StandardClient implements EntityProxyObserver<Job>, Runnable {
protected AgentProxy agent;
static boolean active = true;
ArrayList<String> ignoredPaths = new ArrayList<String>();
HashMap<String, C2KLocalObject> jobs;
-
+
public UserCodeProcess(String agentName, String agentPass) {
// login - try for a while in case server hasn't imported our user yet
for (int i=1;i<6;i++) {
@@ -48,12 +47,13 @@ public class UserCodeProcess extends StandardClient implements EntityProxyObserv }
System.out.println(getDesc()+" initialised for " + agentName);
}
-
- public void run() {
+
+ @Override
+ public void run() {
Thread.currentThread().setName("Usercode Process");
jobs = new HashMap<String, C2KLocalObject>();
// subscribe to job list
- agent.subscribe(this, ClusterStorage.JOB, true);
+ agent.subscribe(new MemberSubscription<Job>(this, ClusterStorage.JOB, true));
while (active) {
Job thisJob = null;
synchronized (jobs) {
@@ -62,10 +62,10 @@ public class UserCodeProcess extends StandardClient implements EntityProxyObserv if (thisJob == null)
thisJob = getJob(jobs, Transitions.START);
if (thisJob == null)
- thisJob = getJob(jobs, Transitions.SUSPEND);
+ thisJob = getJob(jobs, Transitions.SUSPEND);
if (thisJob == null)
thisJob = getJob(jobs, Transitions.RESUME);
-
+
if (thisJob == null) {
Logger.error("No supported jobs, but joblist is not empty! Discarding remaining jobs");
jobs.clear();
@@ -74,7 +74,7 @@ public class UserCodeProcess extends StandardClient implements EntityProxyObserv jobs.remove(ClusterStorage.getPath(thisJob));
}
}
-
+
if (thisJob != null) {
String jobKey = thisJob.getItemSysKey()+":"+thisJob.getStepPath();
try {
@@ -82,8 +82,8 @@ public class UserCodeProcess extends StandardClient implements EntityProxyObserv Logger.msg(5, "Testing start conditions");
boolean start = assessStartConditions(thisJob);
if (start) {
- Logger.msg(5, "Attempting to start");
- agent.execute(thisJob);
+ Logger.msg(5, "Attempting to start");
+ agent.execute(thisJob);
}
else {
Logger.msg(5, "Start conditions failed "+thisJob.getStepName()+" in "+thisJob.getItemSysKey());
@@ -103,7 +103,7 @@ public class UserCodeProcess extends StandardClient implements EntityProxyObserv if (!ignoredPaths.contains(jobKey))
agent.execute(thisJob);
}
- } catch (InvalidTransitionException ex) {
+ } catch (InvalidTransitionException ex) {
// must have already been done by someone else - ignore
} catch (Throwable ex) {
Logger.error("Error executing "+Transitions.getTransitionName(thisJob.getPossibleTransition())+" job:");
@@ -121,7 +121,7 @@ public class UserCodeProcess extends StandardClient implements EntityProxyObserv }
} catch (InterruptedException ex) { }
}
-
+
// shut down
try
{
@@ -132,10 +132,10 @@ public class UserCodeProcess extends StandardClient implements EntityProxyObserv Logger.error(ex);
}
}
-
- private Job getJob(HashMap jobs, int transition) {
- for (Iterator list = jobs.values().iterator();list.hasNext();) {
- Job thisJob = (Job)list.next();
+
+ private static Job getJob(HashMap<String, C2KLocalObject> jobs, int transition) {
+ for (C2KLocalObject c2kLocalObject : jobs.values()) {
+ Job thisJob = (Job)c2kLocalObject;
if (thisJob.getPossibleTransition() == transition) {
Logger.msg(1,"=================================================================");
Logger.msg(1, "Got "+Transitions.getTransitionName(transition)+" job for "+thisJob.getStepName()+" in "+thisJob.getItemSysKey());
@@ -144,27 +144,23 @@ public class UserCodeProcess extends StandardClient implements EntityProxyObserv }
return null;
}
-
+
public boolean assessStartConditions(Job job) {
- // default implementation - has no start conditions.
+ // default implementation - has no start conditions.
return true;
}
-
+
public void runUCLogic(Job job) throws Exception {
// default implementation - the agent will execute any scripts defined when we execute
agent.execute(job);
}
-
-
+
+
/**
* Receives job from the AgentProxy. Reactivates thread if sleeping.
*/
- public void add(C2KLocalObject contents) {
- if (contents instanceof MemberControl) {
- MemberControl ctrl = (MemberControl)contents;
- Logger.msg(5,ctrl.toString());
- }
- else
+ @Override
+ public void add(Job contents) {
synchronized(jobs) {
Logger.msg(7, "Adding "+ClusterStorage.getPath(contents));
jobs.put(ClusterStorage.getPath(contents), contents);
@@ -172,11 +168,18 @@ public class UserCodeProcess extends StandardClient implements EntityProxyObserv }
}
+
+ @Override
+ public void control(String control, String msg) {
+ if (control == MemberSubscription.ERROR)
+ Logger.error("Error in job subscription: "+msg);
+ }
/**
* Removes job removal notification from the AgentProxy.
*/
- public void remove(String id) {
+ @Override
+ public void remove(String id) {
synchronized(jobs) {
Logger.msg(7, "Deleting "+id);
jobs.remove(id);
@@ -186,7 +189,7 @@ public class UserCodeProcess extends StandardClient implements EntityProxyObserv public static UserCodeProcess getInstance() throws UnknownHostException {
return new UserCodeProcess(InetAddress.getLocalHost().getHostName(), "uc");
}
-
+
static public void main(String[] args)
{
int status = 0;
@@ -197,7 +200,8 @@ public class UserCodeProcess extends StandardClient implements EntityProxyObserv UserCodeProcess proc = getInstance();
new Thread(proc).start();
Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
- public void run() {
+ @Override
+ public void run() {
shutdown();
}
}));
@@ -218,7 +222,7 @@ public class UserCodeProcess extends StandardClient implements EntityProxyObserv System.exit(status);
}
}
-
+
public String getDesc() {
return("Usercode Process");
}
@@ -226,4 +230,5 @@ public class UserCodeProcess extends StandardClient implements EntityProxyObserv public static void shutdown() {
active = false;
}
+
}
|
