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.Endpoint; 020import org.apache.camel.ServiceStatus; 021import org.apache.camel.StatefulService; 022import org.apache.camel.api.management.ManagedInstance; 023import org.apache.camel.api.management.ManagedResource; 024import org.apache.camel.api.management.mbean.ManagedEndpointMBean; 025import org.apache.camel.spi.ManagementStrategy; 026 027@ManagedResource(description = "Managed Endpoint") 028public class ManagedEndpoint implements ManagedInstance, ManagedEndpointMBean { 029 private final Endpoint endpoint; 030 031 public ManagedEndpoint(Endpoint endpoint) { 032 this.endpoint = endpoint; 033 } 034 035 public void init(ManagementStrategy strategy) { 036 // noop 037 } 038 039 public Endpoint getEndpoint() { 040 return endpoint; 041 } 042 043 @Override 044 public String getCamelId() { 045 return endpoint.getCamelContext().getName(); 046 } 047 048 @Override 049 public String getCamelManagementName() { 050 return endpoint.getCamelContext().getManagementName(); 051 } 052 053 @Override 054 public String getEndpointUri() { 055 return endpoint.getEndpointUri(); 056 } 057 058 @Override 059 public boolean isSingleton() { 060 return endpoint.isSingleton(); 061 } 062 063 @Override 064 public String getState() { 065 // must use String type to be sure remote JMX can read the attribute without requiring Camel classes. 066 if (endpoint instanceof StatefulService) { 067 ServiceStatus status = ((StatefulService) endpoint).getStatus(); 068 return status.name(); 069 } 070 071 // assume started if not a ServiceSupport instance 072 return ServiceStatus.Started.name(); 073 } 074 075 @Override 076 public Endpoint getInstance() { 077 return endpoint; 078 } 079 080}