001/* 002 * Copyright (c) 2006-2011 Nuxeo SA (http://nuxeo.com/) and others. 003 * 004 * All rights reserved. This program and the accompanying materials 005 * are made available under the terms of the Eclipse Public License v1.0 006 * which accompanies this distribution, and is available at 007 * http://www.eclipse.org/legal/epl-v10.html 008 * 009 * Contributors: 010 * matic 011 */ 012package org.nuxeo.ecm.core.management.probes; 013 014import java.io.Serializable; 015import java.util.Date; 016 017import org.nuxeo.ecm.core.management.api.ProbeInfo; 018import org.nuxeo.ecm.core.management.api.ProbeMBean; 019import org.nuxeo.ecm.core.management.api.ProbeStatus; 020 021public class ProbeInfoImpl implements ProbeMBean, ProbeInfo, Serializable { 022 023 private static final long serialVersionUID = 1L; 024 025 protected final ProbeDescriptor descriptor; 026 027 protected boolean isEnabled = true; 028 029 protected String shortcutName; 030 031 protected String qualifiedName; 032 033 protected ProbeStatus lastStatus = ProbeStatus.newBlankProbStatus(); 034 035 protected long runnedCount = 0L; 036 037 protected Date lastRunnedDate; 038 039 protected long lastDuration = 0L; 040 041 protected long successCount = 0L; 042 043 protected Date lastSucceedDate = new Date(0); 044 045 protected ProbeStatus lastSuccessStatus = ProbeStatus.newBlankProbStatus(); 046 047 protected long failureCount = 0L; 048 049 protected Date lastFailureDate = new Date(0); 050 051 protected ProbeStatus lastFailureStatus = ProbeStatus.newBlankProbStatus(); 052 053 protected ProbeInfoImpl(ProbeDescriptor descriptor) { 054 this.descriptor = descriptor; 055 shortcutName = descriptor.getShortcut(); 056 qualifiedName = descriptor.getQualifiedName(); 057 } 058 059 @Override 060 public long getFailedCount() { 061 return failureCount; 062 } 063 064 @Override 065 public long getLastDuration() { 066 return lastDuration; 067 } 068 069 @Override 070 public ProbeStatus getLastFailureStatus() { 071 return lastFailureStatus; 072 } 073 074 @Override 075 public Date getLastFailedDate() { 076 return lastFailureDate; 077 } 078 079 @Override 080 public Date getLastRunnedDate() { 081 return lastRunnedDate; 082 } 083 084 @Override 085 public Date getLastSucceedDate() { 086 return lastSucceedDate; 087 } 088 089 @Override 090 public long getRunnedCount() { 091 return runnedCount; 092 } 093 094 @Override 095 public long getSucceedCount() { 096 return successCount; 097 } 098 099 @Override 100 public void disable() { 101 isEnabled = false; 102 } 103 104 @Override 105 public void enable() { 106 isEnabled = true; 107 } 108 109 @Override 110 public boolean isEnabled() { 111 return isEnabled; 112 } 113 114 @Override 115 public boolean isInError() { 116 if (lastFailureDate == null) { 117 return false; 118 } 119 if (lastSucceedDate != null) { 120 return lastFailureDate.after(lastSucceedDate); 121 } 122 return true; 123 } 124 125 @Override 126 public ProbeStatus getStatus() { 127 return lastStatus; 128 } 129 130 @Override 131 public String getShortcutName() { 132 return shortcutName; 133 } 134 135 @Override 136 public ProbeDescriptor getDescriptor() { 137 return descriptor; 138 } 139 140 @Override 141 public String getQualifiedName() { 142 return qualifiedName; 143 } 144 145 public void setQualifiedName(String qualifiedName) { 146 this.qualifiedName = qualifiedName; 147 } 148 149 public void setShortcutName(String shortcutName) { 150 this.shortcutName = shortcutName; 151 } 152 153}