1 12 13 package org.ejtools.jmx.browser.model.connector; 14 15 16 17 import javax.management.MBeanServer ; 18 19 20 21 import org.ejtools.jmx.browser.model.service.ConnectionService; 22 23 import org.ejtools.util.service.Profile; 24 25 26 27 40 41 public abstract class AbstractConnectionService implements ConnectionService 42 43 { 44 45 46 47 protected boolean connected = false; 48 49 50 51 protected Profile profile = null; 52 53 54 55 protected MBeanServer server = null; 56 57 58 59 60 61 62 63 protected AbstractConnectionService() { } 64 65 66 67 68 69 78 79 public void connect(Profile profile) 80 81 { 82 83 this.profile = profile; 84 85 try 86 87 { 88 89 this.createMBeanServer(); 90 91 this.setConnected(true); 92 93 } 94 95 catch (Exception e) 96 97 { 98 99 e.printStackTrace(); 100 101 this.setConnected(false); 102 103 } 104 105 } 106 107 108 109 110 111 112 113 public void disconnect() { } 114 115 116 117 118 119 128 129 public MBeanServer getMBeanServer() 130 131 { 132 133 if (!this.connected) 134 135 { 136 137 throw new IllegalStateException ("The service is not connected. Call 'connect' method before."); 138 139 } 140 141 if (this.server == null) 142 143 { 144 145 throw new IllegalStateException ("The server is null. Call 'connect' method before."); 146 147 } 148 149 return this.server; 150 151 } 152 153 154 155 156 157 166 167 public boolean isConnected() 168 169 { 170 171 return this.connected; 172 173 } 174 175 176 177 178 179 188 189 public void setConnected(boolean connected) 190 191 { 192 193 this.connected = connected; 194 195 } 196 197 198 199 200 201 210 211 protected abstract void createMBeanServer() 212 213 throws Exception ; 214 215 216 217 218 219 228 229 protected void setMBeanServer(MBeanServer server) 230 231 { 232 233 this.server = server; 234 235 } 236 237 } 238 239 | Popular Tags |