Search in sources :

Example 1 with Servant

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

the class CharacteristicComponentImpl method initialize.

/**
	 * @see alma.acs.component.ComponentLifecycle#initialize(alma.acs.container.ContainerServices)
	 */
public void initialize(ContainerServices containerServices) throws ComponentLifecycleException {
    super.initialize(containerServices);
    try {
        DAL dal = m_containerServices.getCDB();
        // create characteristic model
        // TODO think of error handling; why creating model per instance...
        characteristicModelImpl = new CharacteristicModelImpl("alma/" + m_instanceName, dal);
    } catch (AcsJContainerServicesEx ce) {
        throw new ComponentLifecycleException("Failed to create characteristic model.", ce);
    }
    // create properties list
    properties = new HashMap<PropertyOperations, Servant>();
}
Also used : ComponentLifecycleException(alma.acs.component.ComponentLifecycleException) PropertyOperations(alma.ACS.PropertyOperations) AcsJContainerServicesEx(alma.JavaContainerError.wrappers.AcsJContainerServicesEx) Servant(org.omg.PortableServer.Servant) DAL(com.cosylab.CDB.DAL)

Example 2 with Servant

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

the class ManagerContainerServices method deactivateOffShoot.

public void deactivateOffShoot(Object offshootImpl) throws AcsJContainerServicesEx {
    if (offshootImpl instanceof Servant) {
        Servant servant = (Servant) offshootImpl;
        checkOffShootServant(servant);
        byte[] id = null;
        try {
            id = offshootPoa.servant_to_id(servant);
            offshootPoa.deactivate_object(id);
        } catch (Throwable thr) {
            String msg = "failed to deactivate offshoot of type '" + servant.getClass().getName() + "' (ID=" + String.valueOf(id) + ")";
            logger.log(Level.WARNING, msg, thr);
            AcsJContainerServicesEx ex = new AcsJContainerServicesEx(thr);
            ex.setContextInfo(msg);
            throw ex;
        }
    } else {
        AcsJContainerServicesEx ex = new AcsJContainerServicesEx();
        ex.setContextInfo("Not yet implemented");
        throw ex;
    }
}
Also used : AcsJContainerServicesEx(alma.JavaContainerError.wrappers.AcsJContainerServicesEx) Servant(org.omg.PortableServer.Servant)

Example 3 with Servant

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

the class Server method run.

public void run(String[] args) {
    String iorFileName = null;
    final Logger sharedLogger = ClientLogManager.getAcsLogManager().getLoggerForApplication(CDB_LOGGER_NAME, true);
    try {
        Properties properties = System.getProperties();
        // default is JDK ORB
        boolean useJacORB = false;
        int portNumber = Integer.parseInt(ACSPorts.getCDBPort());
        for (int i = 0; i < args.length; i++) {
            if (args[i].equals("-OAport") || args[i].equals("-OAPort")) {
                if (i < args.length - 1) {
                    portNumber = Integer.valueOf(args[++i]).intValue();
                }
            }
            if (args[i].equals("-OAIAddr")) {
                if (i < args.length - 1) {
                    properties.put("OAIAddr", args[++i]);
                }
            }
            if (args[i].equals("-orbacus")) {
                sharedLogger.log(AcsLogLevel.NOTICE, "ORBacus is no longer supported, switching to JacORB.");
                //System.err.println(
                //	"ORBacus is no longer supported, switching to JacORB.");
                useJacORB = true;
            }
            if (args[i].equals("-jacorb")) {
                useJacORB = true;
            }
            if (args[i].equals("-o")) {
                if (i < args.length - 1) {
                    iorFileName = args[++i];
                } else {
                    iorFileName = "DAL.ior";
                }
            }
        }
        if (useJacORB) {
            sharedLogger.log(AcsLogLevel.DELOUSE, "DALfs will use JacORB ORB");
            properties.put("org.omg.CORBA.ORBClass", "org.jacorb.orb.ORB");
            properties.put("org.omg.CORBA.ORBSingletonClass", "org.jacorb.orb.ORBSingleton");
            // port
            properties.put("OAPort", Integer.toString(portNumber));
            // ORB implementation name
            properties.put("jacorb.implname", "ORB");
            /*
				 * by setting the following property, the ORB will
				 * accept client requests targeted at the object with
				 * key "CDB", so more readable corbaloc URLs
				 * can be used
				 */
            properties.put("jacorb.orb.objectKeyMap.CDB", "ORB/dalPOA/CDB");
        } else {
            properties.put("com.sun.CORBA.POA.ORBPersistentServerPort", Integer.toString(portNumber));
        }
        // create and initialize the ORB
        ORB orb = ORB.init(args, properties);
        // get reference to rootpoa & activate the POAManager
        POA rootpoa = POAHelper.narrow(orb.resolve_initial_references("RootPOA"));
        /* create a user defined poa for the naming contexts */
        org.omg.CORBA.Policy[] policies = new org.omg.CORBA.Policy[2];
        policies[0] = rootpoa.create_id_assignment_policy(IdAssignmentPolicyValue.USER_ID);
        if (useJacORB)
            policies[1] = rootpoa.create_lifespan_policy(LifespanPolicyValue.PERSISTENT);
        else
            policies[1] = rootpoa.create_lifespan_policy(LifespanPolicyValue.TRANSIENT);
        POA dalpoa = rootpoa.create_POA("dalPOA", rootpoa.the_POAManager(), policies);
        for (int i = 0; i < policies.length; i++) policies[i].destroy();
        rootpoa.the_POAManager().activate();
        // create servant and register it with the ORB
        final WDALImpl servantDelegate = new WDALImpl(args, orb, dalpoa, sharedLogger);
        WJDALOperations topLevelServantDelegate = servantDelegate;
        if (Boolean.getBoolean(LOG_CDB_CALLS_PROPERTYNAME)) {
            // Currently we only intercept the functional IDL-defined methods, by wrapping servantDelegate.
            // If we want to also intercept the CORBA admin methods, then *servant* should be wrapped with a dynamic proxy instead.
            WJDALOperations interceptingServantDelegate = SimpleCallInterceptor.createSimpleInterceptor(WJDALOperations.class, servantDelegate, sharedLogger);
            topLevelServantDelegate = interceptingServantDelegate;
        }
        final Servant servant = new WJDALPOATie(topLevelServantDelegate);
        //create object id
        byte[] id = { 'C', 'D', 'B' };
        //activate object
        dalpoa.activate_object_with_id(id, servant);
        // get object reference from the servant
        org.omg.CORBA.Object ref = dalpoa.servant_to_reference(servant);
        jdal = JDALHelper.narrow(ref);
        // try to bind it in IOR
        if (useJacORB) {
        // nothing to do here
        } else {
            ((com.sun.corba.se.internal.Interceptors.PIORB) orb).register_initial_reference("CDB", rootpoa.servant_to_reference(servant));
        }
        // register in name service if available
        try {
            // get the root naming context
            org.omg.CORBA.Object objRef = orb.resolve_initial_references("NameService");
            NamingContext ncRef = NamingContextHelper.narrow(objRef);
            // Bind the object reference in naming
            NameComponent nc = new NameComponent("CDB", "");
            NameComponent[] path = { nc };
            ncRef.rebind(path, jdal);
        }// is not set at all with the ORBInitRef.NameService property
         catch (Exception e1) {
            sharedLogger.log(AcsLogLevel.NOTICE, "JDAL is NOT registered in the name service because of: " + e1);
        }
        if (Integer.getInteger("ACS.logstdout", 4) < 4) {
            sharedLogger.log(AcsLogLevel.INFO, "JDAL is listening on " + ACSPorts.getIP() + ":" + portNumber + "/CDB");
        }
        // recover (notify) clients
        if (servantDelegate instanceof Recoverer) {
            ((Recoverer) servantDelegate).recoverClients();
        }
        if (iorFileName != null) {
            // write the object reference to a file
            PrintWriter iorFile = new PrintWriter(new FileWriter(iorFileName));
            iorFile.println(orb.object_to_string(jdal));
            iorFile.close();
        }
        sharedLogger.log(AcsLogLevel.INFO, "JDAL is ready and waiting ...");
        // GCH 2006-11-13
        // Here we put also a println to be sure that the message
        // ALWAYS appears on standart output, also if the logging level 
        // is put higher than INFO.
        // This is needed because the ACS startup scripts wait for this message
        // to declare complete the startup of the CDB. 
        System.out.println("JDAL is ready and waiting ...");
        // preload cache
        new Thread(new Runnable() {

            public void run() {
                preloadCache(servantDelegate.getDALImplDelegate(), sharedLogger);
            }
        }, "preload-cache").start();
        // Init remote Logging
        try {
            ClientLogManager.getAcsLogManager().initRemoteLoggingForService(orb, true);
        } catch (Throwable t) {
            sharedLogger.log(AcsLogLevel.ERROR, "Error initializing the remote logging");
        }
        // wait for invocations from clients
        orb.run();
        sharedLogger.log(AcsLogLevel.INFO, "JDAL exiting ORB loop ...");
    } catch (Exception e) {
        sharedLogger.log(AcsLogLevel.NOTICE, "ERROR: " + e);
        e.printStackTrace(System.out);
    }
}
Also used : WJDALOperations(com.cosylab.CDB.WJDALOperations) NameComponent(org.omg.CosNaming.NameComponent) FileWriter(java.io.FileWriter) Logger(java.util.logging.Logger) Properties(java.util.Properties) NamingContext(org.omg.CosNaming.NamingContext) Servant(org.omg.PortableServer.Servant) PrintWriter(java.io.PrintWriter) POA(org.omg.PortableServer.POA) WJDALPOATie(com.cosylab.CDB.WJDALPOATie) ORB(org.omg.CORBA.ORB)

Example 4 with Servant

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

the class ContainerServicesImpl method activateOffShoot.

/**
	 * @see alma.acs.container.ContainerServices#activateOffShoot(org.omg.PortableServer.Servant)
	 */
@Override
public <T extends OffShootOperations> OffShoot activateOffShoot(T offshootImpl, Class<T> idlOpInterface) throws AcsJContainerServicesEx {
    Servant servant = null;
    boolean isTie = false;
    boolean haveToInject = false;
    // Checks
    checkOffShoot(offshootImpl);
    // and set the offshoot implementation as the final delegate
    if (!(offshootImpl instanceof Servant)) {
        if (idlOpInterface == null)
            throw new AcsJContainerServicesEx(new NullPointerException("Received null idlOpInterface when asking to activate XML offshoot"));
        if (!idlOpInterface.isAssignableFrom(offshootImpl.getClass())) {
            AcsJContainerServicesEx ex = new AcsJContainerServicesEx();
            ex.setContextInfo("Received OffShoot of type '" + offshootImpl.getClass().getName() + "' does not inherits from '" + idlOpInterface.getName() + "'");
            throw ex;
        }
        // Guess the name of the xyzPOATie class, build it, and delegate
        String poaTieClassName = null;
        try {
            m_logger.fine("Creating POATie servant for offshoot '" + offshootImpl.getClass().getName() + "'");
            // Get the POATie class and the expected xyzOperations interface
            String baseClassName = idlOpInterface.getName().substring(0, idlOpInterface.getName().length() - 1);
            poaTieClassName = baseClassName + "POATie";
            Class<?> poaTieClazz = Class.forName(poaTieClassName);
            Method implGetter = poaTieClazz.getMethod("_delegate", (Class[]) null);
            Class<?> operationsIF = implGetter.getReturnType();
            // Create the dynamic XML entities wrapper
            Object proxy = DynamicProxyFactory.getDynamicProxyFactory(m_logger).createServerProxy(operationsIF, offshootImpl, idlOpInterface);
            // Create the POATie object, give it the proxy, and set it as our servant
            Constructor<?> c = poaTieClazz.getConstructor(new Class[] { operationsIF });
            servant = (Servant) c.newInstance(proxy);
            if (m_componentXmlTranslatorProxy != null)
                haveToInject = true;
        } catch (ClassNotFoundException e) {
            String msg = "Failed to create servant for offshoot " + offshootImpl.getClass().getName() + ": class '" + poaTieClassName + "' cannot be found";
            m_logger.log(AcsLogLevel.ERROR, msg, e);
            AcsJContainerServicesEx ex = new AcsJContainerServicesEx();
            ex.setContextInfo(msg);
            throw ex;
        } catch (Exception e) {
            throw new AcsJContainerServicesEx(e);
        }
    } else {
        m_logger.fine("Don't need to create servant for offshoot '" + offshootImpl.getClass().getName() + "'");
        servant = (Servant) offshootImpl;
    }
    // check if the servant is the Tie variant, which allows proxy-based call interception by the container
    String servantName = servant.getClass().getName();
    if (servantName.endsWith("POATie")) {
        try {
            // the _delegate getter method is mandated by the IDL-to-Java mapping spec
            Method implGetter = servant.getClass().getMethod("_delegate", (Class[]) null);
            isTie = true;
            Class<?> operationsIF = implGetter.getReturnType();
            java.lang.Object offshootTiedImpl = implGetter.invoke(servant, (java.lang.Object[]) null);
            // now we insert the interceptor between the tie skeleton and the impl.
            // Offshoots have no name, so we construct one from the component name and the offshoot interface name
            // 
            String qualOffshootName = getName() + "/" + operationsIF.getName().substring(0, operationsIF.getName().length() - "Operations".length());
            java.lang.Object interceptingOffshootImpl = ContainerSealant.createContainerSealant(operationsIF, offshootTiedImpl, qualOffshootName, true, m_logger, Thread.currentThread().getContextClassLoader(), methodsExcludedFromInvocationLogging);
            Method implSetter = servant.getClass().getMethod("_delegate", new Class[] { operationsIF });
            implSetter.invoke(servant, new java.lang.Object[] { interceptingOffshootImpl });
            m_logger.fine("created sealant for offshoot " + qualOffshootName);
        } catch (NoSuchMethodException e) {
        // so this was not a Tie skeleton, even though its name ends misleadingly with "POATie"
        } catch (Exception e) {
            m_logger.log(Level.WARNING, "Failed to create interceptor for offshoot " + servantName, e);
        }
    }
    if (!isTie) {
    // TODO: perhaps require tie offshoots with ACS 5.0, and enable this warning log			
    //			m_logger.warning("Offshoot servant '" + servantName + "' from component '" + getName() + 
    //					"' does not follow the tie approach. Calls can thus not be intercepted by the container.");
    }
    OffShoot shoot = null;
    try {
        org.omg.CORBA.Object obj = acsCorba.activateOffShoot(servant, m_clientPOA);
        m_activatedOffshootsMap.put(offshootImpl, servant);
        shoot = OffShootHelper.narrow(obj);
    } catch (Throwable thr) {
        String msg = "failed to activate offshoot object of type '" + servant.getClass().getName() + "' for client '" + m_clientName + "'. ";
        // flatten the exception chain by one level if possible
        if (thr instanceof AcsJContainerServicesEx && thr.getCause() != null) {
            msg += "(" + thr.getMessage() + ")";
            thr = thr.getCause();
        }
        m_logger.log(Level.FINE, msg, thr);
        AcsJContainerServicesEx ex = new AcsJContainerServicesEx(thr);
        throw ex;
    }
    // so when requesting an offshoot into the component, we return the corresponding CORBA object
    if (haveToInject) {
        m_logger.fine("Injecting offshoot '" + offshootImpl.getClass().getName() + "' to '" + m_clientName + "' component XML binder");
        ComponentInvocationHandler handler = (ComponentInvocationHandler) Proxy.getInvocationHandler(m_componentXmlTranslatorProxy);
        handler.addOffshoot(offshootImpl, shoot);
    }
    m_logger.fine("successfully activated offshoot of type " + offshootImpl.getClass().getName());
    return shoot;
}
Also used : Method(java.lang.reflect.Method) AcsJContainerServicesEx(alma.JavaContainerError.wrappers.AcsJContainerServicesEx) Servant(org.omg.PortableServer.Servant) InvocationTargetException(java.lang.reflect.InvocationTargetException) AcsJException(alma.acs.exceptions.AcsJException) OffShoot(alma.ACS.OffShoot) ComponentInvocationHandler(alma.acs.component.dynwrapper.ComponentInvocationHandler)

Example 5 with Servant

use of org.omg.PortableServer.Servant in project cxf by apache.

the class CorbaDestination method getAddressWithId.

public EndpointReferenceType getAddressWithId(String id) {
    if (bindingPOA == null) {
        throw new CorbaBindingException("getAddressWithId failed because the poa is null");
    }
    final EndpointReferenceType ref;
    try {
        Servant servant = bindingPOA.id_to_servant(objectId);
        org.omg.CORBA.Object objRef = bindingPOA.create_reference_with_id(id.getBytes(), servant._all_interfaces(bindingPOA, objectId)[0]);
        AddressType addr = new AddressType();
        orbConfig.exportObjectReference(orb, objRef, address.getLocation(), addr);
        ref = EndpointReferenceUtils.getEndpointReference(addr.getLocation());
        EndpointInfo ei = getEndPointInfo();
        if (ei.getService() != null) {
            EndpointReferenceUtils.setServiceAndPortName(ref, ei.getService().getName(), ei.getName().getLocalPart());
        }
    } catch (Exception e) {
        throw new CorbaBindingException("Failed to getAddressWithId, reason:" + e.toString(), e);
    }
    return ref;
}
Also used : EndpointInfo(org.apache.cxf.service.model.EndpointInfo) EndpointReferenceType(org.apache.cxf.ws.addressing.EndpointReferenceType) AddressType(org.apache.cxf.binding.corba.wsdl.AddressType) CorbaDSIServant(org.apache.cxf.binding.corba.runtime.CorbaDSIServant) Servant(org.omg.PortableServer.Servant) IOException(java.io.IOException)

Aggregations

Servant (org.omg.PortableServer.Servant)16 POA (org.omg.PortableServer.POA)5 AcsJContainerServicesEx (alma.JavaContainerError.wrappers.AcsJContainerServicesEx)4 AcsJContainerEx (alma.JavaContainerError.wrappers.AcsJContainerEx)2 AcsJException (alma.acs.exceptions.AcsJException)2 AcsJCDBRecordDoesNotExistEx (alma.cdbErrType.wrappers.AcsJCDBRecordDoesNotExistEx)2 DummyComponent (alma.jconttest.DummyComponent)2 DummyComponentPOATie (alma.jconttest.DummyComponentPOATie)2 ObjectNotFoundException (org.cristalise.kernel.common.ObjectNotFoundException)2 OffShoot (alma.ACS.OffShoot)1 PropertyOperations (alma.ACS.PropertyOperations)1 AcsJJavaComponentHelperEx (alma.JavaContainerError.wrappers.AcsJJavaComponentHelperEx)1 BACIPropertyType (alma.TMCDB.baci.BACIPropertyType)1 EmptyStringHandlerBACIPropertyType (alma.TMCDB.baci.EmptyStringHandlerBACIPropertyType)1 AcsComponentClassLoader (alma.acs.classloading.AcsComponentClassLoader)1 ComponentLifecycle (alma.acs.component.ComponentLifecycle)1 ComponentLifecycleException (alma.acs.component.ComponentLifecycleException)1 ComponentInvocationHandler (alma.acs.component.dynwrapper.ComponentInvocationHandler)1 ComponentServantManager (alma.acs.container.ComponentServantManager)1 ClientLogManager (alma.acs.logging.ClientLogManager)1