KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > admin > dottedname > DottedNameServerInfoCache


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23  
24 /*
25  * $Header: /cvs/glassfish/admin/mbeans/src/java/com/sun/enterprise/admin/dottedname/DottedNameServerInfoCache.java,v 1.3 2005/12/25 03:42:04 tcfujii Exp $
26  * $Revision: 1.3 $
27  * $Date: 2005/12/25 03:42:04 $
28  */

29 package com.sun.enterprise.admin.dottedname;
30
31 import java.util.HashMap JavaDoc;
32 import java.util.Set JavaDoc;
33 import java.util.Iterator JavaDoc;
34 import java.util.Collections JavaDoc;
35
36 import javax.management.ObjectName JavaDoc;
37
38 /*
39     This class maintains a cache of the current server info as an optimization.
40     
41     The user should call refresh() prior to first use, and when wishing to get
42     the current state.
43     
44  */

45 public class DottedNameServerInfoCache implements DottedNameServerInfo
46 {
47     final DottedNameServerInfo mSrc;
48     
49     Set JavaDoc mConfigNames;
50     Set JavaDoc mServerNames;
51     HashMap JavaDoc mServerToConfig;
52     HashMap JavaDoc mConfigToServers;
53     
54         public
55     DottedNameServerInfoCache( final DottedNameServerInfo src )
56     {
57         mSrc = src;
58         
59         // underlying source may or may not be ready yet, so it's up
60
// to the caller to call refresh() before first use.
61
mConfigNames = Collections.EMPTY_SET;
62         mServerNames = Collections.EMPTY_SET;
63         mServerToConfig = mConfigToServers = new HashMap JavaDoc();
64     }
65     
66         public synchronized Set JavaDoc
67     getConfigNames()
68         throws DottedNameServerInfo.UnavailableException
69     {
70         return( mConfigNames );
71     }
72     
73         public synchronized Set JavaDoc
74     getServerNames()
75         throws DottedNameServerInfo.UnavailableException
76     {
77         return( mServerNames );
78     }
79     
80         public synchronized String JavaDoc
81     getConfigNameForServer( String JavaDoc serverName )
82         throws DottedNameServerInfo.UnavailableException
83     {
84         return( (String JavaDoc)mServerToConfig.get( serverName ) );
85     }
86     
87         public synchronized String JavaDoc []
88     getServerNamesForConfig( String JavaDoc configName )
89         throws DottedNameServerInfo.UnavailableException
90     {
91         return( (String JavaDoc [])mConfigToServers.get( configName ) );
92     }
93     
94         void
95     _refresh()
96         throws DottedNameServerInfo.UnavailableException
97     {
98         mConfigNames = mSrc.getConfigNames();
99         mServerNames = mSrc.getServerNames();
100         
101         // create mapping from server to config
102
Iterator JavaDoc iter = mServerNames.iterator();
103         while ( iter.hasNext() )
104         {
105             final String JavaDoc serverName = (String JavaDoc)iter.next();
106             
107             final String JavaDoc configName = mSrc.getConfigNameForServer( serverName );
108             
109             if ( configName != null )
110             {
111                 mServerToConfig.put( serverName, configName );
112             }
113         }
114         
115         // create mapping from config to servers
116
iter = mConfigNames.iterator();
117         while ( iter.hasNext() )
118         {
119             final String JavaDoc configName = (String JavaDoc)iter.next();
120             
121             final String JavaDoc [] serverNames = mSrc.getServerNamesForConfig( configName );
122             
123             if ( serverNames != null )
124             {
125                 mConfigToServers.put( configName, serverNames );
126             }
127         }
128     }
129     
130         public synchronized void
131     refresh()
132     {
133         try
134         {
135             _refresh();
136         }
137         catch( DottedNameServerInfo.UnavailableException e )
138         {
139             DottedNameLogger.logException( e );
140         }
141     }
142 }
143
144
145
146
147
148
149
150
151
152
Popular Tags