Source Code Cross Referenced for CacheServerMBeanProxyFactory.java in  » Web-Server » xsocket » org » xcache » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Web Server » xsocket » org.xcache 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        // $Id: MultithreadedServerMBeanProxyFactory.java 1386 2007-06-28 11:47:15Z grro $
002:        /*
003:         *  Copyright (c) xsocket.org, 2006 - 2007. All rights reserved.
004:         *
005:         *  This library is free software; you can redistribute it and/or
006:         *  modify it under the terms of the GNU Lesser General Public
007:         *  License as published by the Free Software Foundation; either
008:         *  version 2.1 of the License, or (at your option) any later version.
009:         *
010:         *  This library is distributed in the hope that it will be useful,
011:         *  but WITHOUT ANY WARRANTY; without even the implied warranty of
012:         *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
013:         *  Lesser General Public License for more details.
014:         *
015:         *  You should have received a copy of the GNU Lesser General Public
016:         *  License along with this library; if not, write to the Free Software
017:         *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
018:         *
019:         * Please refer to the LGPL license at: http://www.gnu.org/copyleft/lesser.txt
020:         * The latest copy of this software may be found on http://www.xsocket.org/
021:         */
022:        package org.xcache;
023:
024:        import java.lang.management.ManagementFactory;
025:        import java.util.logging.Level;
026:        import java.util.logging.Logger;
027:
028:        import javax.management.JMException;
029:        import javax.management.MBeanServer;
030:        import javax.management.ObjectName;
031:
032:        import org.xsocket.IntrospectionBasedDynamicBean;
033:        import org.xsocket.stream.IServerListener;
034:        import org.xsocket.stream.ServerMBeanProxyFactory;
035:
036:        /**
037:         * A Mbean proxy factory, which creates and registers an appropriated mbean 
038:         * for a given {@link Server} instance.  
039:         * 
040:         * <br><br><b>This class is for test purpose only, and will be modified or discarded in future versions</b>
041:         * 
042:         * @author grro@xsocket.org
043:         */
044:        public final class CacheServerMBeanProxyFactory {
045:
046:            private static final Logger LOG = Logger
047:                    .getLogger(CacheServerMBeanProxyFactory.class.getName());
048:
049:            /**
050:             * creates and registers a mbean for the given server on the platform MBeanServer
051:             * 
052:             * @param server  the server to register 
053:             * @throws JMException  if an jmx exception occurs
054:             */
055:            public static void createAndRegister(CacheServer server)
056:                    throws JMException {
057:                createAndRegister(server, "org.xcache");
058:            }
059:
060:            /**
061:             * creates and registers a mbean for the given server on the platform MBeanServer 
062:             * under the given domain name 
063:             * 
064:             * @param server   the server to register 
065:             * @param domain   the domain name to use
066:             * @throws JMException  if an jmx exception occurs
067:             */
068:            public static void createAndRegister(CacheServer server,
069:                    String domain) throws JMException {
070:                createAndRegister(ManagementFactory.getPlatformMBeanServer(),
071:                        server, domain);
072:            }
073:
074:            /**
075:             * creates and registers a mbean for the given server on the given MBeanServer
076:             * under the given domain name 
077:             *
078:             * @param mbeanServer  the mbean server to use
079:             * @param server       the server to register 
080:             * @param domain       the domain name to use
081:             * @throws JMException  if an jmx exception occurs 
082:             */
083:            public static void createAndRegister(MBeanServer mbeanServer,
084:                    final CacheServer server, final String domain)
085:                    throws JMException {
086:
087:                ServerMBeanProxyFactory.createAndRegister(server
088:                        .getUnderlyingServer(), domain);
089:
090:                register(server, domain);
091:
092:                server.addListener(new IServerListener() {
093:                    public void onInit() {
094:                    }
095:
096:                    public void onDestroy() {
097:                        try {
098:                            unregister(server, domain);
099:                        } catch (Exception e) {
100:                            if (LOG.isLoggable(Level.FINE)) {
101:                                LOG.fine("couldn't unregister mbean. reason: "
102:                                        + e.toString());
103:                            }
104:                        }
105:                    }
106:                });
107:            }
108:
109:            private static void register(CacheServer server, String domain)
110:                    throws JMException {
111:
112:                ObjectName objectName = new ObjectName(domain
113:                        + ":type=StoreServer,name="
114:                        + server.getLocalAddress().getHostName() + "."
115:                        + server.getLocalPort());
116:
117:                IntrospectionBasedDynamicBean mbean = new IntrospectionBasedDynamicBean(
118:                        server);
119:                ManagementFactory.getPlatformMBeanServer().registerMBean(mbean,
120:                        objectName);
121:
122:                server.addListener(new Listener(server, domain));
123:            }
124:
125:            private static void unregister(CacheServer server, String domain)
126:                    throws JMException {
127:                ObjectName objectName = new ObjectName(domain
128:                        + ":type=StoreServer,name="
129:                        + server.getLocalAddress().getHostName() + "."
130:                        + server.getLocalPort());
131:                ManagementFactory.getPlatformMBeanServer().unregisterMBean(
132:                        objectName);
133:            }
134:
135:            private static final class Listener implements  IServerListener {
136:
137:                private static final Logger LOG = Logger
138:                        .getLogger(Listener.class.getName());
139:
140:                private CacheServer server = null;
141:                private String domain = null;
142:
143:                Listener(CacheServer server, String domain) {
144:                    this .server = server;
145:                    this .domain = domain;
146:
147:                    server.addListener(this );
148:                }
149:
150:                public void onInit() {
151:                }
152:
153:                public void onDestroy() {
154:                    try {
155:                        unregister(server, domain);
156:                    } catch (Exception ex) {
157:                        if (LOG.isLoggable(Level.FINE)) {
158:                            LOG
159:                                    .fine("error occured by deregistering the server (domain="
160:                                            + domain
161:                                            + "). reason: "
162:                                            + ex.toString());
163:                        }
164:                    }
165:                }
166:            }
167:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.