ServerRegistry.java
001 /*
002  *
003  * Licensed to the Apache Software Foundation (ASF) under one
004  * or more contributor license agreements.  See the NOTICE file
005  * distributed with this work for additional information
006  * regarding copyright ownership.  The ASF licenses this file
007  * to you under the Apache License, Version 2.0 (the
008  * "License"); you may not use this file except in compliance
009  * with the License.  You may obtain a copy of the License at
010  
011  *   http://www.apache.org/licenses/LICENSE-2.0
012  
013  * Unless required by applicable law or agreed to in writing,
014  * software distributed under the License is distributed on an
015  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
016  * KIND, either express or implied.  See the License for the
017  * specific language governing permissions and limitations
018  * under the License.
019  *
020  */
021 package org.apache.qpid.management.ui;
022 
023 
024 import java.util.ArrayList;
025 import java.util.List;
026 import java.util.concurrent.ConcurrentHashMap;
027 import java.util.concurrent.ConcurrentMap;
028 
029 import org.apache.qpid.management.ui.jmx.ClientListener;
030 import org.apache.qpid.management.ui.model.ManagedAttributeModel;
031 import org.apache.qpid.management.ui.model.NotificationObject;
032 import org.apache.qpid.management.ui.model.OperationDataModel;
033 
034 public abstract class ServerRegistry
035 {
036     private ManagedServer _managedServer = null;
037     
038     // list of virtual hosts for this server
039     private List<String> _virtualHosts = new ArrayList<String>();
040     // map of all Connection mbeans
041     private ConcurrentMap<String,List<ManagedBean>> _connections = new ConcurrentHashMap<String,List<ManagedBean>>();
042     // map of all exchange mbeans
043     private ConcurrentMap<String,List<ManagedBean>> _exchanges = new ConcurrentHashMap<String,List<ManagedBean>>();
044     // map of all queue mbenas
045     private ConcurrentMap<String,List<ManagedBean>> _queues = new ConcurrentHashMap<String,List<ManagedBean>>();
046     
047     public ServerRegistry()
048     {
049         
050     }
051     
052     public ServerRegistry(ManagedServer server)
053     {
054         _managedServer = server;
055     }
056     
057     public ManagedServer getManagedServer()
058     {
059         return _managedServer;
060     }
061 
062     public void setManagedServer(ManagedServer server)
063     {
064         _managedServer = server;
065     }
066     
067     protected void addConnectionMBean(ManagedBean mbean)
068     {
069         String vHost = mbean.getVirtualHostName();
070         _connections.putIfAbsent(vHost, new ArrayList<ManagedBean>());
071         _connections.get(vHost).add(mbean);
072     }
073     
074     protected void addExchangeMBean(ManagedBean mbean)
075     {
076         String vHost = mbean.getVirtualHostName();
077         _exchanges.putIfAbsent(vHost, new ArrayList<ManagedBean>());
078         _exchanges.get(vHost).add(mbean);
079     }
080     
081     protected void addQueueMBean(ManagedBean mbean)
082     {
083         String vHost = mbean.getVirtualHostName();
084         _queues.putIfAbsent(vHost, new ArrayList<ManagedBean>());
085         _queues.get(vHost).add(mbean);
086     }
087     
088     protected void removeConnectionMBean(ManagedBean mbean)
089     {
090         _connections.get(mbean.getVirtualHostName()).remove(mbean);
091     }
092     
093     protected void removeExchangeMBean(ManagedBean mbean)
094     {
095         _exchanges.get(mbean.getVirtualHostName()).remove(mbean);
096     }
097     
098     protected void removeQueueMBean(ManagedBean mbean)
099     {
100         _queues.get(mbean.getVirtualHostName()).remove(mbean);
101     }
102     
103     public List<ManagedBean> getConnections(String virtualHost)
104     {
105         return _connections.get(virtualHost);
106     }
107     
108     public List<ManagedBean> getExchanges(String virtualHost)
109     {
110         return _exchanges.get(virtualHost);
111     }
112     
113     public List<ManagedBean> getQueues(String virtualHost)
114     {
115         return _queues.get(virtualHost);
116     }
117     
118     public void addVirtualHost(String name)
119     {
120         if (!_virtualHosts.contains(name))
121         {
122             _virtualHosts.add(name);
123         }
124     }
125     
126     public List<String> getVirtualHosts()
127     {
128         return _virtualHosts;
129     }
130     
131     public abstract void setUserList(List<String> list);
132     
133     public abstract List<String> getUsernames();
134     
135     public abstract void addManagedObject(ManagedBean key);
136     
137     public abstract List<ManagedBean> getMBeans();
138     
139     public abstract void removeManagedObject(ManagedBean mbean);
140    
141     public abstract List<ManagedBean> getObjectsToBeRemoved();
142     
143     public abstract ManagedAttributeModel getAttributeModel(ManagedBean mbean);
144     
145     public abstract Object getServerConnection();
146     
147     public abstract void closeServerConnection() throws Exception;
148     
149     public abstract OperationDataModel getOperationModel(ManagedBean mbean);
150     
151     public abstract List<String> getQueueNames(String vistualHostName);
152     
153     public abstract String[] getExchangeNames(String vistualHostName);
154     
155     public abstract String[] getConnectionNames(String vistualHostName);
156     
157     public abstract List<NotificationObject> getNotifications(ManagedBean mbean);
158     
159     public abstract boolean hasSubscribedForNotifications(ManagedBean mbean, String name, String type);
160     
161     public abstract void clearNotifications(ManagedBean mbean, List<NotificationObject> list);
162     
163     public ClientListener getNotificationListener()
164     {
165         return null;
166     }
167 
168     public ClientListener getClientListener()
169     {
170         return null;
171     }
172 }