Revision: e1ce31d7269f
Author: unknown <yulian@Venera.(none)>
Date: Wed Jan 16 13:48:40 2013
Log: Removed queueing on sending mgcp packets.
Small bug ( output only ) for play solved
http://code.google.com/p/mediaserver/source/detail?r=e1ce31d7269f
Modified:
/client/jsr-309/tck/deps/mgcp-driver-3.0.0.FINAL-SNAPSHOT.jar
/client/jsr-309/tck/server.log
/client/mgcp/driver/src/main/java/org/mobicents/protocols/mgcp/stack/JainMgcpStackImpl.java
/client/mgcp/driver/src/main/java/org/mobicents/protocols/mgcp/stack/JainMgcpStackProviderImpl.java
/client/mgcp/driver/src/main/java/org/mobicents/protocols/mgcp/utils/PacketRepresentation.java
/controls/mgcp/src/main/java/org/mobicents/media/server/mgcp/pkg/au/Play.java
=======================================
--- /client/jsr-309/tck/deps/mgcp-driver-3.0.0.FINAL-SNAPSHOT.jar Sat Jan
12 12:37:26 2013
+++ /client/jsr-309/tck/deps/mgcp-driver-3.0.0.FINAL-SNAPSHOT.jar Wed Jan
16 13:48:40 2013
Binary file, no diff available.
=======================================
--- /client/jsr-309/tck/server.log Tue Jan 15 13:21:41 2013
+++ /client/jsr-309/tck/server.log Wed Jan 16 13:48:40 2013
@@ -1,6 +1,6 @@
-2013-01-15 22:42:10,142 DEBUG [TestBase] (main) Loading
file:/opt/mobsource/medianew/client/jsr-309/tck/exclude-list.properties
-2013-01-15 22:42:10,143 INFO [Runner] (main) Start
mandatory.functional.mediagroup.PlayerTest.test_2_1_1_1_Play
javadoc::Joinable::1 javadoc::MediaGroup::1 javadoc::MediaGroup::6
javadoc::Player::1 javadoc::PlayerEvent::15
-2013-01-15 22:42:10,144 DEBUG [TestBase] (main) Getting a MsControlFactory
instance
-2013-01-15 22:42:10,165 INFO [DriverImpl] (main) Initializing MGCP on
/127.0.0.1:2729
-2013-01-15 22:42:10,179 WARN [JainMgcpStackImpl] (main) Failed to locate
properties file, using default values
-2013-01-15 22:42:10,188 INFO [JainMgcpStackImpl] (main) Jain Mgcp stack
bound to IP /127.0.0.1 and UDP port 2729
+2013-01-16 23:16:18,158 DEBUG [TestBase] (main) Loading
file:/opt/mobsource/medianew/client/jsr-309/tck/exclude-list.properties
+2013-01-16 23:16:18,160 INFO [Runner] (main) Start
mandatory.functional.mediagroup.PlayerTest.test_2_1_1_1_Play
javadoc::Joinable::1 javadoc::MediaGroup::1 javadoc::MediaGroup::6
javadoc::Player::1 javadoc::PlayerEvent::15
+2013-01-16 23:16:18,160 DEBUG [TestBase] (main) Getting a MsControlFactory
instance
+2013-01-16 23:16:18,181 INFO [DriverImpl] (main) Initializing MGCP on
/127.0.0.1:2729
+2013-01-16 23:16:18,194 WARN [JainMgcpStackImpl] (main) Failed to locate
properties file, using default values
+2013-01-16 23:16:18,204 INFO [JainMgcpStackImpl] (main) Jain Mgcp stack
bound to IP /127.0.0.1 and UDP port 2729
=======================================
---
/client/mgcp/driver/src/main/java/org/mobicents/protocols/mgcp/stack/JainMgcpStackImpl.java
Tue Jan 15 13:21:41 2013
+++
/client/mgcp/driver/src/main/java/org/mobicents/protocols/mgcp/stack/JainMgcpStackImpl.java
Wed Jan 16 13:48:40 2013
@@ -118,7 +118,6 @@
private ConcurrentHashMap<Integer, TransactionHandler>
completedTransactions = new ConcurrentHashMap<Integer,
TransactionHandler>();
private ConcurrentLinkedList<PacketRepresentation> inputQueue=new
ConcurrentLinkedList<PacketRepresentation>();
- private ConcurrentLinkedList<PacketRepresentation> outputQueue=new
ConcurrentLinkedList<PacketRepresentation>();
private DatagramSocket socket;
@@ -304,7 +303,14 @@
public void send(PacketRepresentation pr)
{
- outputQueue.offer(pr);
+ try {
+ this.channel.send(pr.getBuffer(), pr.getInetAddress());
+ } catch (IOException e) {
+ if(logger.isEnabledFor(Level.ERROR))
+ {
+ logger.error("I/O Exception occured, caused
by", e);
+ }
+ }
}
public boolean isRequest(String header) {
@@ -318,6 +324,11 @@
}
int length = 0;
+ //for testing only
+ long maxRunTime=0;
+ long maxCycleTime=0;
+ long currSleepTime=0;
+
long start = 0;
long finish = 0;
long drift = 0;
@@ -349,27 +360,18 @@
//this is for async send
this.provider.flush();
-
- while((pr=outputQueue.poll())!=null)
- {
- try {
- this.sendBuffer.clear();
-
this.sendBuffer.put(pr.getRawData(),0,pr.getLength());
- this.sendBuffer.flip();
-
this.channel.send(this.sendBuffer, pr.getInetAddress());
- } catch (IOException e) {
-
if(logger.isEnabledFor(Level.ERROR))
- {
- logger.error("I/O Exception
occured, caused by", e);
- }
- }
- }
finish = System.currentTimeMillis();
drift = finish - start;
latency = delay - drift;
//lets check by cycle since if we sleep more
due to
//other threads we will be working not too fast
here
+ if(drift>maxRunTime)
+ {
+ maxRunTime=drift;
+ logger.info("Network thread max working
time:" + maxRunTime);
+ }
+
start = finish;
if (drift <= threshold) {
@@ -379,6 +381,14 @@
return;
}
}
+
+ currSleepTime=System.currentTimeMillis()-finish;
+ if(currSleepTime+drift>maxCycleTime)
+ {
+ maxCycleTime=currSleepTime+drift;
+ logger.info("Network thread max cycle
time:" + maxCycleTime);
+ }
+
} catch (IOException e) {
if (stopped) {
break;
@@ -408,7 +418,7 @@
if(this.provider!=null)
this.provider.stop();
- if (logger.isDebugEnabled()) {
+ if (logger.isDebugEnabled()) {
logger.debug("MGCP stack stopped gracefully on" + this.localAddress
+ ":" + this.port);
}
}
=======================================
---
/client/mgcp/driver/src/main/java/org/mobicents/protocols/mgcp/stack/JainMgcpStackProviderImpl.java
Tue Jan 1 16:15:51 2013
+++
/client/mgcp/driver/src/main/java/org/mobicents/protocols/mgcp/stack/JainMgcpStackProviderImpl.java
Wed Jan 16 13:48:40 2013
@@ -90,38 +90,25 @@
protected NotifiedEntity notifiedEntity = null;
private ConcurrentLinkedList<EventWrapper> waitingQueue=new
ConcurrentLinkedList<EventWrapper>();
- private ConcurrentLinkedList<TransactionHandler> sendingQueue=new
ConcurrentLinkedList<TransactionHandler>();
private DispatcherThread dispatcher;
- private EncodingThread[] encodingThreads;
-
public JainMgcpStackProviderImpl(JainMgcpStackImpl runningStack) {
super();
// eventQueue = new QueuedExecutor();
// pool = Executors.newCachedThreadPool(new
ThreadFactoryImpl());
this.runningStack = runningStack;
- dispatcher=new DispatcherThread();
-
- this.encodingThreads=new
EncodingThread[this.runningStack.parserThreadPoolSize];
- for(int i=0;i<this.encodingThreads.length;i++)
- this.encodingThreads[i]=new EncodingThread();
+ dispatcher=new DispatcherThread();
}
protected void start()
{
- dispatcher.activate();
-
- for(int i=0;i<this.encodingThreads.length;i++)
- this.encodingThreads[i].activate();
+ dispatcher.activate();
}
protected void stop()
{
- dispatcher.shutdown();
-
- for(int i=0;i<this.encodingThreads.length;i++)
- this.encodingThreads[i].shutdown();
+ dispatcher.shutdown();
}
public void setNotifiedEntity(NotifiedEntity notifiedEntity) {
@@ -252,9 +239,7 @@
}
handle.setCommand(true);
handle.setCommandEvent(commandEvent);
-
- sendingQueue.offer(handle);
-
+ handle.send();
} else {
// SENDING RESPONSE
@@ -265,8 +250,7 @@
if (handle != null) {
handle.setCommand(false);
handle.setResponseEvent((JainMgcpResponseEvent) event);
- sendingQueue.offer(handle);
-
+ handle.send();
} else {
logger.error("The TransactionHandler not found for
TransactionHandle " + tid
+ " May be the Tx timed out. Event = " + (JainMgcpResponseEvent)
event);
@@ -463,39 +447,5 @@
private void shutdown() {
this.active = false;
}
- }
-
- private class EncodingThread extends Thread
- {
- private volatile boolean active;
-
- public EncodingThread()
- {
- }
-
- public void run() {
- while(active)
- try {
- sendingQueue.take().send();
- }
- catch(Exception e)
- {
- //catch everything, so worker wont die.
- if(logger.isEnabledFor(Level.ERROR))
- logger.error("Unexpected exception
occured:", e);
- }
- }
-
- public void activate() {
- this.active = true;
- this.start();
- }
-
- /**
- * Terminates thread.
- */
- private void shutdown() {
- this.active = false;
- }
- }
+ }
}
=======================================
---
/client/mgcp/driver/src/main/java/org/mobicents/protocols/mgcp/utils/PacketRepresentation.java
Sat Jan 12 12:37:26 2013
+++
/client/mgcp/driver/src/main/java/org/mobicents/protocols/mgcp/utils/PacketRepresentation.java
Wed Jan 16 13:48:40 2013
@@ -32,6 +32,7 @@
import java.net.InetAddress;
import java.net.InetSocketAddress;
+import java.nio.ByteBuffer;
/**
@@ -47,14 +48,22 @@
private byte[] rawData = null;
private InetSocketAddress remoteAddress = null;
private int length = 0;
+ private ByteBuffer buffer;
private PacketRepresentationFactory prFactory = null;
protected PacketRepresentation(int byteArrSize,
PacketRepresentationFactory prFactory) {
rawData = new byte[byteArrSize];
+ this.buffer=ByteBuffer.wrap(rawData);
this.prFactory = prFactory;
}
+ public ByteBuffer getBuffer() {
+ buffer.position(0);
+ buffer.limit(length);
+ return buffer;
+ }
+
public byte[] getRawData() {
return rawData;
}
=======================================
---
/controls/mgcp/src/main/java/org/mobicents/media/server/mgcp/pkg/au/Play.java
Sat Jan 12 12:37:26 2013
+++
/controls/mgcp/src/main/java/org/mobicents/media/server/mgcp/pkg/au/Play.java
Wed Jan 16 13:48:40 2013
@@ -97,6 +97,7 @@
//get announcement segments
segments = options.getSegments().iterator();
repeatCount = options.getRepeatCount();
+ segCount=0;
uri = segments.next().toString();