本文整理匯總了Java中org.javasimon.SimonManager.getCounter方法的典型用法代碼示例。如果您正苦於以下問題:Java SimonManager.getCounter方法的具體用法?Java SimonManager.getCounter怎麽用?Java SimonManager.getCounter使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.javasimon.SimonManager
的用法示例。
在下文中一共展示了SimonManager.getCounter方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: main
import org.javasimon.SimonManager; //導入方法依賴的package包/類
/**
* Entry point to the JMX Callback Example.
*
* @param args unused
* @throws Exception whatever may happen in this crazy world
*/
@SuppressWarnings("InfiniteLoopStatement")
public static void main(String[] args) throws Exception {
SimonManager.callback().addCallback(new JmxRegisterCallback("org.javasimon.examples.jmx.JmxCallbackExample"));
Counter counter = SimonManager.getCounter("org.javasimon.examples.jmx.counter");
Stopwatch stopwatch = SimonManager.getStopwatch("org.javasimon.examples.jmx.stopwatch");
// these created just to have more stuff in jconsole
SimonManager.getCounter("org.javasimon.different.counter");
SimonManager.getStopwatch("org.javasimon.some.other.jmx.stopwatch1");
SimonManager.getStopwatch("org.javasimon.some.other.jmx.stopwatch2");
System.out.println("Now open jconsole and check it out...\nWatch org.javasimon.examples.jmx.stopwatch for changes.");
while (true) {
counter.increase();
try (Split ignored = stopwatch.start()) {
ExampleUtils.waitRandomlySquared(40);
}
}
}
示例2: managerClearTest
import org.javasimon.SimonManager; //導入方法依賴的package包/類
@Test
public void managerClearTest() throws MalformedObjectNameException {
String counterName = "test.1";
ObjectName counterObjectName = new ObjectName(DOMAIN + ":type=" + SimonInfo.COUNTER + ",name=" + counterName);
String stopwatchName = "test.2";
ObjectName stopwatchObjectName = new ObjectName(DOMAIN + ":type=" + SimonInfo.STOPWATCH + ",name=" + stopwatchName);
Assert.assertFalse(mbs.isRegistered(counterObjectName));
Assert.assertFalse(mbs.isRegistered(stopwatchObjectName));
SimonManager.getCounter(counterName);
Assert.assertTrue(mbs.isRegistered(counterObjectName));
SimonManager.getStopwatch(stopwatchName);
Assert.assertTrue(mbs.isRegistered(stopwatchObjectName));
SimonManager.clear();
Assert.assertFalse(mbs.isRegistered(counterObjectName));
Assert.assertFalse(mbs.isRegistered(stopwatchObjectName));
}
示例3: destroySimonTest
import org.javasimon.SimonManager; //導入方法依賴的package包/類
@Test
public void destroySimonTest() throws MalformedObjectNameException {
String counterName = "test.1";
ObjectName counterObjectName = new ObjectName(DOMAIN + ":type=" + SimonInfo.COUNTER + ",name=" + counterName);
String stopwatchName = "test.2";
ObjectName stopwatchObjectName = new ObjectName(DOMAIN + ":type=" + SimonInfo.STOPWATCH + ",name=" + stopwatchName);
Assert.assertFalse(mbs.isRegistered(counterObjectName));
Assert.assertFalse(mbs.isRegistered(stopwatchObjectName));
SimonManager.getCounter(counterName);
Assert.assertTrue(mbs.isRegistered(counterObjectName));
SimonManager.destroySimon(counterName);
Assert.assertFalse(mbs.isRegistered(counterObjectName));
SimonManager.getStopwatch(stopwatchName);
Assert.assertTrue(mbs.isRegistered(stopwatchObjectName));
SimonManager.destroySimon(stopwatchName);
Assert.assertFalse(mbs.isRegistered(stopwatchObjectName));
}
示例4: testException
import org.javasimon.SimonManager; //導入方法依賴的package包/類
@Test
public void testException() throws Exception {
Counter mon = SimonManager.getCounter(openMon.cleanExceptionForSimon(SharedConstants.EXCEPTION_LABEL));
Counter monGeneral = SimonManager.getCounter(OpenMon.EXCEPTION_LABEL);
assertThat(mon.getCounter()).describedAs("The exception monitor should not have been created yet").isEqualTo(0);
assertThat(monGeneral.getCounter()).describedAs("The general exception monitor should not have been created yet").isEqualTo(0);
openMon.exception(jp, SharedConstants.EXCEPTION);
assertThat(mon.getCounter()).describedAs("The exception monitor should have been created yet").isEqualTo(1);
assertThat(monGeneral.getCounter()).describedAs("The general exception monitor should have been created yet").isEqualTo(1);
}
示例5: SimonConnection
import org.javasimon.SimonManager; //導入方法依賴的package包/類
/**
* Class constructor, initializes Simons (lifespan, active, commits
* and rollbacks) related to the DB connection.
*
* @param conn real DB connection
* @param prefix hierarchy prefix for connection Simons
*/
public SimonConnection(Connection conn, String prefix) {
this.conn = conn;
this.wrapperSupport = new WrapperSupport<>(this.conn, Connection.class);
this.prefix = prefix;
commits = SimonManager.getCounter(prefix + ".conn.commits");
rollbacks = SimonManager.getCounter(prefix + ".conn.rollbacks");
life = SimonManager.getStopwatch(prefix + ".conn").start();
}
示例6: main
import org.javasimon.SimonManager; //導入方法依賴的package包/類
/**
* Entry point of the example application.
*
* @param args command line arguments
* @throws MalformedObjectNameException probably never
*/
public static void main(String[] args) throws MalformedObjectNameException {
// We create some example Simons
Stopwatch stopwatch = SimonManager.getStopwatch("org.javasimon.jmx.example1");
Counter counter = SimonManager.getCounter("org.javasimon.jmx.example2");
// Do little measurement for stopwatch Simon ...
try (Split ignored = stopwatch.start()) {
Thread.sleep(632);
} catch (InterruptedException e) { /* do nothing */ }
// ... and few usage of counter Simon.
counter.increase(52);
counter.decrease(12);
counter.increase(18);
// Than, we register provided SimonManagerMXBean.
// SimonManagerMXBean is part of javasimon, but register method is client responsibility
// so look to it for more detail.
register();
// The following is client part of code.
// Because, this is same VM, we don't need to create JMXConnector object and
// than obtain MBeanServerConnection. Platform MBeanServer is a MBeanServerConnection
// already, so it's used.
// So we use JMX.newMXBeanProxy method to make JMX create new client proxy of SimonManagerMXBean
// for us.
SimonManagerMXBean simonManagerMXBean = JMX.newMXBeanProxy(ManagementFactory.getPlatformMBeanServer(),
new ObjectName("org.javasimon.jmx.example:type=Simon"), SimonManagerMXBean.class);
// Now, we can freely retrieve samples for counter and stopwatch example Simons
System.out.println("counter = " + simonManagerMXBean.getCounterSample("org.javasimon.jmx.example2"));
System.out.println("stopwatch = " + simonManagerMXBean.getStopwatchSample("org.javasimon.jmx.example1"));
// After all, it's good manner to clean up, so we unregister MXBean
unregister();
}
示例7: counterKeyedSampling
import org.javasimon.SimonManager; //導入方法依賴的package包/類
private static void counterKeyedSampling() {
System.out.println("\nCOUNTER incremental sampling demo");
Counter counter = SimonManager.getCounter(null);
System.out.println(counter.sample());
counter.increase();
System.out.println("sample=" + counter.sample());
System.out.println("1: " + counter.sampleIncrement("1"));
counter.increase(2);
System.out.println("sample=" + counter.sample());
System.out.println("1: " + counter.sampleIncrement("1"));
counter.increase(3);
System.out.println("sample=" + counter.sample());
System.out.println("1: " + counter.sampleIncrement("1"));
System.out.println("2: " + counter.sampleIncrement("2"));
counter.set(4);
System.out.println("sample=" + counter.sample());
System.out.println("1: " + counter.sampleIncrement("1"));
System.out.println("2: " + counter.sampleIncrement("2"));
System.out.println("3: " + counter.sampleIncrement("3"));
counter.stopIncrementalSampling("1");
counter.increase(-5);
System.out.println("sample=" + counter.sample());
System.out.println("1: " + counter.sampleIncrement("1"));
System.out.println("2: " + counter.sampleIncrement("2"));
System.out.println("3: " + counter.sampleIncrement("3"));
}
示例8: performJmxCollection
import org.javasimon.SimonManager; //導入方法依賴的package包/類
private void performJmxCollection () {
collectionStart = System.currentTimeMillis();
// Java GC can very occasionally prevent collection
// retries are limited to avoid impacting subsequent collections
numberOfCollectionAttempts = 0;
Split jmxTimer = SimonManager.getStopwatch( "collector.jmx" ).start();
Stream<ServiceInstance> serviceToCollectStream = csapApplication
.getActiveModel()
.getServicesOnHost( Application.getHOST_NAME() );
numberOfCollectionAttempts = 0;
Counter jmxConnectionRetry = SimonManager.getCounter( "collector.jmx.connection.retry" );
while (true) {
numberOfCollectionAttempts++; // Strictly for tracking
List<ServiceInstance> failedToCollectInstances = serviceToCollectStream
.filter( ServiceInstance::isPerformJmxCollection )
.filter( this::collectJmxDataForService )
.collect( Collectors.toList() );
if ( failedToCollectInstances.size() > 0 ) {
jmxConnectionRetry.increase();
serviceToCollectStream = failedToCollectInstances.stream();
try {
logger.info(
"*jmxCollectionFailure item count: {} , attempts taken: {}, sleeping for 1s and trying again.",
failedToCollectInstances.size(), numberOfCollectionAttempts );
Thread.sleep( 1000 );
} catch (InterruptedException e) {
logger.debug( "jmxRetry faile", e );
}
} else {
break;
}
}
jmxTimer.stop();
}