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; 018 019import java.text.DateFormat; 020import java.text.SimpleDateFormat; 021import java.util.Date; 022import org.apache.kahadb.util.ByteSequence; 023 024 025public class JobImpl implements Job { 026 private final JobLocation jobLocation; 027 private final byte[] payload; 028 029 protected JobImpl(JobLocation location,ByteSequence bs) { 030 this.jobLocation=location; 031 this.payload = new byte[bs.getLength()]; 032 System.arraycopy(bs.getData(), bs.getOffset(), this.payload, 0, bs.getLength()); 033 } 034 035 public String getJobId() { 036 return this.jobLocation.getJobId(); 037 } 038 039 public byte[] getPayload() { 040 return this.payload; 041 } 042 043 public long getPeriod() { 044 return this.jobLocation.getPeriod(); 045 } 046 047 public int getRepeat() { 048 return this.jobLocation.getRepeat(); 049 } 050 051 public long getStart() { 052 return this.jobLocation.getStartTime(); 053 } 054 055 public long getDelay() { 056 return this.jobLocation.getDelay(); 057 } 058 059 public String getCronEntry() { 060 return this.jobLocation.getCronEntry(); 061 } 062 063 064 065 public String getNextExecutionTime() { 066 return JobImpl.getDateTime(this.jobLocation.getNextTime()); 067 } 068 069 public String getStartTime() { 070 return JobImpl.getDateTime(getStart()); 071 } 072 073 public static long getDataTime(String value) throws Exception { 074 DateFormat dfm = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); 075 076 Date date = dfm.parse(value); 077 return date.getTime(); 078 } 079 080 public static String getDateTime(long value) { 081 DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); 082 Date date = new Date(value); 083 return dateFormat.format(date); 084 } 085 086 087 088 089}