summaryrefslogtreecommitdiff
path: root/source/com/c2kernel/entity/CorbaServer.java
diff options
context:
space:
mode:
authorAndrew Branson <andrew.branson@cern.ch>2012-05-30 08:37:45 +0200
committerAndrew Branson <andrew.branson@cern.ch>2012-05-30 08:37:45 +0200
commitb086f57f56bf0eb9dab9cf321a0f69aaaae84347 (patch)
tree8e6e26e8b7eed6abad7a17b093bdbb55c5e6b1ba /source/com/c2kernel/entity/CorbaServer.java
parent22088ae8d2d5ff390518dbe1c4372325ffb3a647 (diff)
Initial Maven Conversion
Diffstat (limited to 'source/com/c2kernel/entity/CorbaServer.java')
-rw-r--r--source/com/c2kernel/entity/CorbaServer.java190
1 files changed, 0 insertions, 190 deletions
diff --git a/source/com/c2kernel/entity/CorbaServer.java b/source/com/c2kernel/entity/CorbaServer.java
deleted file mode 100644
index 84d2ef2..0000000
--- a/source/com/c2kernel/entity/CorbaServer.java
+++ /dev/null
@@ -1,190 +0,0 @@
-package com.c2kernel.entity;
-
-import java.util.Map;
-
-import org.omg.PortableServer.POA;
-import org.omg.PortableServer.POAManager;
-import org.omg.PortableServer.Servant;
-import org.omg.PortableServer.POAManagerPackage.AdapterInactive;
-
-import com.c2kernel.common.CannotManageException;
-import com.c2kernel.common.InvalidDataException;
-import com.c2kernel.common.ObjectAlreadyExistsException;
-import com.c2kernel.common.ObjectNotFoundException;
-import com.c2kernel.entity.agent.ActiveEntity;
-import com.c2kernel.entity.agent.ActiveLocator;
-import com.c2kernel.lookup.AgentPath;
-import com.c2kernel.lookup.EntityPath;
-import com.c2kernel.lookup.InvalidEntityPathException;
-import com.c2kernel.process.Gateway;
-import com.c2kernel.utils.Logger;
-import com.c2kernel.utils.SoftCache;
-
-/**************************************************************************
- *
- * $Revision: 1.8 $
- * $Date: 2005/10/13 08:13:44 $
- *
- * Copyright (C) 2003 CERN - European Organization for Nuclear Research
- * All rights reserved.
- **************************************************************************/
-
-
-public class CorbaServer {
- private Map<EntityPath, Servant> mEntityCache;
- private POA mRootPOA;
- private POA mItemPOA;
- private POA mAgentPOA;
- private POAManager mPOAManager;
-
- public CorbaServer() throws InvalidDataException {
- mEntityCache = new SoftCache<EntityPath, Servant>(50);
-
- // init POA
- try {
- setupPOA();
- mPOAManager.activate();
- } catch (Exception ex) {
- Logger.error(ex);
- throw new InvalidDataException("Error initialising POA", "");
- }
-
- new Thread(new Runnable() {
- @Override
- public void run() {
- Thread.currentThread().setName("ORB Invoker");
- Gateway.getORB().run();
- }
- }).start();
- }
-
- public void close() {
- try {
- mPOAManager.deactivate(true, true);
- } catch (AdapterInactive ex) {
- Logger.error(ex);
- }
- }
-
- /**************************************************************************
- * Initialises the C2KRootPOA with policies which are suitable for Factory objects
- **************************************************************************/
- public void setupPOA() throws Exception {
-
- //Initialise the RootPOA
- mRootPOA = org.omg.PortableServer.POAHelper.narrow(
- Gateway.getORB().resolve_initial_references("RootPOA"));
-
- //Initilaise the default POAManager
-
- mPOAManager = mRootPOA.the_POAManager();
-
- // Create POA for use by the entities
- org.omg.CORBA.Policy[] policies = new org.omg.CORBA.Policy[6];
-
- policies[0] = mRootPOA.create_id_assignment_policy(
- org.omg.PortableServer.IdAssignmentPolicyValue.USER_ID);
- policies[1] = mRootPOA.create_lifespan_policy(
- org.omg.PortableServer.LifespanPolicyValue.PERSISTENT);
- policies[2] = mRootPOA.create_servant_retention_policy(
- org.omg.PortableServer.ServantRetentionPolicyValue.NON_RETAIN);
- policies[3] = mRootPOA.create_id_uniqueness_policy(
- org.omg.PortableServer.IdUniquenessPolicyValue.UNIQUE_ID);
- policies[4] = mRootPOA.create_request_processing_policy(
- org.omg.PortableServer.RequestProcessingPolicyValue.
- USE_SERVANT_MANAGER);
- policies[5] = mRootPOA.create_implicit_activation_policy(
- org.omg.PortableServer.ImplicitActivationPolicyValue.
- NO_IMPLICIT_ACTIVATION);
-
- mItemPOA = mRootPOA.create_POA( "Item",
- mRootPOA.the_POAManager(),
- policies );
- mAgentPOA = mRootPOA.create_POA( "Agent",
- mRootPOA.the_POAManager(),
- policies );
-
- //Create the locators
- TraceableLocator itemLocator = new TraceableLocator( mItemPOA );
- mItemPOA.set_servant_manager( itemLocator._this( Gateway.getORB() ) );
-
- ActiveLocator agentLocator = new ActiveLocator( mAgentPOA );
- mAgentPOA.set_servant_manager( agentLocator._this( Gateway.getORB() ) );
-
- }
-
-
- /**************************************************************************
- * Returns a CORBA servant for a pre-existing entity
- **************************************************************************/
- private Servant getEntity(int sysKey, org.omg.PortableServer.POA poa) throws ObjectNotFoundException {
- try {
- EntityPath entityPath = new EntityPath(sysKey);
- Servant entity = null;
- synchronized (mEntityCache) {
- entity = mEntityCache.get(entityPath);
- if (entity == null) {
- Logger.msg(7, "Creating new servant for "+sysKey);
-
- Class<?> entityClass = Gateway.getLDAPLookup().getEntityClass(entityPath);
-
- if (entityClass == TraceableEntity.class) {
- if (poa == null) poa = mItemPOA;
- entity = new TraceableEntity(sysKey, poa);
- }
- else if (entityClass == ActiveEntity.class) {
- if (poa == null) poa = mAgentPOA;
- entity = new ActiveEntity(sysKey, poa);
- }
- mEntityCache.put(entityPath, entity);
- }
- }
- return entity;
-
- } catch (InvalidEntityPathException ex) {
- throw new ObjectNotFoundException("Invalid Entity Key", "");
- }
- }
-
- /**************************************************************************
- * Wrapper for fetching Items
- **************************************************************************/
- public TraceableEntity getItem(int sysKey, org.omg.PortableServer.POA poa) throws ObjectNotFoundException {
- return (TraceableEntity)getEntity(sysKey, poa);
- }
-
- /**************************************************************************
- * Wrapper for fetching Agents
- **************************************************************************/
- public ActiveEntity getAgent(int sysKey, org.omg.PortableServer.POA poa) throws ObjectNotFoundException {
- return (ActiveEntity)getEntity(sysKey, poa);
- }
-
- /**
- * @param entityPath
- * @return
- */
- public Servant createEntity(EntityPath entityPath) throws CannotManageException, ObjectAlreadyExistsException {
- try {
- if (entityPath == null)
- entityPath = Gateway.getLDAPLookup().getNextKeyManager().generateNextEntityKey();
- } catch (Exception ex) {
- Logger.error(ex);
- throw new CannotManageException("Cannot generate next entity key");
- }
- boolean isAgent = entityPath instanceof AgentPath;
- POA myPOA = isAgent?mAgentPOA:mItemPOA;
- org.omg.CORBA.Object obj = myPOA.create_reference_with_id(entityPath.getOID(), isAgent?AgentHelper.id():ItemHelper.id());
- entityPath.setIOR(obj);
- Servant entity;
- if (isAgent)
- entity = new ActiveEntity(entityPath.getSysKey(), myPOA);
- else
- entity = new TraceableEntity(entityPath.getSysKey(), myPOA);
- synchronized (mEntityCache) {
- mEntityCache.put(entityPath, entity);
- }
- return entity;
-
- }
-}