001/* 002 * Copyright 2013 the original author or authors. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * https://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package org.springframework.batch.core.jsr; 017 018import javax.batch.runtime.Metric; 019 020import org.springframework.util.Assert; 021 022/** 023 * Simple implementation of the {@link Metric} interface as required by JSR-352. 024 * 025 * @author Michael Minella 026 * @since 3.0 027 */ 028public class SimpleMetric implements Metric { 029 030 private final MetricType type; 031 private final long value; 032 033 /** 034 * Basic constructor. The attributes are immutable so this class is 035 * thread-safe. 036 * 037 * @param type as defined by JSR-352 038 * @param value the count of the times the related type has occurred. 039 */ 040 public SimpleMetric(MetricType type, long value) { 041 Assert.notNull(type, "A MetricType is required"); 042 043 this.type = type; 044 this.value = value; 045 } 046 047 /* (non-Javadoc) 048 * @see javax.batch.runtime.Metric#getType() 049 */ 050 @Override 051 public MetricType getType() { 052 return type; 053 } 054 055 /* (non-Javadoc) 056 * @see javax.batch.runtime.Metric#getValue() 057 */ 058 @Override 059 public long getValue() { 060 return value; 061 } 062 063}