Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
package net.welen.jmole.protocols;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.logging.Level;
import javax.management.AttributeNotFoundException;
import javax.management.InstanceNotFoundException;
import javax.management.MBeanException;
import javax.management.ReflectionException;
import net.welen.jmole.JMole;
import net.welen.jmole.presentation.PresentationInformation;
/*
* #%L
* JMole, https://bitbucket.org/awelen/jmole
* %%
* Copyright (C) 2015 - 2019 Anders Welén, [email protected]
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Lesser Public License for more details.
*
* You should have received a copy of the GNU General Lesser Public
* License along with this program. If not, see
* .
* #L%
*/
abstract public class AbstractIntervalProtocol implements Protocol, Runnable {
private final static java.util.logging.Logger LOG = java.util.logging.Logger.getLogger(AbstractIntervalProtocol.class.getName());
private static final char SEP = '/';
private Long interval;
private JMole jmole;
private Thread collector;
private boolean stopRequested = false;
private boolean threadStopped = false;
@Override
public void startProtocol(JMole jmole) throws Exception {
this.jmole = jmole;
interval = getInterval();
if (interval == null) {
interval = 60000L;
}
collector = new Thread(this);
collector.setName("JMole protocol thread");
collector.start();
LOG.log(Level.FINE, "JMole protocol thread started: Interval=" + interval);
}
@Override
public void stopProtocol() throws Exception {
LOG.log(Level.FINE, "Stopping protocol thread");
stopRequested = true;
collector.interrupt();
while (!threadStopped) {
try {
Thread.sleep(500);
} catch (InterruptedException e) {
LOG.log(Level.FINE, e.getMessage(), e);
}
}
LOG.log(Level.FINE, "Protocol thread stopped");
}
@Override
public void run() {
stopRequested = false;
threadStopped = false;
try {
while (!stopRequested) {
try {
Thread.sleep(interval);
} catch (InterruptedException e) {
LOG.log(Level.FINE, e.getMessage(), e);
}
if (stopRequested) {
return;
}
try {
handleMeasurements();
} catch (Exception e) {
LOG.log(Level.SEVERE, e.getMessage(), e);
}
try {
handleWarnings();
} catch (Exception e) {
LOG.log(Level.SEVERE, e.getMessage(), e);
}
try {
handleCriticals();
} catch (Exception e) {
LOG.log(Level.SEVERE, e.getMessage(), e);
}
}
} finally {
threadStopped = true;
}
}
private void handleMeasurements()
throws InstanceNotFoundException, AttributeNotFoundException, ReflectionException, MBeanException {
Map