View Javadoc
1   /*
2    * Copyright 2001-2008 The Apache Software Foundation.
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   */
17  package org.apache.juddi.api.impl;
18  
19  import java.util.HashMap;
20  import java.util.List;
21  import java.util.Map;
22  
23  import org.apache.juddi.api.util.CustodyTransferQuery;
24  import org.apache.juddi.api.util.InquiryQuery;
25  import org.apache.juddi.api.util.JUDDIQuery;
26  import org.apache.juddi.api.util.PublicationQuery;
27  import org.apache.juddi.api.util.ReplicationQuery;
28  import org.apache.juddi.api.util.SecurityQuery;
29  import org.apache.juddi.api.util.SubscriptionListenerQuery;
30  import org.apache.juddi.api.util.SubscriptionQuery;
31  import org.apache.juddi.api.util.ValueSetCachingQuery;
32  import org.apache.juddi.api.util.ValueSetValidationQuery;
33  
34  public class ServiceCounterLifecycleResource {
35      static Map<String, UDDIServiceCounter> serviceCounters = 
36              new HashMap<String, UDDIServiceCounter>();
37      
38      static Map<String, List<String>> implForQuery = new HashMap<String, List<String>>();
39      
40      public static String getObjectName(Class<?> klass) {
41          StringBuffer objectName = new StringBuffer("portType=" + klass.toString());
42          return objectName.toString();
43      }
44      
45      public static synchronized void initQuery() {
46          synchronized (implForQuery) {
47              if (implForQuery.isEmpty()) {
48                  implForQuery = new HashMap<String, List<String>>();
49                  implForQuery.put(UDDICustodyTransferImpl.class.getName(), CustodyTransferQuery.getQueries());
50                  implForQuery.put(UDDIInquiryImpl.class.getName(), InquiryQuery.getQueries());
51                  implForQuery.put(UDDIPublicationImpl.class.getName(), PublicationQuery.getQueries());
52                  implForQuery.put(UDDIReplicationImpl.class.getName(), ReplicationQuery.getQueries());
53                  implForQuery.put(UDDISecurityImpl.class.getName(), SecurityQuery.getQueries());
54                  implForQuery.put(UDDISubscriptionImpl.class.getName(), SubscriptionQuery.getQueries());
55                  implForQuery.put(UDDISubscriptionListenerImpl.class.getName(), SubscriptionListenerQuery.getQueries());
56                  implForQuery.put(UDDIValueSetCachingImpl.class.getName(), ValueSetCachingQuery.getQueries());
57                  implForQuery.put(UDDIValueSetValidationImpl.class.getName(), ValueSetValidationQuery.getQueries());
58                  implForQuery.put(JUDDIApiImpl.class.getName(), JUDDIQuery.getQueries());
59              }
60          }
61      }
62      
63      public static UDDIServiceCounter getServiceCounter(Class<?> klass) { 
64          if (implForQuery.isEmpty()) {
65              initQuery();
66          }
67          
68          String objectName = getObjectName(klass);
69          synchronized (serviceCounters) {
70              UDDIServiceCounter serviceCounter = serviceCounters.get(objectName);
71              if (serviceCounter == null) {
72                  UDDIServiceCounter uddiServiceCounter = new UDDIServiceCounter();
73                  uddiServiceCounter.initList(klass, (List<String>)implForQuery.get(klass.getName()));
74                  uddiServiceCounter.registerMBean();                
75                  serviceCounters.put(objectName, uddiServiceCounter);
76                  return uddiServiceCounter;
77              } else {
78                  return serviceCounter;
79              }
80          }
81      }
82  }