001/** 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017package org.apache.activemq.broker.scheduler.memory; 018 019import org.apache.activemq.broker.scheduler.Job; 020import org.apache.activemq.broker.scheduler.JobSupport; 021 022/** 023 * A simple in memory Job POJO. 024 */ 025public class InMemoryJob implements Job { 026 027 private final String jobId; 028 029 private int repeat; 030 private long start; 031 private long nextTime; 032 private long delay; 033 private long period; 034 private String cronEntry; 035 private int executionCount; 036 037 private byte[] payload; 038 039 public InMemoryJob(String jobId) { 040 this.jobId = jobId; 041 } 042 043 @Override 044 public String getJobId() { 045 return jobId; 046 } 047 048 @Override 049 public int getRepeat() { 050 return repeat; 051 } 052 053 public void setRepeat(int repeat) { 054 this.repeat = repeat; 055 } 056 057 @Override 058 public long getStart() { 059 return start; 060 } 061 062 public void setStart(long start) { 063 this.start = start; 064 } 065 066 public long getNextTime() { 067 return nextTime; 068 } 069 070 public void setNextTime(long nextTime) { 071 this.nextTime = nextTime; 072 } 073 074 @Override 075 public long getDelay() { 076 return delay; 077 } 078 079 public void setDelay(long delay) { 080 this.delay = delay; 081 } 082 083 @Override 084 public long getPeriod() { 085 return period; 086 } 087 088 public void setPeriod(long period) { 089 this.period = period; 090 } 091 092 @Override 093 public String getCronEntry() { 094 return cronEntry; 095 } 096 097 public void setCronEntry(String cronEntry) { 098 this.cronEntry = cronEntry; 099 } 100 101 @Override 102 public byte[] getPayload() { 103 return payload; 104 } 105 106 public void setPayload(byte[] payload) { 107 this.payload = payload; 108 } 109 110 @Override 111 public String getStartTime() { 112 return JobSupport.getDateTime(getStart()); 113 } 114 115 @Override 116 public String getNextExecutionTime() { 117 return JobSupport.getDateTime(getNextTime()); 118 } 119 120 @Override 121 public int getExecutionCount() { 122 return executionCount; 123 } 124 125 public void incrementExecutionCount() { 126 this.executionCount++; 127 } 128 129 public void decrementRepeatCount() { 130 if (this.repeat > 0) { 131 this.repeat--; 132 } 133 } 134 135 /** 136 * @return true if this Job represents a Cron entry. 137 */ 138 public boolean isCron() { 139 return getCronEntry() != null && getCronEntry().length() > 0; 140 } 141 142 @Override 143 public int hashCode() { 144 return jobId.hashCode(); 145 } 146 147 @Override 148 public String toString() { 149 return "Job: " + getJobId(); 150 } 151}