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 */
017 package org.apache.camel.management.mbean;
018
019 import org.apache.camel.Endpoint;
020 import org.apache.camel.ServiceStatus;
021 import org.apache.camel.StatefulService;
022 import org.apache.camel.api.management.ManagedInstance;
023 import org.apache.camel.api.management.ManagedResource;
024 import org.apache.camel.api.management.mbean.ManagedEndpointMBean;
025 import org.apache.camel.spi.ManagementStrategy;
026
027 @ManagedResource(description = "Managed Endpoint")
028 public 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 // do nothing
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 getEndpointUri() {
050 return endpoint.getEndpointUri();
051 }
052
053 @Override
054 public boolean isSingleton() {
055 return endpoint.isSingleton();
056 }
057
058 @Override
059 public String getState() {
060 // must use String type to be sure remote JMX can read the attribute without requiring Camel classes.
061 if (endpoint instanceof StatefulService) {
062 ServiceStatus status = ((StatefulService) endpoint).getStatus();
063 return status.name();
064 }
065
066 // assume started if not a ServiceSupport instance
067 return ServiceStatus.Started.name();
068 }
069
070 @Override
071 public Endpoint getInstance() {
072 return endpoint;
073 }
074
075 }