1 23 package com.sun.enterprise.admin.wsmgmt.msg; 24 25 import java.util.Map ; 26 import java.util.List ; 27 import java.util.Hashtable ; 28 import java.util.Collection ; 29 import java.util.ArrayList ; 30 import java.util.Iterator ; 31 import com.sun.enterprise.admin.wsmgmt.config.spi.ConfigFactory; 32 import com.sun.enterprise.admin.wsmgmt.config.spi.ConfigProvider; 33 import com.sun.appserv.management.ext.wsmgmt.MessageTrace; 34 35 import java.util.logging.Logger ; 36 import java.util.logging.Level ; 37 import com.sun.logging.LogDomains; 38 import com.sun.enterprise.util.i18n.StringManager; 39 40 43 public class MessageTraceMgr { 44 45 50 public static MessageTraceMgr getInstance() { 51 if (_instance == null) { 52 _instance = new MessageTraceMgr(); 53 } 54 55 return _instance; 56 } 57 58 61 private MessageTraceMgr() { 62 _applications = new Hashtable (); 63 64 } 65 66 69 public void init() { 70 try { 71 ConfigFactory cf = ConfigFactory.getConfigFactory(); 72 ConfigProvider cp = cf.getConfigProvider(); 73 List list = cp.getManagedWebserviceApplicationIds(); 74 for (Iterator iter=list.iterator(); iter.hasNext();) { 75 String appId = (String ) iter.next(); 76 try { 77 ApplicationMediator am = new ApplicationMediator(appId); 78 _applications.put(appId, am); 79 } catch (MessageTraceException me) { 80 String msg="Initialization error for application: " + appId; 81 _logger.log(Level.FINE, msg, me); 82 } 83 } 84 } catch (Exception e) { 85 String msg="Configuration initialization error."; 86 _logger.log(Level.FINE, msg, e); 87 } 88 } 89 90 99 public void disable(String appId, String endpoint) 100 throws MessageTraceException { 101 102 ApplicationMediator am = (ApplicationMediator) _applications.get(appId); 103 if (am != null) { 104 am.disable(endpoint); 105 if (am.isEmpty()) { 106 _applications.remove(appId); 107 } 108 } else { 109 String msg = _stringMgr.getString("MessageTraceMgr_InvalidAppEx", 110 appId, endpoint); 111 throw new MessageTraceException(msg); 112 } 113 } 114 115 124 public void enable(String appId, String endpoint, int size) 125 throws MessageTraceException { 126 127 ApplicationMediator am = (ApplicationMediator) _applications.get(appId); 128 if (am != null) { 129 am.enable(endpoint, size); 130 } else { 131 am = new ApplicationMediator(appId); 132 am.enable(endpoint, size); 133 _applications.put(appId, am); 134 } 135 } 136 137 147 public void setMessageHistorySize(String appId, String endpoint, int size) 148 throws MessageTraceException { 149 150 ApplicationMediator am = (ApplicationMediator) _applications.get(appId); 151 if (am != null) { 152 am.setMessageHistorySize(endpoint, size); 153 } else { 154 String msg = _stringMgr.getString("MessageTraceMgr_InvalidAppEx", 155 appId, endpoint); 156 throw new MessageTraceException(msg); 157 } 158 } 159 160 163 public void stop() { 164 Collection mediators = _applications.values(); 165 for (Iterator itr=mediators.iterator(); itr.hasNext();) { 166 ApplicationMediator am = (ApplicationMediator) itr.next(); 167 am.destroy(); 168 } 169 _applications.clear(); 170 } 171 172 177 public MessageTrace[] getMessages() { 178 Collection c = new ArrayList (); 179 180 Collection mediators = _applications.values(); 181 for (Iterator itr=mediators.iterator(); itr.hasNext();) { 182 ApplicationMediator am = (ApplicationMediator) itr.next(); 183 c.addAll( am.getMessages() ); 184 } 185 186 MessageTrace[] trace = new MessageTrace[c.size()]; 187 return ((MessageTrace[]) c.toArray(trace)); 188 } 189 190 198 public MessageTrace[] getMessages(String appId, String endpoint) { 199 Collection c = null; 200 ApplicationMediator am = (ApplicationMediator) _applications.get(appId); 201 if (am != null) { 202 c = am.getMessages(endpoint); 203 } 204 MessageTrace[] trace = null; 205 if ( c != null) { 206 trace = new MessageTrace[c.size()]; 207 return ((MessageTrace[]) c.toArray(trace)); 208 } else { 209 return null; 210 } 211 } 212 213 private Map _applications = null; 215 private static MessageTraceMgr _instance = null; 216 private static final Logger _logger = 217 Logger.getLogger(LogDomains.ADMIN_LOGGER); 218 private static final StringManager _stringMgr = 219 StringManager.getManager(MessageTraceMgr.class); 220 221 } 222 | Popular Tags |