raframeresourceadaptor.java

来自「RAFrame.基于SEP的资源管理器院码。」· Java 代码 · 共 572 行 · 第 1/2 页

JAVA
572
字号
        logger.debug("RAFrameResourceAdaptor.eventProcessingSuccessful() called.");
    }
    
    /**
     * implements javax.slee.resource.ResourceAdaptor    
     * Please refer to JSLEE v1.1 Specification, Early Draft Review Page 300 for further information.
     * <br>
     * The SLEE calls this method to inform the resource adaptor object that the specified event was processed
     * unsuccessfully by the SLEE. Event processing can fail if, for example, the SLEE doesn抰 have enough resource
     * to process the event, a SLEE node fails during event processing or a system level failure prevents
     * the SLEE from committing transactions.    
     */
    public void eventProcessingFailed(ActivityHandle activityHandle, Object obj, int param, Address address, int flags, FailureReason failureReason) {
        logger.debug("RAFrameResourceAdaptor.eventProcessingFailed() called.");
    }
    
    /**
     * implements javax.slee.resource.ResourceAdaptor
     * Please refer to JSLEE v1.1 Specification, Early Draft Review Page 301 for further information.
     * <br>
     * The SLEE calls this method to inform the resource adaptor that the SLEE has completed activity end processing
     * for the activity represented by the activity handle. The resource adaptor should release any resource
     * related to this activity as the SLEE will not ask for it again.
     */
    public void activityEnded(javax.slee.resource.ActivityHandle activityHandle) {
        // remove the handle from the list of activities
        activities.remove(activityHandle);
        logger.debug("RAFrameResourceAdaptor.activityEnded() called.");
    }
    
    /**
     * implements javax.slee.resource.ResourceAdaptor    
     * Please refer to JSLEE v1.1 Specification, Early Draft Review Page 301 for further information.
     * <br>
     * The SLEE calls this method to inform the resource adaptor that the activity抯 Activity Context object is no
     * longer attached to any SBB entities and is no longer referenced by any SLEE Facilities. This enables the
     * resource adaptor to implicitly end the Activity object.
     */
    public void activityUnreferenced(javax.slee.resource.ActivityHandle activityHandle) {
        logger.debug("RAFrameResourceAdaptor.activityUnreferenced() called.");
    }
    
    /**
     * implements javax.slee.resource.ResourceAdaptor    
     * Please refer to JSLEE v1.1 Specification, Early Draft Review Page 301 for further information.
     * <br>
     * The SLEE calls this method to query if a specific activity belonging to this resource adaptor object is alive.
     */
    public void queryLiveness(javax.slee.resource.ActivityHandle activityHandle) {
        logger.debug("RAFrameResourceAdaptor.queryLifeness() called.");
    }
    
    /**
     * implements javax.slee.resource.ResourceAdaptor    
     * Please refer to JSLEE v1.1 Specification, Early Draft Review Page 301 for further information.
     * <br>
     * The SLEE calls this method to get access to the underlying activity for an activity handle. The resource
     * adaptor is expected to pass back a non-null object.
     */
    public Object getActivity(javax.slee.resource.ActivityHandle activityHandle) {
        logger.debug("RAFrameResourceAdaptor.getActivity() called.");
        return activities.get(activityHandle);
    }
    
    /**
     * implements javax.slee.resource.ResourceAdaptor    
     * Please refer to JSLEE v1.1 Specification, Early Draft Review Page 301 for further information.
     * <br>
     * The SLEE calls this method to get an activity handle for an activity created by the underlying resource.
     * This method is invoked by the SLEE when it needs to construct an activity context for an activity via an
     * activity context interface factory method invoked by an SBB. 
     */
    public javax.slee.resource.ActivityHandle getActivityHandle(Object obj) {
        logger.debug("RAFrameResourceAdaptor.getActivityHandle(obj) called.");
        return null;
    }

    /**
     * implements javax.slee.resource.ResourceAdaptor    
     * Please refer to JSLEE v1.1 Specification, Early Draft Review Page 302 for further information.
     * <br>
     * The SLEE calls this method to get access to the underlying resource adaptor interface that enables the SBB
     * to invoke the resource adaptor, to send messages for example.
     */    
    public Object getSBBResourceAdaptorInterface(String str) {
        logger.debug("RAFrameResourceAdaptor.getSBBResourceAdapterInterface(" + str + ") called.");
        return raProvider;
    }

    /**
     * implements javax.slee.resource.ResourceAdaptor    
     * Please refer to JSLEE v1.1 Specification, Early Draft Review Page 302 for further information.
     * <br>
     * The SLEE calls this method to get reference to the Marshaler object. The resource adaptor implements
     * the Marshaler interface. The Marshaler is used by the SLEE to convert between object and distributable
     * forms of events and event handles.
     */
    public javax.slee.resource.Marshaler getMarshaler() {
        logger.debug("RAFrameResourceAdaptor.getMarshaler() called.");
        return null;
    }
    
    /**
     * implements javax.slee.resource.ResourceAdaptor    
     * Please refer to JSLEE v1.1 Specification, Early Draft Review Page 302 for further information.
     * <br>
     * The SLEE calls this method to signify to the resource adaptor that a service has been installed and is interested
     * in a specific set of events. The SLEE passes an event filter which identifies a set of event types that
     * services in the SLEE are interested in. The SLEE calls this method once a service is installed.
     */
    public void serviceInstalled(String str, int[] values, String[] str2) {
        logger.debug("RAFrameResourceAdaptor.serviceInstalled() called.");
    }
    
    /**
     * implements javax.slee.resource.ResourceAdaptor    
     * Please refer to JSLEE v1.1 Specification, Early Draft Review Page 303 for further information.
     * <br>
     * The SLEE calls this method to signify that a service has been un-installed in the SLEE. The event types
     * associated to the service key are no longer of interest to a particular application.
     */
    public void serviceUninstalled(String str) {
        logger.debug("RAFrameResourceAdaptor.serviceUninstalled() called.");
    }    
            
    /**
     * implements javax.slee.resource.ResourceAdaptor    
     * Please refer to JSLEE v1.1 Specification, Early Draft Review Page 303 for further information.
     * <br>
     * The SLEE calls this method to inform the resource adaptor that a service has been activated and is interested
     * in the event types associated to the service key. The service must be installed with the resource adaptor
     * via the serviceInstalled method before it can be activated. 
     */
    public void serviceActivated(String str) {
        logger.debug("RAFrameResourceAdaptor.serviceActivated() called.");
    }

    /**
     * implements javax.slee.resource.ResourceAdaptor    
     * Please refer to JSLEE v1.1 Specification, Early Draft Review Page 304 for further information.
     * <br>
     * The SLEE calls this method to inform the SLEE that a service has been deactivated and is no longer interested 
     * in the event types associated to the service key. 
     */
    public void serviceDeactivated(String str) {
        logger.debug("RAFrameResourceAdaptor.serviceDeactivated() called.");
    }


    /**
     * implements javax.slee.resource.ResourceAdaptor
     * The JSLEE v1.1 Specification does not include entityActivated(). However, the API description of JSLEE v1.1
     * does include this method already. So, the documentation follows the code.
     * <br>
     * This method is called in context of project Mobicents in context of resource adaptor
     * activation. More precisely, org.mobicents.slee.resource.ResourceAdaptorEntity.activate() calls
     * this method entityActivated().
     * This method signals the resource adaptor the transition from state "INACTIVE" to state "ACTIVE".
     */
    public void entityActivated() throws javax.slee.resource.ResourceException {
        logger.debug("RAFrameResourceAdaptor.entityActivated() called.");
        try {                        
            logger.debug("Starting RAFStack at port " + port);
            try {
                messageFactory = new MessageFactoryImpl();
                raProvider = new RAFrameProviderImpl(this, messageFactory);
                messageParser = new RAFMessageParser();

                stack = new RAFStack(port, remotehost, remoteport);
                // register the resource adaptor to receive messages from the stack -- onEvent()
                stack.addListener(this);
                stack.start();
                logger.debug("RAFStack up and running.");
                initializeNamingContext();                
            } 
            catch (Exception ex) {
                logger.error("RAFrameResouceAdaptor.start(): Exception caught! ");
                ex.printStackTrace();
                throw new ResourceException(ex.getMessage());
            }
            activities = new HashMap();
        } 
        catch (ResourceException e) {
            e.printStackTrace();
            throw new javax.slee.resource.ResourceException("RAFrameResourceAdaptor.entityActivated(): Failed to activate RAFrame Resource Adaptor!", e);
        }
    }
       
    /**
     * implements javax.slee.resource.ResourceAdaptor
     * The JSLEE v1.1 Specification does not include entityDeactivated(). However, the API description of JSLEE v1.1
     * does include this method already. So, the documentation follows the code.
     * <br>
     * This method is called in context of project Mobicents in context of resource adaptor
     * deactivation. More precisely, org.mobicents.slee.resource.ResourceAdaptorEntity.deactivate() calls
     * this method entityDeactivated(). The method call is done AFTER the call to entityDeactivating().
     * This method signals the resource adaptor the transition from state "STOPPING" to state "INACTIVE".
     */    
    public void entityDeactivated() {
        logger.debug("RAFrameResourceAdaptor.entityDeactivated() called.");
        try {
            cleanNamingContext();
        } catch (NamingException e) {
            logger.error("Cannot unbind naming context");
        }        
        logger.debug("RAFrame Resource Adaptor stopped.");
    }
    
    /**
     * implements javax.slee.resource.ResourceAdaptor
     * The JSLEE v1.1 Specification does not include entityDeactivating(). However, the API description of JSLEE v1.1
     * does include this method already. So, the documentation follows the code.
     * <br>
     * This method is called in context of project Mobicents in context of resource adaptor
     * deactivation. More precisely, org.mobicents.slee.resource.ResourceAdaptorEntity.deactivate() calls
     * this method entityDeactivating() PRIOR to invoking entityDeactivated().
     * This method signals the resource adaptor the transition from state "ACTIVE" to state "STOPPING".
     */    
    public void entityDeactivating() {
        logger.debug("RAFrameResourceAdaptor.entityDeactivating() called.");
        logger.debug("Shuting down the stack.");
        
        try {
            // set the flag in the stack to terminate
            stack.shutdown();
            // the stack will stop every 1000ms to accept incoming connections and check the shutdown flag
            wait(1000);
        }
        catch (InterruptedException ie) {}
    }

    // set up the JNDI naming context     
    private void initializeNamingContext() throws NamingException {
        // get the reference to the SLEE container from JNDI
        SleeContainer container = SleeContainer.lookupFromJndi();
        // get the entities name
        String entityName = bootstrapContext.getEntityName();
        
        ResourceAdaptorEntity resourceAdaptorEntity = ((ResourceAdaptorEntity) container.getResourceAdaptorEnitity(entityName));
        ResourceAdaptorTypeID raTypeId = resourceAdaptorEntity.getInstalledResourceAdaptor().getRaType().getResourceAdaptorTypeID();
        // create the ActivityContextInterfaceFactory
        acif = new RAFrameActivityContextInterfaceFactoryImpl(resourceAdaptorEntity.getServiceContainer(), entityName);
        // set the ActivityContextInterfaceFactory
        resourceAdaptorEntity.getServiceContainer().getActivityContextInterfaceFactories().put(raTypeId, acif);
        
        try {
            if (this.acif != null) {
                // parse the string = java:slee/resources/RAFrameRA/raframeacif
                String jndiName = ((ResourceAdaptorActivityContextInterfaceFactory) acif).getJndiName();
                int begind = jndiName.indexOf(':');
                int toind = jndiName.lastIndexOf('/');
                String prefix = jndiName.substring(begind + 1, toind);
                String name = jndiName.substring(toind + 1);
                logger.debug("jndiName prefix =" + prefix + "; jndiName = " + name);
                SleeContainer.registerWithJndi(prefix, name, this.acif);
            }
        } catch (IndexOutOfBoundsException e) {
            // not register with JNDI
            logger.debug(e);
        }        
    }
    
    // clean the JNDI naming context
    private void cleanNamingContext() throws NamingException {
        try {
            if (this.acif != null) {
                // parse the string = java:slee/resources/RAFrameRA/raframeacif
                String jndiName = ((ResourceAdaptorActivityContextInterfaceFactory) this.acif).getJndiName();
                //remove "java:" prefix
                int begind = jndiName.indexOf(':');
                String javaJNDIName = jndiName.substring(begind + 1);
                logger.debug("JNDI name to unregister: " + javaJNDIName);
                SleeContainer.unregisterWithJndi(javaJNDIName);
                logger.debug("JNDI name unregistered.");
            }
        } catch (IndexOutOfBoundsException e) {
            logger.debug(e);
        }
    }
    
    // method to send a message with the bound RAFStack instance
    public void send(String message) {
        logger.debug("Sending message to stack: " + message);
        stack.send(message);        
    }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?