RLPark 1.0.0
Reinforcement Learning Framework in Java

IRobotServer.java

Go to the documentation of this file.
00001 package rlpark.plugin.irobot.internal.server;
00002 
00003 import java.io.IOException;
00004 
00005 import rlpark.plugin.irobot.internal.descriptors.IRobotCreateSerialConnection;
00006 import rlpark.plugin.irobot.internal.descriptors.IRobotSerialDescriptor;
00007 
00008 public class IRobotServer {
00009   final IRobotDiscoServer server;
00010   private final IRobotCreateSerialConnection serialConnection;
00011   private Thread serverThread;
00012   boolean isRunning = false;
00013 
00014   IRobotServer(int port, String serialPortPath, IRobotSerialDescriptor descriptor) {
00015     serialConnection = new IRobotCreateSerialConnection(serialPortPath, descriptor);
00016     server = new IRobotDiscoServer(port, serialConnection);
00017   }
00018 
00019   public void startDetach() {
00020     serverThread = new Thread(new Runnable() {
00021       @Override
00022       public void run() {
00023         if (!server.initializeSerialLinkCommunication())
00024           return;
00025         isRunning = true;
00026         try {
00027           server.start();
00028         } catch (IOException e) {
00029           e.printStackTrace();
00030         }
00031         isRunning = false;
00032       }
00033     });
00034     serverThread.start();
00035   }
00036 
00037   public void stop() {
00038     server.close();
00039     serverThread = null;
00040   }
00041 
00042   public int port() {
00043     return server.port();
00044   }
00045 
00046   public boolean isRunning() {
00047     return isRunning;
00048   }
00049 }
 All Classes Namespaces Files Functions Variables Enumerations
Zephyr
RLPark