use of com.sun.ejb.containers.BaseContainer in project jersey by jersey.
the class EjbComponentProvider method registerEjbInterceptor.
private void registerEjbInterceptor() {
try {
final Object interceptor = new EjbComponentInterceptor(injectionManager);
initialContext = getInitialContext();
final EjbContainerUtil ejbUtil = EjbContainerUtilImpl.getInstance();
final ApplicationInfo appInfo = getApplicationInfo(ejbUtil);
final List<String> tempLibNames = new LinkedList<>();
for (ModuleInfo moduleInfo : appInfo.getModuleInfos()) {
final String jarName = moduleInfo.getName();
if (jarName.endsWith(".jar") || jarName.endsWith(".war")) {
final String moduleName = jarName.substring(0, jarName.length() - 4);
tempLibNames.add(moduleName);
final Object bundleDescriptor = moduleInfo.getMetaData(EjbBundleDescriptorImpl.class.getName());
if (bundleDescriptor instanceof EjbBundleDescriptorImpl) {
final Collection<EjbDescriptor> ejbs = ((EjbBundleDescriptorImpl) bundleDescriptor).getEjbs();
for (final EjbDescriptor ejb : ejbs) {
final BaseContainer ejbContainer = EjbContainerUtilImpl.getInstance().getContainer(ejb.getUniqueId());
try {
AccessController.doPrivileged(new PrivilegedExceptionAction() {
@Override
public Object run() throws Exception {
final Method registerInterceptorMethod = BaseContainer.class.getDeclaredMethod("registerSystemInterceptor", java.lang.Object.class);
registerInterceptorMethod.setAccessible(true);
registerInterceptorMethod.invoke(ejbContainer, interceptor);
return null;
}
});
} catch (PrivilegedActionException pae) {
final Throwable cause = pae.getCause();
LOGGER.log(Level.WARNING, LocalizationMessages.EJB_INTERCEPTOR_BINDING_WARNING(ejb.getEjbClassName()), cause);
}
}
}
}
}
libNames.addAll(tempLibNames);
final Object interceptorBinder = initialContext.lookup("java:org.glassfish.ejb.container.interceptor_binding_spi");
// the name
if (interceptorBinder == null) {
throw new IllegalStateException(LocalizationMessages.EJB_INTERCEPTOR_BIND_API_NOT_AVAILABLE());
}
try {
AccessController.doPrivileged(new PrivilegedExceptionAction() {
@Override
public Object run() throws Exception {
Method interceptorBinderMethod = interceptorBinder.getClass().getMethod("registerInterceptor", java.lang.Object.class);
interceptorBinderMethod.invoke(interceptorBinder, interceptor);
EjbComponentProvider.this.ejbInterceptorRegistered = true;
LOGGER.log(Level.CONFIG, LocalizationMessages.EJB_INTERCEPTOR_BOUND());
return null;
}
});
} catch (PrivilegedActionException pae) {
throw new IllegalStateException(LocalizationMessages.EJB_INTERCEPTOR_CONFIG_ERROR(), pae.getCause());
}
} catch (NamingException ex) {
throw new IllegalStateException(LocalizationMessages.EJB_INTERCEPTOR_BIND_API_NOT_AVAILABLE(), ex);
} catch (LinkageError ex) {
throw new IllegalStateException(LocalizationMessages.EJB_INTERCEPTOR_CONFIG_LINKAGE_ERROR(), ex);
}
}
use of com.sun.ejb.containers.BaseContainer in project Payara by payara.
the class SerializableS1ASEJBObjectReference method createObject.
@Override
public Object createObject(long appUniqueId) throws IOException {
Object result = null;
BaseContainer container = EjbContainerUtilImpl.getInstance().getContainer(containerId, appUniqueId);
// after this was serialized
if (container == null) {
_ejbLogger.log(Level.WARNING, "ejb.base.io.EJBOutputStream.null_container", debugStr);
result = null;
} else {
try {
if (remoteBusinessInterface == null) {
java.rmi.Remote reference = container.createRemoteReferenceWithId(instanceKey, null);
result = AbstractSerializableS1ASEJBReference.doRemoteRefClassLoaderConversion(reference);
} else {
String generatedRemoteIntfName = EJBUtils.getGeneratedRemoteIntfName(remoteBusinessInterface);
java.rmi.Remote remoteRef = container.createRemoteReferenceWithId(instanceKey, generatedRemoteIntfName);
java.rmi.Remote newRemoteRef = AbstractSerializableS1ASEJBReference.doRemoteRefClassLoaderConversion(remoteRef);
Thread currentThread = Thread.currentThread();
ClassLoader contextClassLoader = currentThread.getContextClassLoader();
result = EJBUtils.createRemoteBusinessObject(contextClassLoader, remoteBusinessInterface, newRemoteRef);
}
/*TODO
if (haEnabled) {
SFSBClientVersionManager.setClientVersion(
containerId, sfsbKey, sfsbClientVersion);
}*/
} catch (Exception e) {
IOException ioex = new IOException("remote ref create error");
ioex.initCause(e);
throw ioex;
}
}
return result;
}
use of com.sun.ejb.containers.BaseContainer in project Payara by payara.
the class EJBUtils method resolveEjbRefObject.
public static Object resolveEjbRefObject(EjbReferenceDescriptor refDesc, Object jndiObj) throws NamingException {
Object returnObject = jndiObj;
if (refDesc.isLocal()) {
EjbDescriptor target = refDesc.getEjbDescriptor();
BaseContainer container = EjbContainerUtilImpl.getInstance().getContainer(target.getUniqueId());
if (refDesc.isEJB30ClientView()) {
GenericEJBLocalHome genericLocalHome = container.getEJBLocalBusinessHome(refDesc.getEjbInterface());
returnObject = genericLocalHome.create(refDesc.getEjbInterface());
} else {
returnObject = container.getEJBLocalHome();
}
} else {
if (refDesc.isEJB30ClientView() && !(jndiObj instanceof RemoteBusinessWrapperBase)) {
returnObject = EJBUtils.lookupRemote30BusinessObject(jndiObj, refDesc.getEjbInterface());
}
}
return returnObject;
}
use of com.sun.ejb.containers.BaseContainer in project Payara by payara.
the class HazelcastTimerStore method _restoreTimers.
/**
* The portion of timer restoration that deals with registering the JDK
* timer tasks and checking for missed expirations.
*
* @return the Set of restored timers
*/
private Set<HZTimer> _restoreTimers(Set<HZTimer> timersEligibleForRestoration) {
// Do timer restoration in two passes. The first pass updates
// the timer cache with each timer. The second pass schedules
// the JDK timer tasks.
Map timersToRestore = new HashMap();
Set<TimerPrimaryKey> timerIdsToRemove = new HashSet<>();
Set<HZTimer> result = new HashSet<HZTimer>();
for (HZTimer timer : timersEligibleForRestoration) {
TimerPrimaryKey timerId = timer.getKey();
if (getTimerState(timerId) != null) {
// Already restored. Add it to the result but do nothing else.
logger.log(Level.FINE, "@@@ Timer already restored: " + timer);
result.add(timer);
continue;
}
long containerId = timer.getContainerId();
// Timer might refer to an obsolete container.
BaseContainer container = getContainer(containerId);
if (container != null) {
// Update applicationId if it is null (from previous version)
long appid = timer.getApplicationId();
if (appid == 0) {
timer.setApplicationId(container.getApplicationId());
}
// End update
Date initialExpiration = timer.getInitialExpiration();
// Create an instance of RuntimeTimerState.
// Only access timedObjectPrimaryKey if timed object is
// an entity bean. That allows us to lazily load the underlying
// blob for stateless session and message-driven bean timers.
Object timedObjectPrimaryKey = null;
if (container.getContainerType() == BaseContainer.ContainerType.ENTITY) {
timedObjectPrimaryKey = timer.getTimedObjectPk();
}
RuntimeTimerState timerState = new RuntimeTimerState(timerId, initialExpiration, timer.getIntervalDuration(), container, timedObjectPrimaryKey, timer.getSchedule(), // Don't need to store the info ref for persistent timer
null, true);
timerCache_.addTimer(timerId, timerState);
// If a single-action timer is still in the database it never
// successfully delivered, so always reschedule a timer task
// for it. For periodic timers, we use the last known
// expiration time to decide whether we need to fire one
// ejbTimeout to make up for any missed ones.
Date expirationTime = initialExpiration;
Date now = new Date();
if (timerState.isPeriodic()) {
// lastExpiration time, or null if we either aren't
// tracking last expiration or an expiration hasn't
// occurred yet for this timer.
Date lastExpiration = timer.getLastExpiration();
EJBTimerSchedule ts = timer.getSchedule();
// timer expirations.
if ((lastExpiration == null) && now.after(initialExpiration)) {
if (!timerState.isExpired()) {
// This timer didn't even expire one time.
logger.log(Level.INFO, "Rescheduling missed expiration for " + "periodic timer " + timerState + ". Timer expirations should " + " have been delivered starting at " + initialExpiration);
}
// keep expiration time at initialExpiration. That
// will force an ejbTimeout almost immediately. After
// that the timer will return to fixed rate expiration.
} else if ((lastExpiration != null) && ((ts != null && ts.getNextTimeout(lastExpiration).getTimeInMillis() < now.getTime()) || ((ts == null) && now.getTime() - lastExpiration.getTime() > timer.getIntervalDuration()))) {
// Schedule-based timer is periodic
logger.log(Level.INFO, "Rescheduling missed expiration for " + "periodic timer " + timerState + ". Last timer expiration " + "occurred at " + lastExpiration);
// Timer expired at least once and at least one
// missed expiration has occurred.
// keep expiration time at initialExpiration. That
// will force an ejbTimeout almost immediately. After
// that the timer will return to fixed rate expiration.
} else {
// In this case, at least one expiration has occurred
// but that was less than one period ago so there were
// no missed expirations.
expirationTime = calcNextFixedRateExpiration(timerState);
}
} else // single-action timer
if (now.after(initialExpiration)) {
logger.log(Level.INFO, "Rescheduling missed expiration for " + "single-action timer " + timerState + ". Timer expiration should " + " have been delivered at " + initialExpiration);
}
if (expirationTime == null) {
// Schedule-based timer will never expire again - remove it.
logger.log(Level.INFO, "Removing schedule-based timer " + timerState + " that will never expire again");
timerIdsToRemove.add(timerId);
} else {
timersToRestore.put(timerState, expirationTime);
result.add(timer);
}
} else {
// Timed object's container no longer exists - remember its id.
logger.log(Level.FINE, "Skipping timer " + timerId + " for container that is not up: " + containerId);
}
}
if (timerIdsToRemove.size() > 0) {
removeTimers(timerIdsToRemove);
}
for (Iterator entries = timersToRestore.entrySet().iterator(); entries.hasNext(); ) {
Map.Entry next = (Map.Entry) entries.next();
RuntimeTimerState nextTimer = (RuntimeTimerState) next.getKey();
TimerPrimaryKey timerId = nextTimer.getTimerId();
Date expiration = (Date) next.getValue();
scheduleTask(timerId, expiration);
logger.log(Level.FINE, "EJBTimerService.restoreTimers(), scheduling timer " + nextTimer);
}
logger.log(Level.FINE, "DONE EJBTimerService.restoreTimers()");
return result;
}
use of com.sun.ejb.containers.BaseContainer in project Payara by payara.
the class HazelcastTimerStore method _restoreTimers.
/**
* The portion of timer restoration that deals with registering the JDK
* timer tasks and checking for missed expirations.
*
* @return the Set of restored timers
*/
private Collection<HZTimer> _restoreTimers(Collection<HZTimer> timersEligibleForRestoration) {
// Do timer restoration in two passes. The first pass updates
// the timer cache with each timer. The second pass schedules
// the JDK timer tasks.
Map timersToRestore = new HashMap();
Set<TimerPrimaryKey> timerIdsToRemove = new HashSet<>();
Set<HZTimer> result = new HashSet<HZTimer>();
for (HZTimer timer : timersEligibleForRestoration) {
TimerPrimaryKey timerId = timer.getKey();
if (getTimerState(timerId) != null) {
// Already restored. Add it to the result but do nothing else.
logger.log(Level.FINE, "@@@ Timer already restored: " + timer);
result.add(timer);
continue;
}
long containerId = timer.getContainerId();
// Timer might refer to an obsolete container.
BaseContainer container = getContainer(containerId);
if (container != null) {
// Update applicationId if it is null (from previous version)
long appid = timer.getApplicationId();
if (appid == 0) {
timer.setApplicationId(container.getApplicationId());
}
// End update
Date initialExpiration = timer.getInitialExpiration();
// Create an instance of RuntimeTimerState.
// Only access timedObjectPrimaryKey if timed object is
// an entity bean. That allows us to lazily load the underlying
// blob for stateless session and message-driven bean timers.
Object timedObjectPrimaryKey = null;
if (container.getContainerType() == BaseContainer.ContainerType.ENTITY) {
timedObjectPrimaryKey = timer.getTimedObjectPk();
}
RuntimeTimerState timerState = new RuntimeTimerState(timerId, initialExpiration, timer.getIntervalDuration(), container, timedObjectPrimaryKey, timer.getSchedule(), // Don't need to store the info ref for persistent timer
null, true);
timerCache_.addTimer(timerId, timerState);
// If a single-action timer is still in the database it never
// successfully delivered, so always reschedule a timer task
// for it. For periodic timers, we use the last known
// expiration time to decide whether we need to fire one
// ejbTimeout to make up for any missed ones.
Date expirationTime = initialExpiration;
Date now = new Date();
if (timerState.isPeriodic()) {
// lastExpiration time, or null if we either aren't
// tracking last expiration or an expiration hasn't
// occurred yet for this timer.
Date lastExpiration = timer.getLastExpiration();
EJBTimerSchedule ts = timer.getSchedule();
// timer expirations.
if ((lastExpiration == null) && now.after(initialExpiration)) {
if (!timerState.isExpired()) {
// This timer didn't even expire one time.
logger.log(Level.INFO, "Rescheduling missed expiration for " + "periodic timer " + timerState + ". Timer expirations should " + " have been delivered starting at " + initialExpiration);
}
// keep expiration time at initialExpiration. That
// will force an ejbTimeout almost immediately. After
// that the timer will return to fixed rate expiration.
} else if ((lastExpiration != null) && ((ts != null && ts.getNextTimeout(lastExpiration).getTimeInMillis() < now.getTime()) || ((ts == null) && now.getTime() - lastExpiration.getTime() > timer.getIntervalDuration()))) {
// Schedule-based timer is periodic
logger.log(Level.INFO, "Rescheduling missed expiration for " + "periodic timer " + timerState + ". Last timer expiration " + "occurred at " + lastExpiration);
// Timer expired at least once and at least one
// missed expiration has occurred.
// keep expiration time at initialExpiration. That
// will force an ejbTimeout almost immediately. After
// that the timer will return to fixed rate expiration.
} else {
// In this case, at least one expiration has occurred
// but that was less than one period ago so there were
// no missed expirations.
expirationTime = calcNextFixedRateExpiration(timerState);
}
} else // single-action timer
if (now.after(initialExpiration)) {
logger.log(Level.INFO, "Rescheduling missed expiration for " + "single-action timer " + timerState + ". Timer expiration should " + " have been delivered at " + initialExpiration);
}
if (expirationTime == null) {
// Schedule-based timer will never expire again - remove it.
logger.log(Level.INFO, "Removing schedule-based timer " + timerState + " that will never expire again");
timerIdsToRemove.add(timerId);
} else {
timersToRestore.put(timerState, expirationTime);
result.add(timer);
}
} else {
// Timed object's container no longer exists - remember its id.
logger.log(Level.FINE, "Skipping timer " + timerId + " for container that is not up: " + containerId);
}
}
if (timerIdsToRemove.size() > 0) {
for (HZTimer hZTimer : result) {
}
removeTimers(timerIdsToRemove);
}
for (Iterator entries = timersToRestore.entrySet().iterator(); entries.hasNext(); ) {
Map.Entry next = (Map.Entry) entries.next();
RuntimeTimerState nextTimer = (RuntimeTimerState) next.getKey();
TimerPrimaryKey timerId = nextTimer.getTimerId();
Date expiration = (Date) next.getValue();
scheduleTask(timerId, expiration);
logger.log(Level.FINE, "EJBTimerService.restoreTimers(), scheduling timer " + nextTimer);
}
logger.log(Level.FINE, "DONE EJBTimerService.restoreTimers()");
return result;
}
Aggregations