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