Skip to content

Commit

Permalink
Clean event dispatching code
Browse files Browse the repository at this point in the history
Signed-off-by: Alexander Pinčuk <alexander.v.pinchuk@gmail.com>
  • Loading branch information
avpinchuk committed Feb 11, 2024
1 parent 1b3d946 commit c25592c
Show file tree
Hide file tree
Showing 33 changed files with 136 additions and 144 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/*
* Copyright (c) 2024 Contributors to the Eclipse Foundation.
* Copyright (c) 2013, 2018 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
Expand Down Expand Up @@ -143,7 +144,7 @@ private void registerIfBatchJobsDirExists(ApplicationInfo applicationInfo) {
}

@Override
public void event(Event event) {
public void event(Event<?> event) {
try {
if (event.is(EventTypes.SERVER_READY)) {
for (String appName : applicationRegistry.getAllApplicationNames()) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2022, 2023 Contributors to the Eclipse Foundation.
* Copyright (c) 2022, 2024 Contributors to the Eclipse Foundation.
* Copyright (c) 1997, 2018 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
Expand Down Expand Up @@ -55,6 +55,7 @@

import org.glassfish.api.admin.ProcessEnvironment;
import org.glassfish.api.admin.ProcessEnvironment.ProcessType;
import org.glassfish.api.deployment.DeploymentContext;
import org.glassfish.api.event.EventListener;
import org.glassfish.api.event.Events;
import org.glassfish.api.naming.GlassfishNamingManager;
Expand Down Expand Up @@ -117,17 +118,17 @@ public void postConstruct() {
}

@Override
public void event(Event event) {
public void event(Event<?> event) {
if (event.is(APPLICATION_LOADED)) {
ApplicationInfo info = APPLICATION_LOADED.getHook(event);

ApplicationInfo info = (ApplicationInfo) event.hook();
loadManagedBeans(info);
registerAppLevelDependencies(info);

} else if (event.is(APPLICATION_UNLOADED)) {
doCleanup(APPLICATION_UNLOADED.getHook(event).getMetaData(Application.class));
ApplicationInfo info = (ApplicationInfo) event.hook();
doCleanup(info.getMetaData(Application.class));
} else if (event.is(DEPLOYMENT_FAILURE)) {
doCleanup(DEPLOYMENT_FAILURE.getHook(event).getModuleMetaData(Application.class));
DeploymentContext context = (DeploymentContext) event.hook();
doCleanup(context.getModuleMetaData(Application.class));
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2022 Contributors to the Eclipse Foundation
* Copyright (c) 2022, 2024 Contributors to the Eclipse Foundation.
* Copyright (c) 1997, 2018 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
Expand Down Expand Up @@ -263,7 +263,7 @@ public String getApplicationName() {
* @param event Event
*/
@Override
public void event(Event event) {
public void event(Event<?> event) {
if (Deployment.UNDEPLOYMENT_VALIDATION.equals(event.type())) {
// this is an application undeploy event
DeploymentContext dc = (DeploymentContext) event.hook();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2022 Contributors to the Eclipse Foundation
* Copyright (c) 2022, 2024 Contributors to the Eclipse Foundation.
* Copyright (c) 1997, 2020 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
Expand Down Expand Up @@ -594,7 +594,7 @@ private void unregisterBeanValidator(String rarName){
}

@Override
public void event(Event event) {
public void event(Event<?> event) {

// added this pre-check so as to validate whether connector-resources referring
// the application (that has rar or is an standalone rar) are present.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2022 Contributors to the Eclipse Foundation
* Copyright (c) 2022, 2024 Contributors to the Eclipse Foundation.
* Copyright (c) 2006, 2018 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
Expand Down Expand Up @@ -418,7 +418,7 @@ protected void generateArtifacts(DeploymentContext dc) throws DeploymentExceptio
}

@Override
public void event(Event event) {
public void event(Event<?> event) {
if (event.is(Deployment.APPLICATION_PREPARED) && isDas()) {
ExtendedDeploymentContext context = (ExtendedDeploymentContext) event.hook();
OpsParams opsparams = context.getCommandParameters(OpsParams.class);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/*
* Copyright (c) 2024 Contributors to the Eclipse Foundation.
* Copyright (c) 1997, 2018 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
Expand Down Expand Up @@ -68,14 +69,11 @@ public <K extends Serializable, V extends Serializable> BackingStore<K, V> creat
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)) { }
}
EventListener glassfishEventListener = 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);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/*
* Copyright (c) 2024 Contributors to the Eclipse Foundation.
* Copyright (c) 2009, 2021 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
Expand Down Expand Up @@ -89,15 +90,10 @@ public synchronized void setORB(ORB orb) {
this.orb = orb;

if (orb != null) {
EventListener glassfishEventListener = new EventListener() {

@Override
public void event(EventListener.Event event) {
if (event.is(SERVER_SHUTDOWN)) {
onShutdown();
}
EventListener glassfishEventListener = event -> {
if (event.is(SERVER_SHUTDOWN)) {
onShutdown();
}

};
eventsProvider.get().register(glassfishEventListener);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2022 Contributors to the Eclipse Foundation
* Copyright (c) 2022, 2024 Contributors to the Eclipse Foundation.
* Copyright (c) 2008, 2020 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
Expand Down Expand Up @@ -177,7 +177,7 @@ public JPApplicationContainer load(JPAContainer container, DeploymentContext con
}

@Override
public void event(@SuppressWarnings("rawtypes") Event event) {
public void event(Event<?> event) {
if (logger.isLoggable(Level.FINEST)) {
logger.finest("JpaDeployer.event():" + event.name());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2022 Contributors to the Eclipse Foundation
* Copyright (c) 2022, 2024 Contributors to the Eclipse Foundation.
* Copyright (c) 2010, 2020 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
Expand Down Expand Up @@ -770,7 +770,7 @@ private ResourceDeployer getResourceDeployer(Object resource){
* config for persisting it in domain.xml
*/
@Override
public void event(Event event) {
public void event(Event<?> event) {
if (event.is(Deployment.DEPLOYMENT_BEFORE_CLASSLOADER_CREATION)) {
DeploymentContext dc = (DeploymentContext) event.hook();
final DeployCommandParameters deployParams = dc.getCommandParameters(DeployCommandParameters.class);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2022 Contributors to the Eclipse Foundation
* Copyright (c) 2022, 2024 Contributors to the Eclipse Foundation.
* Copyright (c) 2006, 2018 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
Expand Down Expand Up @@ -110,8 +110,8 @@ public class SecurityDeployer extends SimpleDeployer<SecurityContainer, DummyApp
private class AppDeployEventListener implements EventListener {

@Override
public void event(Event event) {
Application application = null;
public void event(Event<?> event) {
Application application;

if (MODULE_LOADED.equals(event.type())) {
ModuleInfo moduleInfo = (ModuleInfo) event.hook();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2022 Contributors to the Eclipse Foundation
* Copyright (c) 2022, 2024 Contributors to the Eclipse Foundation.
* Copyright (c) 2009, 2018 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
Expand Down Expand Up @@ -74,16 +74,13 @@ public class TransactionLifecycleService implements PostConstruct, PreDestroy {

@Override
public void postConstruct() {
EventListener glassfishEventListener = new EventListener() {
@Override
public void event(Event event) {
if (event.is(EventTypes.SERVER_READY)) {
LOG.fine("TM LIFECYCLE SERVICE - ON READY");
onReady();
} else if (event.is(EventTypes.PREPARE_SHUTDOWN)) {
LOG.fine("TM LIFECYCLE SERVICE - ON SHUTDOWN");
onShutdown();
}
EventListener glassfishEventListener = event -> {
if (event.is(EventTypes.SERVER_READY)) {
LOG.fine("TM LIFECYCLE SERVICE - ON READY");
onReady();
} else if (event.is(EventTypes.PREPARE_SHUTDOWN)) {
LOG.fine("TM LIFECYCLE SERVICE - ON SHUTDOWN");
onShutdown();
}
};
events.register(glassfishEventListener);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021, 2022 Contributors to Eclipse Foundation.
* Copyright (c) 2021, 2024 Contributors to Eclipse Foundation.
* Copyright (c) 1997, 2018 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
Expand Down Expand Up @@ -551,7 +551,7 @@ public void postConstruct() {
}

@Override
public void event(Event event) {
public void event(Event<?> event) {
if (event.is(Deployment.ALL_APPLICATIONS_PROCESSED)) {
// configure default web modules for virtual servers after all
// applications are processed
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021, 2023 Contributors to the Eclipse Foundation.
* Copyright (c) 2021, 2024 Contributors to the Eclipse Foundation.
* Copyright (c) 2009, 2020 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
Expand Down Expand Up @@ -333,7 +333,7 @@ public WeldApplicationContainer load(WeldContainer container, DeploymentContext
* <code>BeanDeploymentArchive</code>s.
*/
@Override
public void event(Event event) {
public void event(Event<?> event) {
if (event.is(APPLICATION_LOADED)) {
ApplicationInfo appInfo = (ApplicationInfo) event.hook();
WeldBootstrap bootstrap = appInfo.getTransientAppMetaData(WELD_BOOTSTRAP, WeldBootstrap.class);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/*
* Copyright (c) 2024 Contributors to the Eclipse Foundation.
* Copyright (c) 2009, 2018 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
Expand Down Expand Up @@ -193,7 +194,7 @@ public void preDestroy() {
}
}

public void event(Event event) {
public void event(Event<?> event) {
if (event.is(EventTypes.SERVER_READY)) {
// Process the XMLProviders in lib/monitor dir. Should be the last thing to do in server startup.
if (logger.isLoggable(Level.FINE))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Copyright (c) 2021, 2024 Contributors to the Eclipse Foundation.
* Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2021 Contributors to the Eclipse Foundation
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
Expand Down Expand Up @@ -836,28 +836,27 @@ private void initializeGMS() throws GMSException{
registerFailureRecoveryListener("GlassfishFailureRecoveryHandlerTest", this);
}

glassfishEventListener = new org.glassfish.api.event.EventListener() {
public void event(Event event) {
if (gms == null) {
// handle cases where gms is not set and for some reason this handler did not get unregistered.
return;
}
if (event.is(EventTypes.SERVER_SHUTDOWN)) {
GMS_LOGGER.log(LogLevel.INFO, GMS_SERVER_SHUTDOWN_RECEIVED,
new Object[]{gms.getInstanceName(), gms.getGroupName(), event.name()});

// todo: remove these when removing the test register ones above.
removeJoinedAndReadyNotificationListener(GMSAdapterImpl.this);
removeJoinNotificationListener(GMSAdapterImpl.this);
removeFailureNotificationListener(GMSAdapterImpl.this);
removeFailureSuspectedListener(GMSAdapterImpl.this);
gms.shutdown(GMSConstants.shutdownType.INSTANCE_SHUTDOWN);
removePlannedShutdownListener(GMSAdapterImpl.this);
events.unregister(glassfishEventListener);
} else if (event.is(EventTypes.SERVER_READY)) {
// consider putting following, includding call to joinedAndReady into a timertask.
// this time would give instance time to get its heartbeat cache updated by all running
// READY cluster memebrs
glassfishEventListener = event -> {
if (gms == null) {
// handle cases where gms is not set and for some reason this handler did not get unregistered.
return;
}
if (event.is(EventTypes.SERVER_SHUTDOWN)) {
GMS_LOGGER.log(LogLevel.INFO, GMS_SERVER_SHUTDOWN_RECEIVED,
new Object[]{gms.getInstanceName(), gms.getGroupName(), event.name()});

// todo: remove these when removing the test register ones above.
removeJoinedAndReadyNotificationListener(GMSAdapterImpl.this);
removeJoinNotificationListener(GMSAdapterImpl.this);
removeFailureNotificationListener(GMSAdapterImpl.this);
removeFailureSuspectedListener(GMSAdapterImpl.this);
gms.shutdown(GMSConstants.shutdownType.INSTANCE_SHUTDOWN);
removePlannedShutdownListener(GMSAdapterImpl.this);
events.unregister(glassfishEventListener);
} else if (event.is(EventTypes.SERVER_READY)) {
// consider putting following, includding call to joinedAndReady into a timertask.
// this time would give instance time to get its heartbeat cache updated by all running
// READY cluster memebrs
// final long MAX_WAIT_DURATION = 4000;
//
// long elapsedDuration = (joinTime == 0L) ? 0 : System.currentTimeMillis() - joinTime;
Expand All @@ -869,8 +868,7 @@ public void event(Event event) {
// } catch(Throwable t) {}
// }
// validateCoreMembers();
gms.reportJoinedAndReadyState();
}
gms.reportJoinedAndReadyState();
}
};
events.register(glassfishEventListener);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public AMXStartupService() {

private final class ShutdownListener implements EventListener {

public void event(EventListener.Event event) {
public void event(Event<?> event) {
if (event.is(EventTypes.SERVER_SHUTDOWN)) {
shutdown();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2022, 2022 Contributors to the Eclipse Foundation.
* Copyright (c) 2022, 2024 Contributors to the Eclipse Foundation.
* Copyright (c) 2006, 2018 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
Expand Down Expand Up @@ -579,12 +579,12 @@ private DeploymentFailedListener(ReadableArchive archive) {
}

@Override
public void event(@RestrictTo(Deployment.DEPLOYMENT_FAILURE_NAME) Event event) {
public void event(@RestrictTo(Deployment.DEPLOYMENT_FAILURE_NAME) Event<?> event) {
if (!event.is(Deployment.DEPLOYMENT_FAILURE)) {
return;
}

DeploymentContext dc = Deployment.DEPLOYMENT_FAILURE.getHook(event);
DeploymentContext dc = (DeploymentContext) event.hook();

if (!archive.equals(dc.getSource())) {
return;
Expand Down

0 comments on commit c25592c

Please sign in to comment.