Package org.ejbca.core.model.services

Examples of org.ejbca.core.model.services.IWorker


            if (htp == null) {
                throw new FinderException("Cannot find service " + name);
            }
            ServiceConfiguration serviceConfiguration = htp.getServiceConfiguration();
            if (isAuthorizedToEditService(admin, serviceConfiguration)) {
                IWorker worker = getWorker(serviceConfiguration, name, htp.getRunTimeStamp(), htp.getNextRunTimeStamp());
                if (worker != null) {
                    serviceSession.cancelTimer(htp.getId());
                }
                serviceDataSession.removeServiceData(htp.getId());
                logSession.log(admin, admin.getCaId(), LogConstants.MODULE_SERVICES, new java.util.Date(), null, null,
View Full Code Here


        }
        ServiceData htp = serviceDataSession.findByName(name);
        if (htp != null) {
            ServiceConfiguration serviceConfiguration = htp.getServiceConfiguration();
            if (isAuthorizedToEditService(admin, serviceConfiguration)) {
                IWorker worker = getWorker(serviceConfiguration, name, htp.getRunTimeStamp(), htp.getNextRunTimeStamp());
                if (worker != null) {
                    serviceSession.cancelTimer(htp.getId());
                    if (serviceConfiguration.isActive() && worker.getNextInterval() != IInterval.DONT_EXECUTE) {
                        addTimer(worker.getNextInterval() * 1000, htp.getId());
                    }
                }
            } else {
                logSession.log(admin, admin.getCaId(), LogConstants.MODULE_SERVICES, new Date(), null, null, LogConstants.EVENT_ERROR_NOTAUTHORIZEDTORESOURCE,
                        intres.getLocalizedMessage("services.notauthorizedtoedit", name));
View Full Code Here

                    }
                    // Unexpected error (probably database related). We need to reschedule the service w a default interval..
                    addTimer(30 * 1000, timerInfo);
              }
              // Reschedule timer
                IWorker worker = null;
              if (serviceInterval != IInterval.DONT_EXECUTE) {
                  Timer nextTrigger = addTimer(serviceInterval * 1000, timerInfo);
                  try {
                      // Try to acquire lock / see if this node should run
                      worker = serviceSession.getWorkerIfItShouldRun(timerInfo, nextTrigger.getNextTimeout().getTime());
View Full Code Here

    }
   
    @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
    @Override
    public IWorker getWorkerIfItShouldRun(Integer serviceId, long nextTimeout) {
      IWorker worker = null;
        ServiceData serviceData = serviceDataSession.findById(serviceId);
        ServiceConfiguration serviceConfiguration = serviceData.getServiceConfiguration();
        if (!serviceConfiguration.isActive()) {
            if (log.isDebugEnabled()) {
              log.debug("Service " + serviceId + " is inactive.");
            }
          return null// Don't return an inactive worker to run
        }
        String serviceName = serviceData.getName();
        final String hostname = getHostName();
        if (shouldRunOnThisNode(hostname, Arrays.asList(serviceConfiguration.getPinToNodes()))) {
          long oldRunTimeStamp = serviceData.getRunTimeStamp();
          long oldNextRunTimeStamp = serviceData.getNextRunTimeStamp();
          worker = getWorker(serviceConfiguration, serviceName, oldRunTimeStamp, oldNextRunTimeStamp);
          if (worker.getNextInterval() == IInterval.DONT_EXECUTE) {
              if (log.isDebugEnabled()) {
                log.debug("Service has interval IInterval.DONT_EXECUTE.");
              }
            return null// Don't return an inactive worker to run
          }
View Full Code Here

            Integer id = iter2.next();
            ServiceData htp = serviceDataSession.findById(id);
            if (htp != null) {
                if (!existingTimers.contains(id)) {
                  ServiceConfiguration serviceConfiguration = htp.getServiceConfiguration();
                    IWorker worker = getWorker(serviceConfiguration, idToNameMap.get(id), htp.getRunTimeStamp(), htp.getNextRunTimeStamp());
                    if (worker != null && serviceConfiguration.isActive() && worker.getNextInterval() != IInterval.DONT_EXECUTE) {
                      ret.put(id, Long.valueOf((worker.getNextInterval()) * 1000));
                    }
                }             
            } else {
          // Service does not exist, strange, but no panic.
          log.debug("Can not find service with id "+id);
View Full Code Here

     * @param runTimeStamp the time this service runs
     * @param nextRunTimeStamp the time this service will run next time
     * @return a worker object or null if the worker is misconfigured.
     */
    private IWorker getWorker(ServiceConfiguration serviceConfiguration, String serviceName, long runTimeStamp, long nextRunTimeStamp) {
        IWorker worker = null;
        try {
            String clazz = serviceConfiguration.getWorkerClassPath();
            if (StringUtils.isNotEmpty(clazz)) {
                worker = (IWorker) Thread.currentThread().getContextClassLoader().loadClass(clazz).newInstance();
                worker.init(intAdmin, serviceConfiguration, serviceName, runTimeStamp, nextRunTimeStamp);
            } else {
                log.info("Worker has empty classpath for service " + serviceName);
            }
        } catch (Exception e) {
            // Only display a real error if it is a worker that we are actually
View Full Code Here

      long ret = IInterval.DONT_EXECUTE;
        ServiceData htp = serviceDataSession.findById(serviceId);
        if (htp != null) {
          ServiceConfiguration serviceConfiguration = htp.getServiceConfiguration();
            if (serviceConfiguration.isActive()) {
                IWorker worker = getWorker(serviceConfiguration, "temp", 0, 0)// A bit dirty, but it works..
                if (worker!=null) {
                    ret = worker.getNextInterval();
                }
            } else {
                if (log.isDebugEnabled()) {
                  log.debug("Service " + serviceId + " is inactive.");
                }
View Full Code Here

TOP

Related Classes of org.ejbca.core.model.services.IWorker

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.