io.nadron.concurrent.Lanes Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of nadron Show documentation
Show all versions of nadron Show documentation
Nadron is a high speed socket based java game server written using Netty and Mike Rettig's Jetlang. It is specifically tuned for network based multiplayer games and supports TCP and UDP network protocols.
package io.nadron.concurrent;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.ThreadFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public enum Lanes
{
LANES;
final String serverCores = System.getProperty("jet.lanes");
final int numOfCores;
final Lane[] jetLanes;
@SuppressWarnings("unchecked")
Lanes()
{
final Logger LOG = LoggerFactory.getLogger(Lanes.class);
int cores = 1;
if (null != serverCores)
{
try
{
cores = Integer.parseInt(serverCores);
}
catch (NumberFormatException e)
{
LOG.warn("Invalid server cores {} passed in, going to ignore",serverCores);
// ignore;
}
}
numOfCores = cores;
jetLanes = new Lane[cores];
ThreadFactory threadFactory = new NamedThreadFactory("Lane",true);
for (int i = 1; i <= cores; i++)
{
DefaultLane defaultLane = new DefaultLane("Lane[" + i + "]",
ManagedExecutor.newSingleThreadExecutor(threadFactory));
jetLanes[i - 1] = defaultLane;
}
}
public Lane[] getJetLanes()
{
return jetLanes;
}
public int getNumOfCores()
{
return numOfCores;
}
}