-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
246 additions
and
101 deletions.
There are no files selected for viewing
Binary file not shown.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package org.thematics.io.networking; | ||
|
||
import org.jboss.netty.channel.ChannelHandlerContext; | ||
import org.jboss.netty.channel.ChannelStateEvent; | ||
import org.jboss.netty.channel.ExceptionEvent; | ||
import org.jboss.netty.channel.MessageEvent; | ||
import org.jboss.netty.channel.SimpleChannelHandler; | ||
|
||
public class Handler extends SimpleChannelHandler { | ||
|
||
@Override | ||
public void channelOpen(ChannelHandlerContext ctx, ChannelStateEvent e) { | ||
|
||
} | ||
|
||
@Override | ||
public void channelClosed(ChannelHandlerContext ctx, ChannelStateEvent e) { | ||
|
||
} | ||
|
||
@Override | ||
public void channelConnected(ChannelHandlerContext ctx, ChannelStateEvent e) { | ||
|
||
} | ||
|
||
@Override | ||
public void channelDisconnected(ChannelHandlerContext ctx, ChannelStateEvent e) { | ||
|
||
} | ||
|
||
@Override | ||
public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) { | ||
|
||
} | ||
|
||
@Override | ||
public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent ee) throws Exception { | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package org.thematics.io.networking; | ||
|
||
import java.net.InetSocketAddress; | ||
|
||
import org.jboss.netty.bootstrap.ServerBootstrap; | ||
import org.jboss.netty.channel.ChannelException; | ||
import org.jboss.netty.channel.ChannelFactory; | ||
import org.jboss.netty.channel.ChannelPipeline; | ||
import org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory; | ||
import org.thematics.utility.Log; | ||
import org.thematics.utility.Log.Level; | ||
|
||
public class ServerChannel { | ||
|
||
private static final int PORT= 43594; | ||
private static ServerBootstrap bootstrap; | ||
|
||
public ServerChannel() { | ||
|
||
} | ||
|
||
public void init() { | ||
ChannelFactory factory = new NioServerSocketChannelFactory(); | ||
|
||
bootstrap = new ServerBootstrap(factory); | ||
|
||
Handler handler = new Handler(); | ||
|
||
ChannelPipeline pipeline = bootstrap.getPipeline(); | ||
pipeline.addLast("handler", handler); | ||
|
||
bootstrap.setOption("child.tcpNoDelay", true); | ||
bootstrap.setOption("child.keepAlive", true); | ||
|
||
try { | ||
bootstrap.bind(new InetSocketAddress(PORT)); | ||
} catch (ChannelException e) { | ||
Log.log("Could not bind the server to port " + PORT + ", shutting down..." , Level.FATAL); | ||
shutdown(); | ||
System.exit(0); | ||
} | ||
Log.log("Successfully bound on port " + PORT + ".", Level.INFO); | ||
} | ||
|
||
public static final void shutdown() { | ||
bootstrap.shutdown(); | ||
bootstrap.releaseExternalResources(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package org.thematics.server.event; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
/** | ||
* Class containing the specifications for the events. | ||
* @author Guillaume | ||
* | ||
*/ | ||
public abstract class Event { | ||
|
||
/** | ||
* The delay between each event process. | ||
*/ | ||
private int delay; | ||
|
||
/** | ||
* The events to be processed. | ||
*/ | ||
private List<Event> events = new ArrayList<Event>(); | ||
|
||
/** | ||
* An empty constructor with delay initialized with super() call. | ||
*/ | ||
public Event() { | ||
} | ||
|
||
/** | ||
* The processed event instance to initialize the delay. | ||
* @param delay | ||
*/ | ||
protected Event(int delay) { | ||
this.delay = delay; | ||
} | ||
|
||
/** | ||
* Returns the events to be processed. | ||
* @return events | ||
*/ | ||
public List<Event> getEvents() { | ||
return events; | ||
} | ||
|
||
/** | ||
* The delay between each event process. | ||
* @return delay | ||
*/ | ||
public int getDelay() { | ||
return delay; | ||
} | ||
|
||
/** | ||
* The event processed every x amount of time | ||
* depending on the delay value. | ||
* @param event | ||
* the event processed. | ||
*/ | ||
public abstract void processEvent(Event event); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package org.thematics.server.event; | ||
|
||
import java.util.concurrent.TimeUnit; | ||
|
||
import org.thematics.server.Executing; | ||
|
||
public class EventHandler { | ||
|
||
/** | ||
* The event instance to be processed. | ||
*/ | ||
private Event event; | ||
|
||
/** | ||
* Adds an event in the list to be processed and | ||
* initializes the event instance. | ||
* @param event | ||
*/ | ||
public void startEvent(Event event) { | ||
event.getEvents().add(event); | ||
this.event = event; | ||
} | ||
|
||
/** | ||
* Processes all the events from the list with a delay | ||
* determined with the constructor of the class. | ||
*/ | ||
public void process() { | ||
Executing.bigTasks.scheduleAtFixedRate(new Runnable() { | ||
|
||
@Override | ||
public void run() { | ||
for (Event events : event.getEvents()) | ||
events.processEvent(events); | ||
} | ||
|
||
}, 0, event.getDelay(), TimeUnit.MILLISECONDS); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package org.thematics.server.event; | ||
|
||
|
||
/** | ||
* All the events processed every 2000 ms. | ||
* @author Guillaume | ||
* | ||
*/ | ||
public class WorldEvents extends Event { | ||
|
||
public WorldEvents() { | ||
super(2000); | ||
} | ||
|
||
@Override | ||
public void processEvent(Event event) { | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -63,5 +63,4 @@ public void initWorld() { | |
private World() { | ||
|
||
} | ||
|
||
} |
Oops, something went wrong.