KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > servicemix > jbi > container > ComponentEnvironment


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17 package org.apache.servicemix.jbi.container;
18
19 import java.io.File JavaDoc;
20 import java.io.FileOutputStream JavaDoc;
21 import java.io.IOException JavaDoc;
22 import java.io.PrintWriter JavaDoc;
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 /**
30  * Holder for environment infomation
31  *
32  * @version $Revision: 426415 $
33  */

34 public class ComponentEnvironment {
35     
36     private static final Log log = LogFactory.getLog(ComponentEnvironment.class);
37     
38     private File JavaDoc installRoot;
39     private File JavaDoc workspaceRoot;
40     private File JavaDoc componentRoot;
41     private File JavaDoc stateFile;
42     private File JavaDoc statsFile;
43     private PrintWriter JavaDoc statsWriter;
44     private ComponentMBeanImpl localConnector;
45
46     /**
47      * @return Returns the installRoot.
48      */

49     public File JavaDoc getInstallRoot() {
50         return installRoot;
51     }
52
53     /**
54      * @param installRoot The installRoot to set.
55      */

56     public void setInstallRoot(File JavaDoc installRoot) {
57         this.installRoot = installRoot;
58     }
59
60     /**
61      * @return Returns the workspaceRoot.
62      */

63     public File JavaDoc getWorkspaceRoot() {
64         return workspaceRoot;
65     }
66
67     /**
68      * @param workspaceRoot The workspaceRoot to set.
69      */

70     public void setWorkspaceRoot(File JavaDoc workspaceRoot) {
71         this.workspaceRoot = workspaceRoot;
72     }
73
74     /**
75      * @return Returns the localConnector.
76      */

77     public ComponentMBeanImpl getLocalConnector() {
78         return localConnector;
79     }
80
81     /**
82      * @param localConnector The localConnector to set.
83      */

84     public void setLocalConnector(ComponentMBeanImpl localConnector) {
85         this.localConnector = localConnector;
86     }
87
88     /**
89      * @return Returns the componentRoot.
90      */

91     public File JavaDoc getComponentRoot() {
92         return componentRoot;
93     }
94
95     /**
96      * @param componentRoot The componentRoot to set.
97      */

98     public void setComponentRoot(File JavaDoc componentRoot) {
99         this.componentRoot = componentRoot;
100     }
101
102     /**
103      * @return Returns the stateFile.
104      */

105     public File JavaDoc getStateFile() {
106         return stateFile;
107     }
108
109     /**
110      * @param stateFile The stateFile to set.
111      */

112     public void setStateFile(File JavaDoc stateFile) {
113         this.stateFile = stateFile;
114     }
115     
116     /**
117      * close this environment
118      */

119     public synchronized void close() {
120         if (statsWriter != null) {
121             statsWriter.close();
122         }
123     }
124
125     /**
126      * dump stats
127      */

128     public synchronized void dumpStats() {
129         if (componentRoot != null && componentRoot.exists()) {
130             try {
131                 if (statsWriter == null && statsFile != null) {
132                     FileOutputStream JavaDoc fileOut = new FileOutputStream JavaDoc(statsFile);
133                     statsWriter = new PrintWriter JavaDoc(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 JavaDoc e) {
145                 log.warn("Failed to dump stats", e);
146             }
147         }
148     }
149
150     /**
151      * @return Returns the statsFile.
152      */

153     public File JavaDoc getStatsFile() {
154         return statsFile;
155     }
156
157     /**
158      * @param statsFile The statsFile to set.
159      */

160     public void setStatsFile(File JavaDoc statsFile) {
161         this.statsFile = statsFile;
162     }
163
164 }
165
Popular Tags