Java 类javax.ejb.TimerHandle 实例源码

项目:Mastering-Java-EE-Development-with-WildFly    文件:TimerBean.java   
public void programmaticTimeout() {
    logger.info("TimerEJB: programmatic timeout occurred");
    timeoutDone = false;
    long duration = 60;
    Timer timer = timerService.createSingleActionTimer(duration, new TimerConfig());
    timer.getInfo();
    try {
        timer.getSchedule();
    } catch (IllegalStateException e) {
        logger.log(SEVERE, "it is not a scheduler", e);
    }
    TimerHandle timerHandle = timer.getHandle();
    timerHandle.getTimer();
    timer.isCalendarTimer();
    timer.isPersistent();
    timer.getTimeRemaining();
}
项目:http-queue    文件:JobManager.java   
public Job createJob(Job job) throws JobAlreadyExistsException {
    if (job.getId() != null && em.find(Job.class, job.getId()) != null) {
        throw new JobAlreadyExistsException();
    }

    ScheduleExpression schedule = new ScheduleExpression();
    schedule.second(job.getSecond());
    schedule.minute(job.getMinute());
    schedule.hour(job.getHour());
    schedule.dayOfMonth(job.getDayOfMonth());
    schedule.dayOfWeek(job.getDayOfWeek());
    schedule.month(job.getMonth());
    schedule.year(job.getYear());

    TimerConfig timerConfig = new TimerConfig(job.getId(), true);
    Timer timer = timerService.createCalendarTimer(schedule, timerConfig);
    TimerHandle timerHandle = timer.getHandle();
    job.serialize(timerHandle);

    logger.info("Timer {} created with cron expression {}. The next timeout is {}.", job.getId(),
            job.getCronExpression(), timer.getNextTimeout());

    if (job.getId() != null) {
        em.merge(job);
    } else {
        em.persist(job);
    }

    return job;
}
项目:http-queue    文件:JobManager.java   
public void removeJob(long jobId) {
    Job job = em.find(Job.class, jobId);
    if (job != null) {
        em.remove(job);
        TimerHandle timerHandle = job.geTimerHandle();
        if (timerHandle != null) {
            timerHandle.getTimer().cancel();
        }
    } else {
        logger.info("Job with id {} not found. Cancelling...", jobId);
    }
}
项目:http-queue    文件:Job.java   
public void serialize(TimerHandle timerHandle) {
    try {
        ByteArrayOutputStream bytes = new ByteArrayOutputStream();
        ObjectOutputStream stream = new ObjectOutputStream(bytes);

        stream.writeObject(timerHandle);

        stream.flush();

        this.timerHandle = new SerialBlob(bytes.toByteArray());
    } catch (SQLException | IOException e) {
        throw new RuntimeException(e);
    }
}
项目:http-queue    文件:Job.java   
public TimerHandle geTimerHandle() {
    try {
        if (timerHandle == null)
            return null;
        ObjectInputStream input = new ObjectInputStream(timerHandle.getBinaryStream());
        return (TimerHandle) input.readObject();
    } catch (ClassNotFoundException | SQLException | IOException e) {
        throw new RuntimeException(e);
    }
}
项目:tomee    文件:TimerImpl.java   
public TimerHandle getHandle() throws IllegalStateException, NoSuchObjectLocalException {
    checkState();
    if (!timerData.isPersistent()) {
        throw new IllegalStateException("can't getHandle for a non-persistent timer");
    }
    return new TimerHandleImpl(timerData.getId(), timerData.getDeploymentId());
}
项目:oscm    文件:EJBTimerStub.java   
@Override
public TimerHandle getHandle() throws IllegalStateException,
        NoSuchObjectLocalException, EJBException {
    throw new UnsupportedOperationException();
}
项目:oscm    文件:TimerStub.java   
@Override
public TimerHandle getHandle() throws EJBException, IllegalStateException,
        NoSuchObjectLocalException {

    return null;
}
项目:cws    文件:SanitizerBeanTest.java   
@Override
public TimerHandle getHandle() throws IllegalStateException, EJBException {
    return null;
}
项目:development    文件:EJBTimerStub.java   
@Override
public TimerHandle getHandle() throws IllegalStateException,
        NoSuchObjectLocalException, EJBException {
    throw new UnsupportedOperationException();
}
项目:development    文件:TimerStub.java   
@Override
public TimerHandle getHandle() throws EJBException, IllegalStateException,
        NoSuchObjectLocalException {

    return null;
}
项目:lightmare    文件:TimerImpl.java   
@Override
public TimerHandle getHandle() throws IllegalStateException, NoSuchObjectLocalException, EJBException {
    return handle;
}