Search in sources :

Example 11 with POAManager

use of org.omg.PortableServer.POAManager in project ACS by ACS-Community.

the class AcsCorba method deactivateComponentPOAManager.

/**
	 * Deactivates a component's POA manager. 
	 * The effect is that no further calls will reach the component.
	 * This method returns immediately if the POA manager is already inactive.
	 * Otherwise it will only return when the active requests are done.
	 * <p>
	 * Note for JacORB (1.4 as well as 2.2.4): there seems to be a problem in 
	 * <code>org.jacorb.poa.RequestController#waitForCompletion</code> with local calls (e.g. collocated component). 
	 * Instead of duly waiting for completion, that method returns immediately when such calls are still executing. 
	 * Even worse, <code>RequestController#activeRequestTable</code> seems to never get touched in case of local calls.
	 * There is a currently commented out JUnit test that verifies this problem.
	 * <p>
	 * The purpose of this method is to allow the container to "drain" a component of requests,
	 * so that <code>cleanUp</code> can be called while no functional calls are running or can come in.
	 * An alternative to using the component POA manager could be to destroy the component POA before
	 * calling <code>cleanUp</code>. This has the disadvantage of also destroying the offshoot child POA,
	 * which is needed to properly clean up callback connections.
	 * <p>
	 * Note that {@link POAManager#deactivate(boolean, boolean)} is called in a separate thread,
	 * so that this method itself may well be called from an ORB thread.
	 * This method uses <code>etherealize_objects=false</code> and <code>wait_for_completion=true</code>.
	 * 
	 * @param compPOA the component POA
	 * @param compName component instance name
	 * @param timeoutMillis timeout in milliseconds after which this call returns even if the POA manager is not inactive yet.
	 * @return true if the POA manager is inactive.
	 */
public boolean deactivateComponentPOAManager(POA compPOA, final String compName, int timeoutMillis) {
    final POAManager compPOAManager = compPOA.the_POAManager();
    if (compPOAManager.get_state() == State.INACTIVE) {
        return true;
    }
    final CountDownLatch deactivateSyncer = new CountDownLatch(1);
    // todo: use thread pool instead of always creating a thread for this purpose
    Thread discardRequestsThread = new Thread(new Runnable() {

        public void run() {
            try {
                // note that deactivate(wait_for_completion=true) must not be called from an ORB thread, 
                // thus we use a separate thread here. This is quite annoying because 
                // at least in JacORB's implementation, another new thread is created inside deactivate
                compPOAManager.deactivate(false, true);
                //					compPOAManager.discard_requests(true);
                deactivateSyncer.countDown();
            } catch (AdapterInactive e) {
                m_logger.log(Level.INFO, "Failed to finish and reject requests for component " + compName, e);
            }
        }
    });
    discardRequestsThread.setDaemon(true);
    discardRequestsThread.setName("deactivatePOAManager_" + compName);
    StopWatch stopWatch = null;
    if (m_logger.isLoggable(Level.FINEST)) {
        stopWatch = new StopWatch();
    }
    discardRequestsThread.start();
    boolean isInactive = false;
    try {
        isInactive = deactivateSyncer.await(timeoutMillis, TimeUnit.MILLISECONDS);
    } catch (InterruptedException e) {
    // isInactive == false
    } finally {
        if (m_logger.isLoggable(Level.FINEST)) {
            long deactivationTime = stopWatch.getLapTimeMillis();
            String msg = "POA manager deactivation for component '" + compName + "' was " + (isInactive ? "" : "*not* ") + "successful and took " + deactivationTime + " ms. " + "The component can" + (isInactive ? "not" : "") + " receive further calls over CORBA.";
            m_logger.finest(msg);
        }
    }
    return isInactive;
}
Also used : POAManager(org.omg.PortableServer.POAManager) AdapterInactive(org.omg.PortableServer.POAManagerPackage.AdapterInactive) CountDownLatch(java.util.concurrent.CountDownLatch) StopWatch(alma.acs.util.StopWatch)

Example 12 with POAManager

use of org.omg.PortableServer.POAManager in project ACS by ACS-Community.

the class ACSRemoteAccess method initialize.

/**
	 * Initialize the connection.
	 * 
	 * @param theORB The ORB. 
	 *               If it is null then a new CORBA connection is initialized.
	 * @param manager A reference to the Manager
	 *                If it is null a reference is built by reading the properties.
	 */
public void initialize(ORB theORB, Manager manager) {
    isExternalORB = (theORB != null);
    this.orb = theORB;
    if (orb == null) {
        listenersDispatcher.publishReport("Initializing CORBA...");
        // ORB stanza
        java.util.Properties orbprops = java.lang.System.getProperties();
        orb = ORB.init(new String[0], orbprops);
        // POA stanza -- use RootPOA
        POA rootPOA = null;
        try {
            rootPOA = POAHelper.narrow(orb.resolve_initial_references("RootPOA"));
        } catch (org.omg.CORBA.ORBPackage.InvalidName in) {
            throw new IllegalStateException("Cannot resolve RootPOA: " + in);
        }
        POAManager poaManager = rootPOA.the_POAManager();
        try {
            poaManager.activate();
        } catch (Exception e) {
            throw new IllegalStateException("POAManager activation failed." + e);
        }
        // setup ORB profiling
        try {
            if (orb instanceof AcsProfilingORB) {
                AcsORBProfiler profiler = new AcsORBProfilerImplBase(logger);
                ((AcsProfilingORB) orb).registerAcsORBProfiler(profiler);
                logger.finer("Orb profiling set up, using class " + AcsORBProfilerImplBase.class.getName());
            }
        } catch (Throwable th) {
            logger.log(Level.WARNING, "Failed to setup ORB profiling.", th);
        }
        // end of CORBA stanza
        listenersDispatcher.publishReport("CORBA initialized.");
    }
    Manager maciManager = manager;
    if (maciManager == null) {
        maciManager = resolveManagerReference();
        if (maciManager == null) {
            // HSO: Ale, should this not throw an exception?
            return;
        }
    }
    NamingContext namingContext = resolveNamingServiceContext(maciManager);
    if (namingContext == null) {
        return;
    }
    if (!resolveNotifyChannel(LOGGING_XML_CHANNEL, namingContext)) {
        return;
    }
    boolean isConsumerAdminCreated = createConsumerAdmin();
    if (!isConsumerAdminCreated) {
        return;
    }
    isInitialized = createStructuredPushConsumer();
}
Also used : AcsORBProfilerImplBase(alma.acs.profiling.orb.AcsORBProfilerImplBase) POA(org.omg.PortableServer.POA) POAManager(org.omg.PortableServer.POAManager) Manager(si.ijs.maci.Manager) NamingContext(org.omg.CosNaming.NamingContext) AcsORBProfiler(org.jacorb.orb.acs.AcsORBProfiler) POAManager(org.omg.PortableServer.POAManager) AcsProfilingORB(org.jacorb.orb.acs.AcsProfilingORB)

Example 13 with POAManager

use of org.omg.PortableServer.POAManager in project ACS by ACS-Community.

the class BlockingPingClient method initializeCORBA.

/**
	 * Initializes CORBA.
	 */
private void initializeCORBA() {
    System.out.println("Initializing CORBA...");
    // ORB stanza
    java.util.Properties orbprops = java.lang.System.getProperties();
    // to make code completely independed, properties have to be set using JVM -D mechanism
    // ORBacus
    //orbprops.put("org.omg.CORBA.ORBClass", "com.ooc.CORBA.ORB");
    //orbprops.put("org.omg.CORBA.ORBSingletonClass", "com.ooc.CORBA.ORBSingleton");
    // JacORB
    //orbprops.put("org.omg.CORBA.ORBClass", "org.jacorb.orb.ORB");
    //orbprops.put("org.omg.CORBA.ORBSingletonClass", "org.jacorb.orb.ORBSingleton");
    // Java JDK (none)
    orb = org.omg.CORBA.ORB.init(new String[0], orbprops);
    // POA stanza -- use RootPOA
    POA rootPOA = null;
    try {
        rootPOA = POAHelper.narrow(orb.resolve_initial_references("RootPOA"));
    } catch (org.omg.CORBA.ORBPackage.InvalidName in) {
        throw new IllegalStateException("Cannot resolve RootPOA: " + in);
    }
    POAManager manager = rootPOA.the_POAManager();
    try {
        // activate POA
        manager.activate();
        // start CORBA event-handler thread 
        orbThread = new Thread(this);
        orbThread.start();
    } catch (Exception e) {
        throw new IllegalStateException("POAManager activation failed: " + e);
    }
    System.out.println("CORBA initialized.");
}
Also used : POA(org.omg.PortableServer.POA) ClientPOA(si.ijs.maci.ClientPOA) POAManager(org.omg.PortableServer.POAManager)

Example 14 with POAManager

use of org.omg.PortableServer.POAManager in project ACS by ACS-Community.

the class BACIRemoteAccess method initialize.

/**
	 * Insert the method's description here.
	 * Creation date: (1.11.2000 13:00:27)
	 */
public void initialize() {
    notifier.reportMessage("Starting engine initialization...");
    Properties props = System.getProperties();
    managerLoc = props.getProperty(MANAGER_CORBALOC);
    String IRloc = props.getProperty(IR_CORBALOC);
    if (managerLoc == null || IRloc == null) {
        CorbalocDialog dialog = new CorbalocDialog();
        if (managerLoc != null)
            dialog.setManagerFieldText(managerLoc);
        if (IRloc != null)
            dialog.setRepositoryFieldText(IRloc);
        dialog.show();
        if (dialog.isOKed()) {
            managerLoc = dialog.getManagerFieldText();
            IRloc = dialog.getRepositoryFieldText();
            ORBdebug = dialog.getDebugSelected();
        }
    }
    if (IRloc == null || "".equals(IRloc))
        throw new IllegalStateException("'" + IR_CORBALOC + "' property is not set. Aborting...");
    if (managerLoc == null || "".equals(managerLoc))
        throw new IllegalStateException("'" + MANAGER_CORBALOC + "' property is not set. Aborting...");
    notifier.reportDebug("BACIRemoteAccess::initialize", "Startup using '" + MANAGER_CORBALOC + "' = '" + managerLoc + "'.");
    notifier.reportDebug("BACIRemoteAccess::initialize", "Startup using '" + IR_CORBALOC + "' = '" + IRloc + "'.");
    String poolTime = props.getProperty(PROPERTY_POOL_TIMEOUT);
    notifier.reportDebug("BACIRemoteAccess::initialize", "Startup using '" + PROPERTY_POOL_TIMEOUT + "' = '" + poolTime + "'.");
    // check it POOL_TIME has to be oveeriden
    if (poolTime != null) {
        try {
            int value = Integer.parseInt(poolTime);
            if (value >= POLL_SLEEP)
                POLL_TIMEOUT = value;
        } catch (Exception ex) {
            notifier.reportDebug("BACIRemoteAccess::initialize", "Failed to parse '" + PROPERTY_POOL_TIMEOUT + "' property value '" + poolTime + "' as integer.");
        }
    }
    notifier.reportDebug("BACIRemoteAccess::initialize", "Configuration: STRICT flag = " + strict);
    notifier.reportDebug("BACIRemoteAccess::initialize", "Configuration: POOL_TIMEOUT = " + POLL_TIMEOUT + " ms.");
    // ORB stanza
    java.util.Properties orbprops = java.lang.System.getProperties();
    // to make code completely independed, properties have to be set using JVM -D mechanism
    // ORBacus
    //orbprops.put("org.omg.CORBA.ORBClass", "com.ooc.CORBA.ORB");
    //orbprops.put("org.omg.CORBA.ORBSingletonClass", "com.ooc.CORBA.ORBSingleton");
    // JacORB
    //orbprops.put("org.omg.CORBA.ORBClass", "org.jacorb.orb.ORB");
    //orbprops.put("org.omg.CORBA.ORBSingletonClass", "org.jacorb.orb.ORBSingleton");
    // Java JDK (does not work)
    //if (ORBdebug)
    //       what to do here
    orb = org.omg.CORBA.ORB.init(new String[0], orbprops);
    notifier.reportDebug("BACIRemoteAccess::initialize", "ORB initialized.");
    // POA stanza -- use RootPOA
    POA rootPOA = null;
    try {
        rootPOA = POAHelper.narrow(orb.resolve_initial_references("RootPOA"));
    } catch (org.omg.CORBA.ORBPackage.InvalidName in) {
        throw new IllegalStateException("Cannot resolve RootPOA: " + in);
    }
    POAManager manager = rootPOA.the_POAManager();
    notifier.reportDebug("BACIRemoteAccess::initialize", "POA initialized.");
    try {
        manager.activate();
        orbThread = new Thread(this);
        orbThread.start();
    } catch (Exception e) {
        throw new IllegalStateException("POAManager activation failed: " + e);
    }
    // resolve IR
    org.omg.CORBA.Object repRef = null;
    notifier.reportDebug("BACIRemoteAccess::initialize", "Trying to resolve 'Repository'.");
    try {
        repRef = orb.string_to_object(IRloc);
    //	repRef = orb.resolve_initial_references("DefaultRepository");
    } catch (Exception e) {
        throw new IllegalStateException("Cannot access orb initial reference 'InterfaceRepository'.");
    }
    if (repRef == null)
        throw new IllegalStateException("Cannot resolve Interface Repository");
    rep = RepositoryHelper.narrow(repRef);
    notifier.reportDebug("BACIRemoteAccess::initialize", "Obtained reference to 'Repository'.");
    notifier.reportMessage("Obtained reference to 'Repository'.");
    // clear callback descriptions list, because it is static!!
    synchronized (descriptions) {
        descriptions.clear();
        notifier.reportDebug("BACIRemoveAccess::destroy", "Cleared IF descriptions list for CallbackImpl.");
    }
    // clear callback operation descriptions list, because it is static!!
    synchronized (operationListDescriptions) {
        operationListDescriptions.clear();
        notifier.reportDebug("BACIRemoveAccess::destroy", "Cleared IF operation descriptions list for CallbackImpl.");
    }
    // start dispatcher
    dispatcher = new Dispatcher();
    dispatcher.start();
    notifier.reportDebug("BACIRemoteAccess::initialize", "Started callback dispatcher thread.");
    // resolve manager
    resolveManager();
}
Also used : Properties(java.util.Properties) POA(org.omg.PortableServer.POA) ClientPOA(si.ijs.maci.ClientPOA) Properties(java.util.Properties) IntrospectionInconsistentException(si.ijs.acs.objectexplorer.engine.IntrospectionInconsistentException) AcsJException(alma.acs.exceptions.AcsJException) DataException(si.ijs.acs.objectexplorer.engine.DataException) NonStickyConnectFailedRemoteException(si.ijs.acs.objectexplorer.engine.NonStickyConnectFailedRemoteException) RemoteException(si.ijs.acs.objectexplorer.engine.RemoteException) POAManager(org.omg.PortableServer.POAManager)

Example 15 with POAManager

use of org.omg.PortableServer.POAManager in project ACS by ACS-Community.

the class AlarmServiceUtils method initORB.

/**
	 * Instantiate the ORB
	 * 
	 * @return the ORB
	 */
private ORB initORB() {
    // ORB stanza
    java.util.Properties orbprops = java.lang.System.getProperties();
    ORB theORB = ORB.init(new String[0], orbprops);
    // POA stanza -- use RootPOA
    POA rootPOA = null;
    try {
        rootPOA = POAHelper.narrow(theORB.resolve_initial_references("RootPOA"));
    } catch (org.omg.CORBA.ORBPackage.InvalidName in) {
        throw new IllegalStateException("Cannot resolve RootPOA: " + in);
    }
    POAManager poaManager = rootPOA.the_POAManager();
    try {
        poaManager.activate();
    } catch (Exception e) {
        throw new IllegalStateException("POAManager activation failed." + e);
    }
    return theORB;
}
Also used : POA(org.omg.PortableServer.POA) POAManager(org.omg.PortableServer.POAManager) ORB(org.omg.CORBA.ORB) InvalidName(org.omg.CORBA.ORBPackage.InvalidName)

Aggregations

POAManager (org.omg.PortableServer.POAManager)18 POA (org.omg.PortableServer.POA)12 Properties (java.util.Properties)5 ClientPOA (si.ijs.maci.ClientPOA)5 ORB (org.omg.CORBA.ORB)3 HandleDataStore (com.cosylab.acs.maci.manager.HandleDataStore)2 ManagerImpl (com.cosylab.acs.maci.manager.ManagerImpl)2 CBstringPOA (alma.ACS.CBstringPOA)1 CBstringSeqPOA (alma.ACS.CBstringSeqPOA)1 AcsJException (alma.acs.exceptions.AcsJException)1 AcsORBProfilerImplBase (alma.acs.profiling.orb.AcsORBProfilerImplBase)1 StopWatch (alma.acs.util.StopWatch)1 ClientProxyImpl (com.cosylab.acs.maci.plug.ClientProxyImpl)1 IOException (java.io.IOException)1 URI (java.net.URI)1 ArrayList (java.util.ArrayList)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 CorbaDSIServant (org.apache.cxf.binding.corba.runtime.CorbaDSIServant)1 AcsORBProfiler (org.jacorb.orb.acs.AcsORBProfiler)1 AcsProfilingORB (org.jacorb.orb.acs.AcsProfilingORB)1