use of org.glassfish.api.event.EventTypes in project Payara by payara.
the class EventsTest method asynchronousEvents.
@Test
@Ignore
public void asynchronousEvents() {
List<EventTypes> asyncEvents = asynchonousEvents();
Iterator<EventTypes> itr = asyncEvents.iterator();
while (itr.hasNext()) {
EventTypes et = itr.next();
for (EventListener.Event evt : allEvents) {
if (evt.is(et)) {
itr.remove();
}
}
}
for (EventTypes et : asyncEvents) {
System.out.println("Asynchronous event " + et.type() + " was not received");
}
Assert.assertTrue(asyncEvents.size() == 0);
}
use of org.glassfish.api.event.EventTypes 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();
}
}
use of org.glassfish.api.event.EventTypes in project Payara by payara.
the class EventsImpl method send.
@Override
public void send(final Event event, boolean asynchronously) {
List<EventListener> l = new ArrayList<EventListener>();
l.addAll(listeners);
for (final EventListener listener : l) {
Method m = null;
try {
// check if the listener is interested with his event.
m = listener.getClass().getMethod("event", Event.class);
} catch (Throwable ex) {
// We need to catch Throwable, otherwise we can server not to
// shutdown when the following happens:
// Assume a bundle which has registered a event listener
// has been uninstalled without unregistering the listener.
// listener.getClass() refers to a class of such an uninstalled
// bundle. If framework has been refreshed, then the
// classloader can't be used further to load any classes.
// As a result, an exception like NoClassDefFoundError is thrown
// from getMethod.
logger.log(Level.SEVERE, KernelLoggerInfo.exceptionSendEvent, ex);
}
if (m != null) {
RestrictTo fooBar = m.getParameterTypes()[0].getAnnotation(RestrictTo.class);
if (fooBar != null) {
EventTypes interested = EventTypes.create(fooBar.value());
if (!event.is(interested)) {
continue;
}
}
}
if (asynchronously) {
executor.submit(new Runnable() {
@Override
public void run() {
try {
listener.event(event);
} catch (Throwable e) {
logger.log(Level.WARNING, KernelLoggerInfo.exceptionDispatchEvent, e);
}
}
});
} else {
try {
listener.event(event);
} catch (DeploymentException de) {
// we re-throw the exception to abort the deployment
throw de;
} catch (Throwable e) {
logger.log(Level.WARNING, KernelLoggerInfo.exceptionDispatchEvent, e);
}
}
}
}
use of org.glassfish.api.event.EventTypes in project Payara by payara.
the class ImmutableTest method test1.
@Test
public void test1() {
EventTypes evt1 = EventTypes.create("foo");
EventTypes evt2 = EventTypes.create("foo");
EventTypes evt3 = EventTypes.create("foo34");
Assert.assertNotSame(evt1, evt3);
Assert.assertEquals(evt1, evt2);
Assert.assertTrue(evt1 == evt2);
Assert.assertFalse(evt1 == evt3);
}
Aggregations