1 17 package org.apache.servicemix.jbi.container; 18 19 import java.io.File ; 20 import java.io.FileOutputStream ; 21 import java.io.IOException ; 22 import java.io.PrintWriter ; 23 24 import org.apache.commons.logging.Log; 25 import org.apache.commons.logging.LogFactory; 26 import org.apache.servicemix.jbi.framework.ComponentMBeanImpl; 27 import org.apache.servicemix.jbi.messaging.MessagingStats; 28 29 34 public class ComponentEnvironment { 35 36 private static final Log log = LogFactory.getLog(ComponentEnvironment.class); 37 38 private File installRoot; 39 private File workspaceRoot; 40 private File componentRoot; 41 private File stateFile; 42 private File statsFile; 43 private PrintWriter statsWriter; 44 private ComponentMBeanImpl localConnector; 45 46 49 public File getInstallRoot() { 50 return installRoot; 51 } 52 53 56 public void setInstallRoot(File installRoot) { 57 this.installRoot = installRoot; 58 } 59 60 63 public File getWorkspaceRoot() { 64 return workspaceRoot; 65 } 66 67 70 public void setWorkspaceRoot(File workspaceRoot) { 71 this.workspaceRoot = workspaceRoot; 72 } 73 74 77 public ComponentMBeanImpl getLocalConnector() { 78 return localConnector; 79 } 80 81 84 public void setLocalConnector(ComponentMBeanImpl localConnector) { 85 this.localConnector = localConnector; 86 } 87 88 91 public File getComponentRoot() { 92 return componentRoot; 93 } 94 95 98 public void setComponentRoot(File componentRoot) { 99 this.componentRoot = componentRoot; 100 } 101 102 105 public File getStateFile() { 106 return stateFile; 107 } 108 109 112 public void setStateFile(File stateFile) { 113 this.stateFile = stateFile; 114 } 115 116 119 public synchronized void close() { 120 if (statsWriter != null) { 121 statsWriter.close(); 122 } 123 } 124 125 128 public synchronized void dumpStats() { 129 if (componentRoot != null && componentRoot.exists()) { 130 try { 131 if (statsWriter == null && statsFile != null) { 132 FileOutputStream fileOut = new FileOutputStream (statsFile); 133 statsWriter = new PrintWriter (fileOut, true); 134 statsWriter.println(localConnector.getComponentNameSpace().getName() + ":"); 135 statsWriter.println("inboundExchanges,inboundExchangeRate,outboundExchanges,outboundExchangeRate"); 136 } 137 MessagingStats stats = localConnector.getMessagingStats(); 138 long inbound = stats.getInboundExchanges().getCount(); 139 double inboundRate = stats.getInboundExchangeRate().getAveragePerSecond(); 140 long outbound = stats.getOutboundExchanges().getCount(); 141 double outboundRate = stats.getOutboundExchangeRate().getAveragePerSecond(); 142 statsWriter.println(inbound + "," + inboundRate + "," + outbound + "," + outboundRate); 143 } 144 catch (IOException e) { 145 log.warn("Failed to dump stats", e); 146 } 147 } 148 } 149 150 153 public File getStatsFile() { 154 return statsFile; 155 } 156 157 160 public void setStatsFile(File statsFile) { 161 this.statsFile = statsFile; 162 } 163 164 } 165 | Popular Tags |