Search in sources :

Example 1 with EventListener

use of org.glassfish.api.event.EventListener in project Payara by payara.

the class ShoalBackingStoreProxy method postConstruct.

@Override
public void postConstruct() {
    BackingStoreFactoryRegistry.register("replicated", this);
    Logger.getLogger(ShoalBackingStoreProxy.class.getName()).log(Level.FINE, "Registered SHOAL BackingStore Proxy with persistence-type = replicated");
    EventListener glassfishEventListener = new EventListener() {

        @Override
        public void event(Event event) {
            if (event.is(EventTypes.SERVER_SHUTDOWN)) {
                BackingStoreFactoryRegistry.unregister("replicated");
                Logger.getLogger(ShoalBackingStoreProxy.class.getName()).log(Level.FINE, "Unregistered SHOAL BackingStore Proxy with persistence-type = replicated");
            }
        // else if (event.is(EventTypes.SERVER_READY)) {  }
        }
    };
    events.register(glassfishEventListener);
}
Also used : EventListener(org.glassfish.api.event.EventListener)

Example 2 with EventListener

use of org.glassfish.api.event.EventListener in project Payara by payara.

the class ConnectorsClassLoaderUtil method createRARClassLoader.

private ConnectorClassFinder createRARClassLoader(final ClassLoader parent, String moduleDir, final String moduleName, List<URI> appLibs) throws ConnectorRuntimeException {
    ConnectorClassFinder cl = null;
    try {
        final DelegatingClassLoader.ClassFinder librariesCL = getLibrariesClassLoader(appLibs);
        cl = (ConnectorClassFinder) AccessController.doPrivileged(new PrivilegedExceptionAction() {

            public Object run() throws Exception {
                final ConnectorClassFinder ccf = new ConnectorClassFinder(parent, moduleName, librariesCL);
                if (processEnv.getProcessType().isEmbedded()) {
                    events.register(new EventListener() {

                        public void event(Event event) {
                            if (event.is(EventTypes.PREPARE_SHUTDOWN)) {
                                ccf.done();
                            }
                        }
                    });
                }
                return ccf;
            }
        });
    } catch (Exception ex) {
        _logger.log(Level.SEVERE, "error.creating.connector.classloader", ex);
        ConnectorRuntimeException cre = new ConnectorRuntimeException(ex.getMessage());
        cre.initCause(ex);
        throw cre;
    }
    File file = new File(moduleDir);
    try {
        cl.appendURL(file.toURI().toURL());
        appendJars(file, cl);
    } catch (MalformedURLException e) {
        throw new RuntimeException(e);
    }
    return cl;
}
Also used : MalformedURLException(java.net.MalformedURLException) PrivilegedExceptionAction(java.security.PrivilegedExceptionAction) EventListener(org.glassfish.api.event.EventListener) DelegatingClassLoader(org.glassfish.internal.api.DelegatingClassLoader) PrivilegedActionException(java.security.PrivilegedActionException) MalformedURLException(java.net.MalformedURLException)

Example 3 with EventListener

use of org.glassfish.api.event.EventListener in project Payara by payara.

the class GlassFishORBHelper method setORB.

public synchronized void setORB(ORB orb) {
    this.orb = orb;
    if (orb != null) {
        EventListener glassfishEventListener = new org.glassfish.api.event.EventListener() {

            public void event(org.glassfish.api.event.EventListener.Event event) {
                if (event.is(EventTypes.SERVER_SHUTDOWN)) {
                    onShutdown();
                }
            }
        };
        eventsProvider.get().register(glassfishEventListener);
    }
}
Also used : EventListener(org.glassfish.api.event.EventListener)

Example 4 with EventListener

use of org.glassfish.api.event.EventListener in project Payara by payara.

the class TransactionLifecycleService method postConstruct.

@Override
public void postConstruct() {
    EventListener glassfishEventListener = new EventListener() {

        @Override
        public void event(Event event) {
            if (event.is(EventTypes.SERVER_READY)) {
                _logger.fine("TM LIFECYCLE SERVICE - ON READY");
                onReady();
            } else if (event.is(EventTypes.PREPARE_SHUTDOWN)) {
                _logger.fine("TM LIFECYCLE SERVICE - ON SHUTDOWN");
                onShutdown();
            }
        }
    };
    events.register(glassfishEventListener);
    if (nm != null) {
        try {
            nm.publishObject(USER_TX_NO_JAVA_COMP, new NamingObjectProxy.InitializationNamingObjectProxy() {

                @Override
                public Object create(Context ic) throws NamingException {
                    ActiveDescriptor<?> descriptor = habitat.getBestDescriptor(BuilderHelper.createContractFilter("javax.transaction.UserTransaction"));
                    if (descriptor == null)
                        return null;
                    return habitat.getServiceHandle(descriptor).getService();
                }
            }, false);
        } catch (NamingException e) {
            _logger.warning("Can't bind \"UserTransaction\" in JNDI");
        }
    }
}
Also used : Context(javax.naming.Context) NamingObjectProxy(org.glassfish.api.naming.NamingObjectProxy) ActiveDescriptor(org.glassfish.hk2.api.ActiveDescriptor) NamingException(javax.naming.NamingException) EventListener(org.glassfish.api.event.EventListener)

Example 5 with EventListener

use of org.glassfish.api.event.EventListener in project Payara by payara.

the class EventsTest method deployUndeployTest.

@Test
public void deployUndeployTest() throws Exception {
    final List<EventTypes> myTestEvents = getSingletonModuleSuccessfullDeploymentEvents();
    Events events = habitat.getService(Events.class);
    EventListener listener = new EventListener() {

        public void event(Event event) {
            if (myTestEvents.contains(event.type())) {
                myTestEvents.remove(event.type());
            }
        }
    };
    events.register(listener);
    Deployment deployment = habitat.getService(Deployment.class);
    DeployCommandParameters params = new DeployCommandParameters(application);
    params.name = "fakeApplication";
    params.target = "server";
    ActionReport report = habitat.getService(ActionReport.class, "hk2-agent");
    ExtendedDeploymentContext dc = deployment.getBuilder(Logger.getAnonymousLogger(), params, report).source(application).build();
    deployment.deploy(dc);
    events.unregister(listener);
    for (EventTypes et : myTestEvents) {
        System.out.println("An expected event of type " + et.type() + " was not received");
    }
    try {
        final List<EventTypes> myTestEvents2 = getSingletonModuleSuccessfullUndeploymentEvents();
        EventListener listener2 = new EventListener() {

            public void event(Event event) {
                if (myTestEvents2.contains(event.type())) {
                    myTestEvents2.remove(event.type());
                }
            }
        };
        events.register(listener2);
        UndeployCommandParameters params2 = new UndeployCommandParameters("fakeApplication");
        params2.target = "server";
        ActionReport report2 = habitat.getService(ActionReport.class, "hk2-agent");
        ExtendedDeploymentContext dc2 = deployment.getBuilder(Logger.getAnonymousLogger(), params2, report2).source(application).build();
        deployment.undeploy("fakeApplication", dc2);
        events.unregister(listener2);
        for (EventTypes et : myTestEvents2) {
            System.out.println("An expected event of type " + et.type() + " was not received");
        }
    } catch (Throwable t) {
        t.printStackTrace();
    }
}
Also used : DeployCommandParameters(org.glassfish.api.deployment.DeployCommandParameters) UndeployCommandParameters(org.glassfish.api.deployment.UndeployCommandParameters) Events(org.glassfish.api.event.Events) Deployment(org.glassfish.internal.deployment.Deployment) EventTypes(org.glassfish.api.event.EventTypes) EventListener(org.glassfish.api.event.EventListener) ActionReport(org.glassfish.api.ActionReport) ExtendedDeploymentContext(org.glassfish.internal.deployment.ExtendedDeploymentContext) ConfigApiTest(org.glassfish.tests.utils.ConfigApiTest)

Aggregations

EventListener (org.glassfish.api.event.EventListener)6 EventTypes (org.glassfish.api.event.EventTypes)2 Method (java.lang.reflect.Method)1 MalformedURLException (java.net.MalformedURLException)1 PrivilegedActionException (java.security.PrivilegedActionException)1 PrivilegedExceptionAction (java.security.PrivilegedExceptionAction)1 ArrayList (java.util.ArrayList)1 Context (javax.naming.Context)1 NamingException (javax.naming.NamingException)1 ActionReport (org.glassfish.api.ActionReport)1 DeployCommandParameters (org.glassfish.api.deployment.DeployCommandParameters)1 UndeployCommandParameters (org.glassfish.api.deployment.UndeployCommandParameters)1 Event (org.glassfish.api.event.EventListener.Event)1 Events (org.glassfish.api.event.Events)1 RestrictTo (org.glassfish.api.event.RestrictTo)1 NamingObjectProxy (org.glassfish.api.naming.NamingObjectProxy)1 DeploymentException (org.glassfish.deployment.common.DeploymentException)1 ActiveDescriptor (org.glassfish.hk2.api.ActiveDescriptor)1 DelegatingClassLoader (org.glassfish.internal.api.DelegatingClassLoader)1 Deployment (org.glassfish.internal.deployment.Deployment)1