Commit 011b440f authored by Alex Wenckus's avatar Alex Wenckus Committed by alex

IAdding commons lang jar and source files

git-svn-id: http://svn.igniterealtime.org/svn/repos/openfire/trunk@9103 b35dd754-fafc-0310-a699-88a17e54d16e
parent 68578568
......@@ -5,6 +5,7 @@ ant-contrib.jar | 1.0b1
ant-subdirtask.jar | Revision 1.4 (CVS)
bouncycastle.jar | JDK 1.5, 137 (bcprov-jdk15-137.jar)
cglib.jar | 2.1.3 (JMock 2.1.0)
commons-lang.jar | 2.3
commons-logging.jar | Jetty 5.1.10
commons-el.jar | Jetty 6.0.1 (1.0)
commons-httpclient.jar | 3.0
......
......@@ -462,6 +462,17 @@
<SOURCES />
</library>
</orderEntry>
<orderEntry type="module-library" exported="">
<library>
<CLASSES>
<root url="jar://$MODULE_DIR$/../lib/merge/commons-lang.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES>
<root url="jar://$MODULE_DIR$/../lib/src/commons-lang-sources.jar!/" />
</SOURCES>
</library>
</orderEntry>
<orderEntryProperties />
</component>
<component name="VcsManagerConfiguration">
......
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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.
*/
package org.apache.commons.lang;
import java.io.IOException;
import java.io.StringWriter;
import java.io.Writer;
/**
* <p>Escapes and unescapes <code>String</code>s for
* Java, Java Script, HTML, XML, and SQL.</p>
*
* @author Apache Jakarta Turbine
* @author Purple Technology
* @author <a href="mailto:alex@purpletech.com">Alexander Day Chaffee</a>
* @author Antony Riley
* @author Helge Tesgaard
* @author <a href="sean@boohai.com">Sean Brown</a>
* @author <a href="mailto:ggregory@seagullsw.com">Gary Gregory</a>
* @author Phil Steitz
* @author Pete Gieser
* @since 2.0
* @version $Id: StringEscapeUtils.java 471626 2006-11-06 04:02:09Z bayard $
*/
public class StringEscapeUtils {
/**
* <p><code>StringEscapeUtils</code> instances should NOT be constructed in
* standard programming.</p>
*
* <p>Instead, the class should be used as:
* <pre>StringEscapeUtils.escapeJava("foo");</pre></p>
*
* <p>This constructor is public to permit tools that require a JavaBean
* instance to operate.</p>
*/
public StringEscapeUtils() {
super();
}
/**
* <p>Escapes the characters in a <code>String</code> using JavaScript String rules.</p>
* <p>Escapes any values it finds into their JavaScript String form.
* Deals correctly with quotes and control-chars (tab, backslash, cr, ff, etc.) </p>
*
* <p>So a tab becomes the characters <code>'\\'</code> and
* <code>'t'</code>.</p>
*
* <p>The only difference between Java strings and JavaScript strings
* is that in JavaScript, a single quote must be escaped.</p>
*
* <p>Example:
* <pre>
* input string: He didn't say, "Stop!"
* output string: He didn\'t say, \"Stop!\"
* </pre>
* </p>
*
* @param str String to escape values in, may be null
* @return String with escaped values, <code>null</code> if null string input
*/
public static String escapeJavaScript(String str) {
return escapeJavaStyleString(str, true);
}
/**
* <p>Escapes the characters in a <code>String</code> using JavaScript String rules
* to a <code>Writer</code>.</p>
*
* <p>A <code>null</code> string input has no effect.</p>
*
* @see #escapeJavaScript(java.lang.String)
* @param out Writer to write escaped string into
* @param str String to escape values in, may be null
* @throws IllegalArgumentException if the Writer is <code>null</code>
* @throws IOException if error occurs on underlying Writer
**/
public static void escapeJavaScript(Writer out, String str) throws IOException {
escapeJavaStyleString(out, str, true);
}
/**
* <p>Worker method for the {@link #escapeJavaScript(String)} method.</p>
*
* @param str String to escape values in, may be null
* @param escapeSingleQuotes escapes single quotes if <code>true</code>
* @return the escaped string
*/
private static String escapeJavaStyleString(String str, boolean escapeSingleQuotes) {
if (str == null) {
return null;
}
try {
StringWriter writer = new StringWriter(str.length() * 2);
escapeJavaStyleString(writer, str, escapeSingleQuotes);
return writer.toString();
} catch (IOException ioe) {
// this should never ever happen while writing to a StringWriter
ioe.printStackTrace();
return null;
}
}
/**
* <p>Worker method for the {@link #escapeJavaScript(String)} method.</p>
*
* @param out write to receieve the escaped string
* @param str String to escape values in, may be null
* @param escapeSingleQuote escapes single quotes if <code>true</code>
* @throws IOException if an IOException occurs
*/
private static void escapeJavaStyleString(Writer out, String str, boolean escapeSingleQuote) throws IOException {
if (out == null) {
throw new IllegalArgumentException("The Writer must not be null");
}
if (str == null) {
return;
}
int sz;
sz = str.length();
for (int i = 0; i < sz; i++) {
char ch = str.charAt(i);
// handle unicode
if (ch > 0xfff) {
out.write("\\u" + hex(ch));
} else if (ch > 0xff) {
out.write("\\u0" + hex(ch));
} else if (ch > 0x7f) {
out.write("\\u00" + hex(ch));
} else if (ch < 32) {
switch (ch) {
case '\b':
out.write('\\');
out.write('b');
break;
case '\n':
out.write('\\');
out.write('n');
break;
case '\t':
out.write('\\');
out.write('t');
break;
case '\f':
out.write('\\');
out.write('f');
break;
case '\r':
out.write('\\');
out.write('r');
break;
default :
if (ch > 0xf) {
out.write("\\u00" + hex(ch));
} else {
out.write("\\u000" + hex(ch));
}
break;
}
} else {
switch (ch) {
case '\'':
if (escapeSingleQuote) {
out.write('\\');
}
out.write('\'');
break;
case '"':
out.write('\\');
out.write('"');
break;
case '\\':
out.write('\\');
out.write('\\');
break;
default :
out.write(ch);
break;
}
}
}
}
/**
* <p>Returns an upper case hexadecimal <code>String</code> for the given
* character.</p>
*
* @param ch The character to convert.
* @return An upper case hexadecimal <code>String</code>
*/
private static String hex(char ch) {
return Integer.toHexString(ch).toUpperCase();
}
}
package org.apache.mina.management;
import org.apache.mina.common.*;
import org.apache.mina.filter.executor.ExecutorFilter;
import java.net.SocketAddress;
import java.util.Queue;
import java.util.Set;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.atomic.AtomicLong;
/**
* Collects statistics of an {@link org.apache.mina.common.IoService}. It's polling all the sessions of a given
* IoService. It's attaching a {@link org.apache.mina.management.IoSessionStat} object to all the sessions polled
* and filling the throughput values.
*
* Usage :
* <pre>
* IoService service = ...
* MINAStatCollector collector = new MINAStatCollector( service );
* collector.start();
* </pre>
*
* By default the {@link org.apache.mina.management.MINAStatCollector} is polling the sessions every 5 seconds. You can
* give a different polling time using a second constructor.<p>
*
* Note: This class is a spin-off from StatCollector present in
* https://svn.apache.org/repos/asf/mina/branches/1.1/core/src/main/java/org/apache/mina/management.
*
* @author The Apache Directory Project (mina-dev@directory.apache.org)
* @version $Rev: 477648 $, $Date: 2006-11-21 04:33:38 -0800 (Tue, 21 Nov 2006) $
*/
public class MINAStatCollector {
/**
* The session attribute key for {@link org.apache.mina.management.IoSessionStat}.
*/
public static final String KEY = MINAStatCollector.class.getName() + ".stat";
/**
* @noinspection StaticNonFinalField
*/
private static volatile int nextId = 0;
private final int id = nextId ++;
private final IoService service;
private Worker worker;
private int pollingInterval = 5000;
private Queue<IoSession> polledSessions;
// resume of session stats, for simplifying acces to the statistics
private AtomicLong totalProcessedSessions = new AtomicLong();
private AtomicLong totalMsgWritten = new AtomicLong();
private AtomicLong totalMsgRead = new AtomicLong();
private AtomicLong totalBytesWritten = new AtomicLong();
private AtomicLong totalBytesRead = new AtomicLong();
private AtomicLong totalScheduledWrites = new AtomicLong();
private AtomicLong totalQueuedEvents = new AtomicLong();
private final IoServiceListener serviceListener = new IoServiceListener()
{
public void serviceActivated( IoService service, SocketAddress serviceAddress, IoHandler handler,
IoServiceConfig config )
{
}
public void serviceDeactivated( IoService service, SocketAddress serviceAddress, IoHandler handler,
IoServiceConfig config )
{
}
public void sessionCreated( IoSession session )
{
addSession( session );
}
public void sessionDestroyed( IoSession session )
{
removeSession( session );
}
};
/**
* Create a stat collector for the given service with a default polling time of 5 seconds.
* @param service the IoService to inspect
*/
public MINAStatCollector( IoService service )
{
this( service,5000 );
}
/**
* create a stat collector for the given given service
* @param service the IoService to inspect
* @param pollingInterval milliseconds
*/
public MINAStatCollector( IoService service, int pollingInterval )
{
this.service = service;
this.pollingInterval = pollingInterval;
}
/**
* Start collecting stats for the {@link org.apache.mina.common.IoSession} of the service.
* New sessions or destroyed will be automaticly added or removed.
*/
public void start()
{
synchronized (this)
{
if ( worker != null && worker.isAlive() )
throw new RuntimeException( "Stat collecting already started" );
// add all current sessions
polledSessions = new ConcurrentLinkedQueue<IoSession>();
Set<SocketAddress> addresses = service.getManagedServiceAddresses();
if (addresses != null) {
for (SocketAddress element : addresses) {
for (IoSession ioSession : service.getManagedSessions(element)) {
addSession(ioSession);
}
}
}
// listen for new ones
service.addListener( serviceListener );
// start polling
worker = new Worker();
worker.start();
}
}
/**
* Stop collecting stats. all the {@link org.apache.mina.management.IoSessionStat} object will be removed of the
* polled session attachements.
*/
public void stop()
{
synchronized (this)
{
service.removeListener( serviceListener );
// stop worker
worker.stop = true;
worker.interrupt();
while( worker.isAlive() )
{
try
{
worker.join();
}
catch( InterruptedException e )
{
//ignore since this is shutdown time
}
}
for (IoSession session : polledSessions) {
session.removeAttribute(KEY);
}
polledSessions.clear();
}
}
/**
* is the stat collector started and polling the {@link org.apache.mina.common.IoSession} of the {@link org.apache.mina.common.IoService}
* @return true if started
*/
public boolean isRunning()
{
synchronized (this)
{
return worker != null && worker.stop != true;
}
}
private void addSession( IoSession session )
{
IoSessionStat sessionStats = new IoSessionStat();
sessionStats.lastPollingTime = System.currentTimeMillis();
session.setAttribute( KEY, sessionStats );
totalProcessedSessions.incrementAndGet();
polledSessions.add( session );
}
private void removeSession( IoSession session )
{
// remove the session from the list of polled sessions
polledSessions.remove( session );
// add the bytes processed between last polling and session closing
// prevent non seen byte with non-connected protocols like HTTP and datagrams
IoSessionStat sessStat = ( IoSessionStat ) session.getAttribute( KEY );
session.removeAttribute( KEY );
totalMsgWritten.addAndGet(session.getWrittenMessages() - sessStat.lastMessageWrite);
totalMsgRead.addAndGet(session.getReadMessages() - sessStat.lastMessageRead);
totalBytesWritten.addAndGet(session.getWrittenBytes() - sessStat.lastByteWrite);
totalBytesRead.addAndGet(session.getReadBytes() - sessStat.lastByteRead);
}
/**
* total number of sessions processed by the stat collector
* @return number of sessions
*/
public long getTotalProcessedSessions()
{
return totalProcessedSessions.longValue();
}
public long getBytesRead()
{
return totalBytesRead.get();
}
public long getBytesWritten()
{
return totalBytesWritten.get();
}
public long getMsgRead()
{
return totalMsgRead.get();
}
public long getMsgWritten()
{
return totalMsgWritten.get();
}
public long getScheduledWrites() {
return totalScheduledWrites.get();
}
public long getQueuedEvents() {
return totalQueuedEvents.get();
}
public long getSessionCount()
{
return polledSessions.size();
}
private class Worker extends Thread
{
boolean stop = false;
private Worker()
{
super( "StatCollectorWorker-"+id );
}
public void run()
{
while ( !stop )
{
// wait polling time
try
{
Thread.sleep( pollingInterval );
}
catch ( InterruptedException e )
{
}
long tmpMsgWritten = 0l;
long tmpMsgRead = 0l;
long tmpBytesWritten = 0l;
long tmpBytesRead = 0l;
long tmpScheduledWrites = 0l;
long tmpQueuevedEvents = 0l;
for (IoSession session : polledSessions)
{
// upadating individual session statistics
IoSessionStat sessStat = ( IoSessionStat ) session.getAttribute( KEY );
long currentTimestamp = System.currentTimeMillis();
// Calculate delta
float pollDelta = (currentTimestamp - sessStat.lastPollingTime) / 1000f;
// Store last polling time of this session
sessStat.lastPollingTime = currentTimestamp;
long readBytes = session.getReadBytes();
long writtenBytes = session.getWrittenBytes();
long readMessages = session.getReadMessages();
long writtenMessages = session.getWrittenMessages();
sessStat.byteReadThroughput = (readBytes - sessStat.lastByteRead) / pollDelta;
sessStat.byteWrittenThroughput = (writtenBytes - sessStat.lastByteWrite) / pollDelta;
sessStat.messageReadThroughput = (readMessages - sessStat.lastMessageRead) / pollDelta;
sessStat.messageWrittenThroughput = (writtenMessages - sessStat.lastMessageWrite) / pollDelta;
tmpMsgWritten += (writtenMessages - sessStat.lastMessageWrite);
tmpMsgRead += (readMessages - sessStat.lastMessageRead);
tmpBytesWritten += (writtenBytes - sessStat.lastByteWrite);
tmpBytesRead += (readBytes - sessStat.lastByteRead);
tmpScheduledWrites += session.getScheduledWriteRequests();
ExecutorFilter executorFilter =
(ExecutorFilter) session.getFilterChain().get(ExecutorThreadModel.class.getName());
if (executorFilter != null) {
tmpQueuevedEvents += executorFilter.getEventQueueSize(session);
}
sessStat.lastByteRead = readBytes;
sessStat.lastByteWrite = writtenBytes;
sessStat.lastMessageRead = readMessages;
sessStat.lastMessageWrite = writtenMessages;
}
totalMsgWritten.addAndGet(tmpMsgWritten);
totalMsgRead.addAndGet(tmpMsgRead);
totalBytesWritten.addAndGet(tmpBytesWritten);
totalBytesRead.addAndGet(tmpBytesRead);
totalScheduledWrites.set(tmpScheduledWrites);
totalQueuedEvents.set(tmpQueuevedEvents);
}
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment