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.camel.management.mbean; 018 019import org.apache.camel.CamelContext; 020import org.apache.camel.api.management.ManagedResource; 021import org.apache.camel.api.management.mbean.ManagedThrottlingExceptionRoutePolicyMBean; 022import org.apache.camel.impl.ThrottlingExceptionHalfOpenHandler; 023import org.apache.camel.impl.ThrottlingExceptionRoutePolicy; 024 025@ManagedResource(description = "Managed ThrottlingExceptionRoutePolicy") 026public class ManagedThrottlingExceptionRoutePolicy extends ManagedService implements ManagedThrottlingExceptionRoutePolicyMBean { 027 028 private final ThrottlingExceptionRoutePolicy policy; 029 030 public ManagedThrottlingExceptionRoutePolicy(CamelContext context, ThrottlingExceptionRoutePolicy policy) { 031 super(context, policy); 032 this.policy = policy; 033 } 034 035 public ThrottlingExceptionRoutePolicy getPolicy() { 036 return policy; 037 } 038 039 @Override 040 public Long getHalfOpenAfter() { 041 return getPolicy().getHalfOpenAfter(); 042 } 043 044 @Override 045 public void setHalfOpenAfter(Long milliseconds) { 046 getPolicy().setHalfOpenAfter(milliseconds); 047 } 048 049 @Override 050 public Long getFailureWindow() { 051 return getPolicy().getFailureWindow(); 052 } 053 054 @Override 055 public void setFailureWindow(Long milliseconds) { 056 getPolicy().setFailureWindow(milliseconds); 057 } 058 059 @Override 060 public Integer getFailureThreshold() { 061 return getPolicy().getFailureThreshold(); 062 } 063 064 @Override 065 public void setFailureThreshold(Integer numberOfFailures) { 066 getPolicy().setFailureThreshold(numberOfFailures); 067 } 068 069 @Override 070 public String currentState() { 071 return getPolicy().dumpState(); 072 } 073 074 @Override 075 public String getHalfOpenHandlerName() { 076 ThrottlingExceptionHalfOpenHandler obj = getPolicy().getHalfOpenHandler(); 077 if (obj != null) { 078 return obj.getClass().getSimpleName(); 079 } else { 080 return ""; 081 } 082 } 083 084 @Override 085 public Integer getCurrentFailures() { 086 return getPolicy().getFailures(); 087 } 088 089 @Override 090 public Long getLastFailure() { 091 if (getPolicy().getLastFailure() == 0) { 092 return 0L; 093 } else { 094 return System.currentTimeMillis() - getPolicy().getLastFailure(); 095 } 096 } 097 098 @Override 099 public Long getOpenAt() { 100 if (getPolicy().getOpenedAt() == 0) { 101 return 0L; 102 } else { 103 return System.currentTimeMillis() - getPolicy().getOpenedAt(); 104 } 105 } 106 107}