Search in sources :

Example 1 with ApplicationDescriptorImpl

use of fish.payara.appserver.micro.services.data.ApplicationDescriptorImpl in project Payara by payara.

the class PayaraInstanceImpl method event.

/**
 * @param event
 */
@Override
@SuppressWarnings({ "unchecked" })
public void event(Event event) {
    if (event.is(EventTypes.SERVER_READY)) {
        initialiseInstanceDescriptor();
        PayaraInternalEvent pie = new PayaraInternalEvent(PayaraInternalEvent.MESSAGE.ADDED, me);
        ClusterMessage<PayaraInternalEvent> message = new ClusterMessage<>(pie);
        this.cluster.getEventBus().publish(INTERNAL_EVENTS_NAME, message);
        for (String appName : appRegistry.getAllApplicationNames()) {
            me.addApplication(new ApplicationDescriptorImpl(appRegistry.get(appName)));
        }
        cluster.getClusteredStore().set(INSTANCE_STORE_NAME, myCurrentID, me);
    } else // Adds the application to the clustered register of deployed applications
    if (event.is(Deployment.APPLICATION_STARTED)) {
        if (event.hook() != null && event.hook() instanceof ApplicationInfo) {
            ApplicationInfo applicationInfo = (ApplicationInfo) event.hook();
            if (me == null) {
                // race check
                initialiseInstanceDescriptor();
            }
            me.addApplication(new ApplicationDescriptorImpl(applicationInfo));
            logger.log(Level.FINE, "App Loaded: {2}, Enabled: {0}, my ID: {1}", new Object[] { hazelcast.isEnabled(), myCurrentID, applicationInfo.getName() });
            cluster.getClusteredStore().set(INSTANCE_STORE_NAME, myCurrentID, me);
        }
    } else // removes the application from the clustered registry of applications
    if (event.is(Deployment.APPLICATION_UNLOADED)) {
        if (event.hook() != null && event.hook() instanceof ApplicationInfo) {
            ApplicationInfo applicationInfo = (ApplicationInfo) event.hook();
            me.removeApplication(new ApplicationDescriptorImpl(applicationInfo));
            cluster.getClusteredStore().set(INSTANCE_STORE_NAME, myCurrentID, me);
        }
    } else if (event.is(HazelcastEvents.HAZELCAST_SHUTDOWN_STARTED)) {
        PayaraInternalEvent pie = new PayaraInternalEvent(PayaraInternalEvent.MESSAGE.REMOVED, me);
        ClusterMessage<PayaraInternalEvent> message = new ClusterMessage<>(pie);
        this.cluster.getClusteredStore().remove(INSTANCE_STORE_NAME, myCurrentID);
        this.cluster.getEventBus().publish(INTERNAL_EVENTS_NAME, message);
    }
    // When Hazelcast is bootstrapped, update the instance descriptor with any new information
    if (event.is(HazelcastEvents.HAZELCAST_BOOTSTRAP_COMPLETE)) {
        initialiseInstanceDescriptor();
        logger.log(Level.FINE, "Hz Bootstrap Complete, Enabled: {0}, my ID: {1}", new Object[] { hazelcast.isEnabled(), myCurrentID });
        // remove listener first
        cluster.getEventBus().removeMessageReceiver(INTERNAL_EVENTS_NAME, this);
        cluster.getEventBus().removeMessageReceiver(CDI_EVENTS_NAME, this);
        cluster.getEventBus().addMessageReceiver(INTERNAL_EVENTS_NAME, this);
        cluster.getEventBus().addMessageReceiver(CDI_EVENTS_NAME, this);
    }
    // If the generated name had to be changed, update the instance descriptor with the new information
    if (event.is(HazelcastEvents.HAZELCAST_GENERATED_NAME_CHANGE)) {
        initialiseInstanceDescriptor();
    }
}
Also used : ApplicationDescriptorImpl(fish.payara.appserver.micro.services.data.ApplicationDescriptorImpl) ApplicationInfo(org.glassfish.internal.data.ApplicationInfo) ClusterMessage(fish.payara.nucleus.eventbus.ClusterMessage)

Aggregations

ApplicationDescriptorImpl (fish.payara.appserver.micro.services.data.ApplicationDescriptorImpl)1 ClusterMessage (fish.payara.nucleus.eventbus.ClusterMessage)1 ApplicationInfo (org.glassfish.internal.data.ApplicationInfo)1