Skip to content

Commit

Permalink
#21 UdpManager will only generate selectors and initialize poll tasks…
Browse files Browse the repository at this point in the history
… when it is started. Upon stopping the manager, these resources will be cleaned.

Code cleanup of PortManager and UdpManager.
  • Loading branch information
hrosa committed Aug 25, 2015
1 parent f499797 commit 743a984
Show file tree
Hide file tree
Showing 3 changed files with 561 additions and 547 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,22 @@
package org.mobicents.media.server.io.network;

/**
* Defines relation between audio/video format and RTP payload number as
* specified by Audio/Video Profile spec.
* Possible types of IP addresses.
*
* @author Oleg Kulikov
* @author Henrique Rosa (henrique.rosa@telestax.com)
*/
public enum IPAddressType {

IPV4(0),IPV6(1),INVALID(2);

private int value;

IPAddressType(int value)
{
this.value=value;
IPV4(0), IPV6(1), INVALID(2);

private final int value;

IPAddressType(int value) {
this.value = value;
}

public int getValue()
{
return value;

public int getValue() {
return value;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,60 +23,72 @@
package org.mobicents.media.server.io.network;

import java.util.concurrent.atomic.AtomicInteger;

/**
* The utility class that helps to accuire port for converstion.
* The utility class that helps to acquire port for conversation.
*
* The range of available port is identified by a pair of integer constants.
* Method <code>next</code> consiquently peeks up even port either from beginning or
* from the end of range.
* The range of available port is identified by a pair of integer constants. Method <code>next</code> consequently peeks up even
* port either from beginning or from the end of range.
*
* @author yulian oifa
*/
public class PortManager {
//the available range
private int low = 1024, high=65534;
private int step=(high-low)/2;
//pointers

private static final int DEFAULT_LOW_PORT = 1024;
private static final int DEFAULT_HIGH_PORT = 65534;

private int lowestPort;
private int highestPort;
private int step;

private AtomicInteger currPort = new AtomicInteger(0);

/**
* Creates new instance.
*/
public PortManager(int lowestPort, int highestPort) {
this.lowestPort = lowestPort;
this.highestPort = highestPort;
this.step = (highestPort - lowestPort) / 2;
}

public PortManager() {
this(DEFAULT_LOW_PORT, DEFAULT_HIGH_PORT);
}

/**
* Modify the low boundary.
*
* @param low port number
*/
public void setLowestPort(int low) {
this.low = low % 2 == 0 ? low : low + 1;
step=(high-low)/2;
this.lowestPort = (low % 2 == 0) ? low : low + 1;
this.step = (this.highestPort - low) / 2;
}

/**
* Gets the low boundary of available range.
*
* @return low min port number
*/
public int getLowestPort() {
return low;
return lowestPort;
}

/**
* Modify the upper boundary.
*
* @param high port number
*/
public void setHighestPort(int high) {
this.high = high % 2 == 0 ? high : high - 1;
step=(high-low)/2 + 1;
this.highestPort = high % 2 == 0 ? high : high - 1;
this.step = (high - this.lowestPort) / 2 + 1;
}

/**
* Gets the upper boundary of available range.
*
* @retun min port number
*/
public int getHighestPort() {
return this.high;
return this.highestPort;
}

/**
Expand All @@ -85,15 +97,15 @@ public int getHighestPort() {
* @return even port number
*/
public int next() {
return high-(currPort.getAndAdd(1)%step)*2;
return highestPort - (currPort.getAndAdd(1) % step) * 2;
}

public int peek() {
return high-((currPort.get()+1)%step)*2;
return highestPort - ((currPort.get() + 1) % step) * 2;
}

public int current() {
return high-(currPort.get()%step)*2;
return highestPort - (currPort.get() % step) * 2;
}

}
Loading

0 comments on commit 743a984

Please sign in to comment.