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.Component;
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.ManagedComponentMBean;
025 import org.apache.camel.spi.ManagementStrategy;
026
027 /**
028 * @version
029 */
030 @ManagedResource(description = "Managed Component")
031 public class ManagedComponent implements ManagedInstance, ManagedComponentMBean {
032 private final Component component;
033 private final String name;
034
035 public ManagedComponent(String name, Component component) {
036 this.name = name;
037 this.component = component;
038 }
039
040 public void init(ManagementStrategy strategy) {
041 // do nothing
042 }
043
044 public Component getComponent() {
045 return component;
046 }
047
048 public String getComponentName() {
049 return name;
050 }
051
052 public String getState() {
053 // must use String type to be sure remote JMX can read the attribute without requiring Camel classes.
054 if (component instanceof StatefulService) {
055 ServiceStatus status = ((StatefulService) component).getStatus();
056 return status.name();
057 }
058
059 // assume started if not a ServiceSupport instance
060 return ServiceStatus.Started.name();
061 }
062
063 public String getCamelId() {
064 return component.getCamelContext().getName();
065 }
066
067 public Object getInstance() {
068 return component;
069 }
070 }