Search in sources :

Example 1 with EjbTimerService

use of org.glassfish.ejb.config.EjbTimerService in project Payara by payara.

the class EJBTimerService method initProperties.

private void initProperties() {
    try {
        // Check for property settings from domain.xml
        EjbContainer ejbc = ejbContainerUtil.getEjbContainer();
        EjbTimerService ejbt = ejbc.getEjbTimerService();
        if (ejbt != null) {
            String valString = ejbt.getMinimumDeliveryIntervalInMillis();
            long val = (valString != null) ? Long.parseLong(valString) : -1;
            if (val > 0) {
                minimumDeliveryInterval_ = val;
            }
            valString = ejbt.getMaxRedeliveries();
            val = (valString != null) ? Long.parseLong(valString) : -1;
            // EJB 2.1 specification minimum is 1
            if (val > 0) {
                maxRedeliveries_ = val;
            }
            valString = ejbt.getRedeliveryIntervalInternalInMillis();
            val = (valString != null) ? Long.parseLong(valString) : -1;
            if (val > 0) {
                redeliveryInterval_ = val;
            }
            rescheduleFailedTimer = Boolean.valueOf(ejbt.getPropertyValue(RESCHEDULE_FAILED_TIMER));
            // Load confing listener
            ejbContainerUtil.getServices().getService(EJBTimerServiceConfigListener.class);
        }
    } catch (Exception e) {
        logger.log(Level.FINE, "Exception converting timer service " + "domain.xml properties.  Defaults will be used instead.", e);
    }
    logger.log(Level.FINE, "EJB Timer Service properties : " + "min delivery interval = " + getMinimumDeliveryInterval() + "\nmax redeliveries = " + maxRedeliveries_ + "\nredelivery interval = " + getRedeliveryInterval());
}
Also used : EjbContainer(org.glassfish.ejb.config.EjbContainer) EjbTimerService(org.glassfish.ejb.config.EjbTimerService) FinderException(javax.ejb.FinderException) EJBException(javax.ejb.EJBException) CreateException(javax.ejb.CreateException)

Example 2 with EjbTimerService

use of org.glassfish.ejb.config.EjbTimerService in project Payara by payara.

the class EJBTimerServiceUpgrade method doUpgrade.

private void doUpgrade(EjbTimerService ts) {
    String value = ts.getMinimumDeliveryIntervalInMillis();
    if (value == null || "7000".equals(value)) {
        value = "" + EjbContainerUtil.MINIMUM_TIMER_DELIVERY_INTERVAL;
    }
    List<Property> properties = ts.getProperty();
    if (properties != null) {
        for (Property p : properties) {
            if (p.getName().equals(EjbContainerUtil.TIMER_SERVICE_UPGRADED)) {
                // Already set
                return;
            }
        }
    }
    try {
        final String minDelivery = value;
        ConfigSupport.apply(new SingleConfigCode<EjbTimerService>() {

            public Object run(EjbTimerService ts) throws PropertyVetoException, TransactionFailure {
                Property prop = ts.createChild(Property.class);
                ts.getProperty().add(prop);
                prop.setName(EjbContainerUtil.TIMER_SERVICE_UPGRADED);
                prop.setValue("false");
                ts.setMinimumDeliveryIntervalInMillis(minDelivery);
                return null;
            }
        }, ts);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : PropertyVetoException(java.beans.PropertyVetoException) TransactionFailure(org.jvnet.hk2.config.TransactionFailure) Property(org.jvnet.hk2.config.types.Property) EjbTimerService(org.glassfish.ejb.config.EjbTimerService) PropertyVetoException(java.beans.PropertyVetoException)

Example 3 with EjbTimerService

use of org.glassfish.ejb.config.EjbTimerService in project Payara by payara.

the class PersistentEJBTimerService method initEJBTimerService.

static void initEJBTimerService(String target) {
    EJBTimerService timerService = null;
    EjbContainerUtil _ejbContainerUtil = EjbContainerUtilImpl.getInstance();
    EjbTimerService _ejbt = _ejbContainerUtil.getEjbTimerService(target);
    String resourceName = getTimerResource(_ejbt);
    File root = _ejbContainerUtil.getServerContext().getInstallRoot();
    boolean is_upgrade = isUpgrade(resourceName, _ejbt, root);
    File rootScratchDir = _ejbContainerUtil.getServerEnvironment().getApplicationStubPath();
    File appScratchFile = new File(rootScratchDir, TIMER_SERVICE_APP_NAME);
    // Remember the value before the file is created during deploy
    boolean removeOldTimers = is_upgrade && !appScratchFile.exists();
    boolean available = _ejbContainerUtil.getDeployment().isRegistered(TIMER_SERVICE_APP_NAME);
    if (available) {
        logger.log(Level.WARNING, "EJBTimerService had been explicitly deployed.");
    } else {
        if (resourceName != null) {
            available = deployEJBTimerService(root, appScratchFile, resourceName, is_upgrade);
        } else {
            logger.log(Level.WARNING, "Cannot deploy EJBTimerService: Timer resource for target " + target + " is not available");
        }
    }
    if (available) {
        try {
            timerService = new PersistentEJBTimerService("java:global/" + TIMER_SERVICE_APP_NAME + "/" + TIMER_SERVICE_BEAN_NAME, removeOldTimers);
            logger.log(Level.INFO, "ejb.timer_service_started", new Object[] { resourceName });
        } catch (Exception ex) {
            logger.log(Level.WARNING, "ejb.timer_service_init_error", ex);
        }
    }
    EJBTimerService.setPersistentTimerService(timerService);
}
Also used : EjbContainerUtil(com.sun.ejb.containers.EjbContainerUtil) EJBTimerService(com.sun.ejb.containers.EJBTimerService) NonPersistentEJBTimerService(com.sun.ejb.containers.NonPersistentEJBTimerService) NonPersistentEJBTimerService(com.sun.ejb.containers.NonPersistentEJBTimerService) EjbTimerService(org.glassfish.ejb.config.EjbTimerService) File(java.io.File) PropertyVetoException(java.beans.PropertyVetoException) EJBException(javax.ejb.EJBException) FinderException(javax.ejb.FinderException) CreateException(javax.ejb.CreateException)

Example 4 with EjbTimerService

use of org.glassfish.ejb.config.EjbTimerService in project Payara by payara.

the class EJBTimerServiceConfigListener method changed.

/**
 *************************************************************************
 */
/**
 * Implementation of org.jvnet.hk2.config.ConfigListener ********************
 */
/**
 *************************************************************************
 */
public UnprocessedChangeEvents changed(PropertyChangeEvent[] events) {
    // Events that we can't process now because they require server restart.
    List<UnprocessedChangeEvent> unprocessedEvents = new ArrayList<UnprocessedChangeEvent>();
    for (PropertyChangeEvent event : events) {
        if (event.getSource() instanceof EjbTimerService) {
            Object oldValue = event.getOldValue();
            Object newValue = event.getNewValue();
            if (_logger.isLoggable(Level.FINE)) {
                _logger.log(Level.FINE, "Got EjbTimerService change event ==== " + event.getSource() + " " + event.getPropertyName() + " " + oldValue + " " + newValue);
            }
            if (oldValue != null && oldValue.equals(newValue)) {
                if (_logger.isLoggable(Level.FINE)) {
                    _logger.log(Level.FINE, "Event " + event.getPropertyName() + " did not change existing value of " + oldValue);
                }
            } else {
                unprocessedEvents.add(new UnprocessedChangeEvent(event, "Restart required to reconfigure EJB Timer Service"));
            }
        }
    }
    return (unprocessedEvents.size() > 0) ? new UnprocessedChangeEvents(unprocessedEvents) : null;
}
Also used : UnprocessedChangeEvents(org.jvnet.hk2.config.UnprocessedChangeEvents) PropertyChangeEvent(java.beans.PropertyChangeEvent) UnprocessedChangeEvent(org.jvnet.hk2.config.UnprocessedChangeEvent) ArrayList(java.util.ArrayList) EjbTimerService(org.glassfish.ejb.config.EjbTimerService)

Aggregations

EjbTimerService (org.glassfish.ejb.config.EjbTimerService)4 PropertyVetoException (java.beans.PropertyVetoException)2 CreateException (javax.ejb.CreateException)2 EJBException (javax.ejb.EJBException)2 FinderException (javax.ejb.FinderException)2 EJBTimerService (com.sun.ejb.containers.EJBTimerService)1 EjbContainerUtil (com.sun.ejb.containers.EjbContainerUtil)1 NonPersistentEJBTimerService (com.sun.ejb.containers.NonPersistentEJBTimerService)1 PropertyChangeEvent (java.beans.PropertyChangeEvent)1 File (java.io.File)1 ArrayList (java.util.ArrayList)1 EjbContainer (org.glassfish.ejb.config.EjbContainer)1 TransactionFailure (org.jvnet.hk2.config.TransactionFailure)1 UnprocessedChangeEvent (org.jvnet.hk2.config.UnprocessedChangeEvent)1 UnprocessedChangeEvents (org.jvnet.hk2.config.UnprocessedChangeEvents)1 Property (org.jvnet.hk2.config.types.Property)1