use of com.sun.ejb.containers.EJBTimerService in project Payara by payara.
the class ListTimers method listTimers.
private String[] listTimers(String[] serverIds) {
String[] result = new String[serverIds.length];
EJBTimerService ejbTimerService = EJBTimerService.getEJBTimerService();
if (ejbTimerService != null) {
result = ejbTimerService.listTimers(serverIds);
}
return result;
}
use of com.sun.ejb.containers.EJBTimerService in project Payara by payara.
the class EjbDeployer method createAutomaticPersistentTimersForEJB.
/**
* Start EJB Timer Service and create automatic timers for this EJB in this target
*/
private void createAutomaticPersistentTimersForEJB(EjbDescriptor ejbDescriptor, String target) {
try {
// Start EJB Timer Service if it wasn't started yet. On DAS the first start will create the timer table.
EJBTimerService timerService = EJBTimerService.getEJBTimerService(target);
if (_logger.isLoggable(Level.FINE)) {
_logger.log(Level.FINE, "EjbDeployer BEAN ID? " + ejbDescriptor.getUniqueId());
_logger.log(Level.FINE, "EjbDeployer TimerService: " + timerService);
}
if (timerService != null) {
if (_logger.isLoggable(Level.FINE)) {
_logger.log(Level.FINE, "EjbDeployer - calling timerService.createSchedules for " + ejbDescriptor.getUniqueId());
}
timerService.createSchedulesOnServer(ejbDescriptor, getOwnerId(target));
if (_logger.isLoggable(Level.FINE)) {
_logger.log(Level.FINE, "EjbDeployer Done With BEAN ID: " + ejbDescriptor.getUniqueId());
}
} else {
throw new RuntimeException("EJB Timer Service is not available");
}
} catch (Exception e) {
throw new DeploymentException("Failed to create automatic timers for " + ejbDescriptor.getName(), e);
}
}
use of com.sun.ejb.containers.EJBTimerService in project Payara by payara.
the class EjbDeployer method clean.
/**
* Clean any files and artifacts that were created during the execution
* of the prepare method.
*
* @param dc deployment context
*/
public void clean(DeploymentContext dc) {
// Both undeploy and shutdown scenarios are
// handled directly in EjbApplication.shutdown.
// But CMP drop tables should be handled here.
OpsParams params = dc.getCommandParameters(OpsParams.class);
if ((params.origin.isUndeploy() || params.origin.isDeploy()) && isDas()) {
// If CMP beans are present, cmpDeployer should've been initialized in unload()
if (cmpDeployer != null) {
cmpDeployer.clean(dc);
}
Properties appProps = dc.getAppProps();
String uniqueAppId = appProps.getProperty(APP_UNIQUE_ID_PROP);
try {
if (getTimeoutStatusFromApplicationInfo(params.name()) && uniqueAppId != null) {
String target = ((params.origin.isDeploy()) ? dc.getCommandParameters(DeployCommandParameters.class).target : dc.getCommandParameters(UndeployCommandParameters.class).target);
if (DeploymentUtils.isDomainTarget(target)) {
List<String> targets = (List<String>) dc.getTransientAppMetaData(DeploymentProperties.PREVIOUS_TARGETS, List.class);
if (targets == null) {
targets = domain.getAllReferencedTargetsForApplication(params.name());
}
if (targets != null && targets.size() > 0) {
target = targets.get(0);
}
}
EJBTimerService timerService = null;
boolean tsInitialized = false;
ProgressTracker tracker = dc.getTransientAppMetaData(ExtendedDeploymentContext.TRACKER, ProgressTracker.class);
if (tracker == null || !tracker.get("initialized", EngineRef.class).isEmpty()) {
timerService = EJBTimerService.getEJBTimerService(target, false);
tsInitialized = true;
}
if (_logger.isLoggable(Level.FINE)) {
_logger.log(Level.FINE, "EjbDeployer APP ID of a Timeout App? " + uniqueAppId);
_logger.log(Level.FINE, "EjbDeployer TimerService: " + timerService);
}
if (tsInitialized) {
if (timerService == null) {
_logger.log(Level.WARNING, "EJB Timer Service is not available. Timers for application with id " + uniqueAppId + " will not be deleted");
} else {
if (getKeepStateFromApplicationInfo(params.name())) {
_logger.log(Level.INFO, "Timers will not be destroyed since keepstate is true for application {0}", params.name());
} else {
timerService.destroyAllTimers(Long.parseLong(uniqueAppId));
}
}
}
}
} catch (Exception e) {
_logger.log(Level.WARNING, "Failed to delete timers for application with id " + uniqueAppId, e);
}
}
// Security related cleanup is to be done for the undeploy event
if (params.origin.isUndeploy() || params.origin.isDeploy() || params.origin.isLoad()) {
// Removing EjbSecurityManager for undeploy case
String appName = params.name();
String[] contextIds = ejbSecManagerFactory.getContextsForApp(appName, false);
if (contextIds != null) {
for (String contextId : contextIds) {
try {
// TODO:appName is not correct, we need the module name
// from the descriptor.
probeProvider.policyDestructionStartedEvent(contextId);
SecurityUtil.removePolicy(contextId);
probeProvider.policyDestructionEndedEvent(contextId);
probeProvider.policyDestructionEvent(contextId);
} catch (IASSecurityException ex) {
_logger.log(Level.WARNING, "Error removing the policy file " + "for application " + appName + " " + ex);
}
ArrayList<EJBSecurityManager> managers = ejbSecManagerFactory.getManagers(contextId, false);
if (managers != null) {
for (EJBSecurityManager m : managers) {
m.destroy();
}
}
}
}
// Removing the RoleMapper
SecurityUtil.removeRoleMapper(dc);
}
}
use of com.sun.ejb.containers.EJBTimerService in project Payara by payara.
the class DatabaseEJBTimerService method migrateTimers.
/**
*--------------------------------------------------------------
* Private methods for DistributedEJBTimerService
*--------------------------------------------------------------
*/
private int migrateTimers(String serverId) {
if (logger.isLoggable(Level.INFO)) {
logger.log(Level.INFO, "[DistributedEJBTimerService] migrating timers from " + serverId);
}
int result = 0;
// Force loading TimerService if it hadn't been started
EJBTimerService ejbTimerService = EJBTimerService.getEJBTimerService();
if (ejbTimerService != null && ejbTimerService.isPersistent()) {
result = ejbTimerService.migrateTimers(serverId);
} else {
// throw new IllegalStateException("EJB Timer service is null. "
// + "Cannot migrate timers for: " + serverId);
}
return result;
}
use of com.sun.ejb.containers.EJBTimerService in project Payara by payara.
the class TimerWelcomeServlet method processRequest.
/**
* Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
* @param request servlet request
* @param response servlet response
*/
protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
try {
out.println("<html>");
out.println("<head>");
out.println("<title>Timer Application</title>");
out.println("</head>");
out.println("<body>");
out.println("<h3>Welcome to Timer Application</h3>");
out.println("<br>");
// Persistent timers
Set persistenttimers = timer.findActiveTimersOwnedByThisServer();
// Non-persistent timers get directly from the service
EJBTimerService ejbTimerService = EJBTimerService.getEJBTimerService();
Set nonpersistenttimers = ejbTimerService.getNonPersistentActiveTimerIdsByThisServer();
int persistentsize = persistenttimers.size();
int nonpersistentsize = nonpersistenttimers.size();
out.println("There " + ((persistentsize == 1) ? "is " : "are ") + persistentsize + " active persistent timer" + ((persistentsize == 1) ? "" : "s") + " on this container");
out.println("<br>");
out.println("There " + ((nonpersistentsize == 1) ? "is " : "are ") + nonpersistentsize + " active non-persistent timer" + ((nonpersistentsize == 1) ? "" : "s") + " on this container");
out.println("<br>");
} catch (Throwable e) {
out.println("Problem accessing timers... ");
out.println(e);
e.printStackTrace();
} finally {
out.println("</body>");
out.println("</html>");
out.close();
out.flush();
}
}
Aggregations