View Javadoc
1   /*
2    * Copyright 2011 the original author or authors.
3    * 
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *     
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.openehealth.ipf.platform.camel.core.management;
17  
18  import javax.management.MalformedObjectNameException;
19  import javax.management.ObjectName;
20  
21  import org.apache.camel.CamelContext;
22  import org.apache.camel.Processor;
23  import org.apache.camel.management.DefaultManagementNamingStrategy;
24  import org.apache.camel.model.ProcessorDefinition;
25  import org.apache.camel.model.ProcessorDefinitionHelper;
26  import org.apache.camel.model.RouteDefinition;
27  
28  /**
29   * @author Reinhard Luft
30   */
31  public class ProcessorManagementNamingStrategy extends
32          DefaultManagementNamingStrategy {
33  
34      public static final String KEY_ROUTE = "route";
35  
36      public ObjectName getObjectNameForProcessor(CamelContext context,
37              Processor processor, ProcessorDefinition<?> definition)
38              throws MalformedObjectNameException {
39  
40          StringBuilder buffer = new StringBuilder();
41          buffer.append(domainName).append(":");
42          buffer.append(KEY_CONTEXT + "=").append(getContextId(context)).append(",");
43          buffer.append(KEY_TYPE + "=").append(TYPE_PROCESSOR).append(",");
44  
45          RouteDefinition route = ProcessorDefinitionHelper.getRoute(definition);
46  
47          if (route != null) {
48              buffer.append(KEY_ROUTE + "=").append(route.getId()).append(",");
49          }
50  
51          buffer.append(KEY_NAME + "=").append(ObjectName.quote(definition.getId()));
52          return createObjectName(buffer);
53      }
54  
55  }