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/Gateway.java | |
| 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/Gateway.java')
| -rw-r--r-- | source/com/c2kernel/process/Gateway.java | 132 |
1 files changed, 68 insertions, 64 deletions
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));
}
|
