Package systeminformationmonitor.system

Source Code of systeminformationmonitor.system.TCPStat

/*
*  Copyright 2009 Leo Xu.
*
*  Licensed under the Apache License, Version 2.0 (the "License");
*  you may not use this file except in compliance with the License.
*  You may obtain a copy of the License at
*
*       http://www.apache.org/licenses/LICENSE-2.0
*
*  Unless required by applicable law or agreed to in writing, software
*  distributed under the License is distributed on an "AS IS" BASIS,
*  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*  See the License for the specific language governing permissions and
*  limitations under the License.
*  under the License.
*/
package systeminformationmonitor.system;

import java.util.logging.Level;
import java.util.logging.Logger;
import org.hyperic.sigar.SigarException;
import org.hyperic.sigar.Tcp;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.plot.CategoryPlot;
import systeminformationmonitor.SystemInformationMonitorApp;
import systeminformationmonitor.swing.model.TCPConnectionModel;
import systeminformationmonitor.swing.model.TCPSegmentModel;
import systeminformationmonitor.system.object.TCPStatObject;

/**
* TCPStat class generates all TCP related information.
* @author Leo Xu
*/
public class TCPStat extends AbstractSystemUpdater {

    public TCPStat() {
        super();
    }

    @Override
    public void prepare() {
    }

    @Override
    public void update() {
        TCPStatObject tcpObj = getTCPStat();
        threadLock.lock()// block until condition holds
        try {
            ChartPanel chart = (ChartPanel) SystemInformationMonitorApp.getApplication().getView().getTcpJPanel();
            CategoryPlot plot = (CategoryPlot) chart.getChart().getPlot();
            TCPSegmentModel model = (TCPSegmentModel) plot.getDataset();
            model.update(tcpObj);

            ChartPanel connectChart = (ChartPanel) SystemInformationMonitorApp.getApplication().getView().getConnectionJPanel();
            CategoryPlot connectPlot = (CategoryPlot) connectChart.getChart().getPlot();
            TCPConnectionModel connectModel = (TCPConnectionModel) connectPlot.getDataset();
            connectModel.update(tcpObj);

        } finally {
            threadLock.unlock();
        }
    }

    private TCPStatObject getTCPStat() {
        TCPStatObject tcpObj = new TCPStatObject();
        try {
            Tcp stat = sigar.getTcp();
            tcpObj.setActiveOpens(stat.getActiveOpens());
            tcpObj.setPassiveOpens(stat.getPassiveOpens());
            tcpObj.setAttemptFails(stat.getAttemptFails());
            tcpObj.setEstabResets(stat.getEstabResets());
            tcpObj.setCurrentEstab(stat.getCurrEstab());
            tcpObj.setInSegs(stat.getInSegs());
            tcpObj.setOutSegs(stat.getOutSegs());
            tcpObj.setRetransSegs(stat.getRetransSegs());
            tcpObj.setInErrs(stat.getInErrs());
            tcpObj.setOutRsts(stat.getOutRsts());
        } catch (SigarException ex) {
            Logger.getLogger(NetStat.class.getName()).log(Level.SEVERE, null, ex);
        }

        return tcpObj;
    }
}
TOP

Related Classes of systeminformationmonitor.system.TCPStat

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.