Search in sources :

Example 1 with EJBTimerService

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;
}
Also used : EJBTimerService(com.sun.ejb.containers.EJBTimerService)

Example 2 with EJBTimerService

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);
    }
}
Also used : DeploymentException(org.glassfish.deployment.common.DeploymentException) EJBTimerService(com.sun.ejb.containers.EJBTimerService) DeploymentException(org.glassfish.deployment.common.DeploymentException) IASSecurityException(com.sun.enterprise.security.util.IASSecurityException)

Example 3 with EJBTimerService

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);
    }
}
Also used : EJBSecurityManager(org.glassfish.ejb.security.application.EJBSecurityManager) ProgressTracker(org.glassfish.internal.data.ProgressTracker) OpsParams(org.glassfish.api.deployment.OpsParams) EJBTimerService(com.sun.ejb.containers.EJBTimerService) DeploymentProperties(org.glassfish.deployment.common.DeploymentProperties) Properties(java.util.Properties) EngineRef(org.glassfish.internal.data.EngineRef) DeploymentException(org.glassfish.deployment.common.DeploymentException) IASSecurityException(com.sun.enterprise.security.util.IASSecurityException) IASSecurityException(com.sun.enterprise.security.util.IASSecurityException) DeployCommandParameters(org.glassfish.api.deployment.DeployCommandParameters) UndeployCommandParameters(org.glassfish.api.deployment.UndeployCommandParameters) List(java.util.List) ArrayList(java.util.ArrayList)

Example 4 with EJBTimerService

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;
}
Also used : EJBTimerService(com.sun.ejb.containers.EJBTimerService)

Example 5 with EJBTimerService

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();
    }
}
Also used : Set(java.util.Set) EJBTimerService(com.sun.ejb.containers.EJBTimerService)

Aggregations

EJBTimerService (com.sun.ejb.containers.EJBTimerService)6 IASSecurityException (com.sun.enterprise.security.util.IASSecurityException)2 DeploymentException (org.glassfish.deployment.common.DeploymentException)2 EjbContainerUtil (com.sun.ejb.containers.EjbContainerUtil)1 PropertyVetoException (java.beans.PropertyVetoException)1 File (java.io.File)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Properties (java.util.Properties)1 Set (java.util.Set)1 CreateException (javax.ejb.CreateException)1 EJBException (javax.ejb.EJBException)1 FinderException (javax.ejb.FinderException)1 DeployCommandParameters (org.glassfish.api.deployment.DeployCommandParameters)1 OpsParams (org.glassfish.api.deployment.OpsParams)1 UndeployCommandParameters (org.glassfish.api.deployment.UndeployCommandParameters)1 DeploymentProperties (org.glassfish.deployment.common.DeploymentProperties)1 EjbTimerService (org.glassfish.ejb.config.EjbTimerService)1 EJBSecurityManager (org.glassfish.ejb.security.application.EJBSecurityManager)1 EngineRef (org.glassfish.internal.data.EngineRef)1