PDA

View Full Version : jboss



zer0cool
یک شنبه 19 اسفند 1386, 11:21 صبح
اگر کسی اطلاعاتی درباره counter تو jboss و نحوه تنظیمش داره ممنون میشم در اختیارم بگذاره.
البته سرچ کردم ولی چیزه خاصی متوجه نشدم!

zer0cool
سه شنبه 21 اسفند 1386, 11:04 صبح
public class CounterService
extends ServiceMBeanSupport
implements CounterServiceMBean

A service offering accumulator style counters to help in diagnosing performance issues.

//--------------------------------------------------------------------------------

public class MessageCounter
extends Object

This class stores message count informations for a given queue

MessageCounter

public MessageCounter(String name,
String subscription,
BasicQueue queue,
boolean topic,
boolean durable,
int daycountmax)

Constructor

Parameters:
name - destination name
subscription - subscription name
queue - internal queue object
topic - topic destination flag
durable - durable subsciption flag
daycountmax - max message history day count

Method Detail
getMessageStatistics

public static MessageStatistics[] getMessageStatistics(MessageCounter[] counter)
throws Exception

Get an array of message statistics from an array of message counters

Parameters:
counter - the message counters
Returns:
the message statistics
Throws:
Exception - for any error

toString

public String toString()

Get string representation

incrementCounter

public void incrementCounter()

Increment message counter and update message history

getDestinationName

public String getDestinationName()

Gets the related destination name

Returns:
String destination name

getDestinationSubscription

public String getDestinationSubscription()

Gets the related destination subscription

Returns:
String destination name

getDestinationTopic

public boolean getDestinationTopic()

Gets the related destination topic flag

Returns:
boolean true: topic destination, false: queue destination

getDestinationDurable

public boolean getDestinationDurable()

Gets the related destination durable subscription flag

Returns:
boolean true : durable subscription, false: non-durable subscription

getCount

public int getCount()

Gets the total message count since startup or last counter reset

Returns:
int message count

getCountDelta

public int getCountDelta()

Gets the message count delta since last method call

Returns:
int message count delta

getDepth

public int getDepth()

Gets the current message count of pending messages within the destination waiting for dispatch

Returns:
int message queue depth

getDepthDelta

public int getDepthDelta()

Gets the message count delta of pending messages since last method call. Therefore

Returns:
int message queue depth delta

getLastUpdate

public long getLastUpdate()

Gets the timestamp of the last message add

Returns:
long system time

resetCounter

public void resetCounter()

Reset message counter values

getCounterAsString

public String getCounterAsString()

Get message counter data as string in format "Topic/Queue, Name, Subscription, Durable, Count, CountDelta, Depth, DepthDelta, Timestamp Last Increment"

Returns:
String message counter data string

getHistoryLimit

public int getHistoryLimit()

Get message counter history day count limit <0: unlimited, 0: history disabled, >0: day count

setHistoryLimit

public void setHistoryLimit(int daycountmax)

Set message counter history day count limit <0: unlimited, 0: history disabled, >0: day count

resetHistory

public void resetHistory()

Reset message counter history

getHistoryAsString

public String getHistoryAsString()

Get message counter history data as string in format "day count\n Date 1, hour counter 0, hour counter 1, ..., hour counter 23\n Date 2, hour counter 0, hour counter 1, ..., hour counter 23\n ..... ..... Date n, hour counter 0, hour counter 1, ..., hour counter 23\n"

Returns:
String message history data string



//--------------------------------------------------------------------------------
Counter

A simple counter that starts counting at 1 at the top of the page, and each time it is invoked, will increase its value by one. These counters are transient, and relative to the current page view only - i.e. two persons viewing the same page at the same time get their own counters.

The current counter value is accessible also as a WikiVariable. The name of the variable is "counter", or "counter-<name>", if you have defined a counter name.

Parameters

* name = counter name. You may define as many counters per page as you want; you just need to separate them with the counter name

Example

[{Counter}], [{Counter}], [{Counter}], [{Counter name='aa'}] produces

1, 2, 3, 1.

The value of "counter" at the end is 3 and the value of "counter-aa" is 1.

//------------------------------------------------------------------------------


package demo.coordination;

import java.text.MessageFormat;

import java.util.logging.Logger;

import org.springframework.beans.factory.DisposableBean;

import org.springframework.beans.factory.InitializingBean ;

public class CounterService implements InitializingBean, DisposableBean, Runnable {



private static final Logger logger = Logger.getLogger(CounterService.class.getName());

private static final String LOG_PREFIX = System.getProperty("counter.log.prefix", "Counter service [INFO]:") + " ";

private static final int MAX_COUNTER = 999;

private static final String STATUS_FORMAT = "This node is currently <font color=\\\"green\\\"><b><i>{0}</i></b></font>.<br>The current distributed counter value is: {1}";

private transient boolean running;

private int counter = 0;

private final Object lock = new Object();



public void afterPropertiesSet() throws Exception {

log("Creating background thread to try to increment counter");

Thread t = new Thread(this, "MessageService");

t.start();

}



public void destroy() throws Exception {

running = false;

}



public void run() {

log("[background thread] Waiting to synchronize on the counter lock...");

synchronized (lock) {

log("[background thread] Got the counter lock, I will start incrementing the counter");

running = true;

boolean logFirstIncrement = true;

while (running) {

synchronized (this) {

counter++;

if (counter > MAX_COUNTER) counter = 0;

if (logFirstIncrement) {

log("[background thread] Incremented the counter to " + counter + " -- will increment every second");

logFirstIncrement = false;

}

}

try {

Thread.sleep(1000L);

} catch (InterruptedException ex) {

}

}

}

}



public String getStatus() {

synchronized (this) {

return MessageFormat.format(STATUS_FORMAT, new Object[]{running ? "active" : "passive", new Integer(counter)});

}

}



private static void log(String message) {

logger.info(LOG_PREFIX + message);

}

}

///--------------------------------------------------------------------------------

[License Info] JSourcery

package org.jboss.varia.counter;

import java.text.DecimalFormat;

import java.util.HashMap;

import java.util.Iterator;

import javax.naming.InitialContext;

import javax.naming.Reference;

import javax.naming.StringRefAddr;

import org.jboss.system.ServiceMBeanSupport;

import org.jboss.naming.NonSerializableFactory;

public class CounterService extends ServiceMBeanSupport implements CounterServiceMBean {



public static final String JNDI_NAME = "java:/CounterService";

private HashMap counterMap = new HashMap();



public void accumulate(String counterName, long add) {

Counter counter = null;

synchronized (counterMap) {

counter = (Counter)counterMap.get(counterName);

if (counter == null) {

counter = new Counter(counterName);

counterMap.put(counterName, counter);

}

}

counter.addToCount(add);

}



protected void startService() throws Exception {

InitialContext ctx = new InitialContext();

NonSerializableFactory.bind(JNDI_NAME, this);

StringRefAddr addr = new StringRefAddr("nns", JNDI_NAME);

Reference ref = new Reference(this.getClass().getName(), addr, NonSerializableFactory.class.getName(), null);

ctx.bind(JNDI_NAME, ref);

}



protected void stopService() throws Exception {

InitialContext ctx = new InitialContext();

ctx.unbind(JNDI_NAME);

NonSerializableFactory.unbind(JNDI_NAME);

}



public String list() {

DecimalFormat format = new DecimalFormat("####0.0000");

String retVal = "";

Iterator keys = counterMap.keySet().iterator();

while (keys.hasNext()) {

String key = (String)keys.next();

Counter counter = (Counter)counterMap.get(key);

long total = 0;

int entries = 0;

synchronized (counter) {

total = counter.getCount();

entries = counter.getEntries();

}

double avg = ((double)total) / ((double)entries);

String descrip = key + ": total=" + total + " on " + entries + "entries for " + "an average of " + format.format(avg) + "<br>\\n";

retVal += descrip;

}

return retVal;

}



private static class Counter {

private String name;

private long count = 0;

private int entries = 0;



public Counter(String n) {

super();

name = n;

}



public String getName() {

return name;

}



public synchronized long getCount() {

return count;

}



public synchronized int getEntries() {

return entries;

}



public synchronized void addToCount(long add) {

count += add;

entries++;

}

}

}



من این کدرو پیدا کردم اگه کسی میتونه دقیقا توضیح بده اینجا چه اتفاقی افتاده مرسی.