001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one
003: * or more contributor license agreements. See the NOTICE file
004: * distributed with this work for additional information
005: * regarding copyright ownership. The ASF licenses this file
006: * to you under the Apache License, Version 2.0 (the
007: * "License"); you may not use this file except in compliance
008: * with the License. You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing,
013: * software distributed under the License is distributed on an
014: * * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015: * KIND, either express or implied. See the License for the
016: * specific language governing permissions and limitations
017: * under the License.
018: */
019:
020: package org.apache.synapse.transport.base;
021:
022: import org.apache.commons.logging.Log;
023: import org.apache.commons.logging.LogFactory;
024: import org.apache.axis2.transport.TransportListener;
025: import org.apache.axis2.transport.TransportSender;
026:
027: public class TransportView implements TransportViewMBean {
028:
029: private static final Log log = LogFactory
030: .getLog(TransportView.class);
031:
032: public static final int STOPPED = 0;
033: public static final int RUNNING = 1;
034: public static final int PAUSED = 2;
035: public static final int SHUTTING_DOWN = 3;
036:
037: private TransportListener listener = null;
038: private TransportSender sender = null;
039:
040: public TransportView(TransportListener listener,
041: TransportSender sender) {
042: this .listener = listener;
043: this .sender = sender;
044: }
045:
046: // JMX Attributes
047: public long getMessagesReceived() {
048: if (listener instanceof ManagementSupport) {
049: return ((ManagementSupport) listener).getMessagesReceived();
050: }
051: return -1;
052: }
053:
054: public long getFaultsReceiving() {
055: if (listener instanceof ManagementSupport) {
056: return ((ManagementSupport) listener).getFaultsReceiving();
057: }
058: return -1;
059: }
060:
061: public long getBytesReceived() {
062: if (listener instanceof ManagementSupport) {
063: return ((ManagementSupport) listener).getBytesReceived();
064: }
065: return -1;
066: }
067:
068: public long getMessagesSent() {
069: if (sender instanceof ManagementSupport) {
070: return ((ManagementSupport) sender).getMessagesSent();
071: }
072: return -1;
073: }
074:
075: public long getFaultsSending() {
076: if (sender instanceof ManagementSupport) {
077: return ((ManagementSupport) sender).getFaultsSending();
078: }
079: return -1;
080: }
081:
082: public long getBytesSent() {
083: if (sender instanceof ManagementSupport) {
084: return ((ManagementSupport) sender).getBytesSent();
085: }
086: return -1;
087: }
088:
089: // JMX Operations
090: public void start() throws Exception {
091: listener.start();
092: }
093:
094: public void stop() throws Exception {
095: listener.stop();
096: }
097:
098: public void pause() throws Exception {
099: if (listener instanceof ManagementSupport) {
100: ((ManagementSupport) listener).pause();
101: }
102: }
103:
104: public void resume() throws Exception {
105: if (listener instanceof ManagementSupport) {
106: ((ManagementSupport) listener).resume();
107: }
108: }
109:
110: public void maintenenceShutdown(long seconds) throws Exception {
111: if (listener instanceof ManagementSupport) {
112: ((ManagementSupport) listener)
113: .maintenenceShutdown(seconds * 1000);
114: }
115: }
116:
117: public void resetStatistics() {
118: log.info("Operation not supported over JMX");
119: }
120: }
|