summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNino Breuer2014-05-22 14:31:47 +0200
committerNino Breuer2014-05-22 14:31:47 +0200
commitedabd9afdac4778b1f3d7f7887d749f891ca9187 (patch)
treeee5a97503ffb3ec08c887f472f1179b289cbbb1e
parentnix (diff)
downloadtutor-module-edabd9afdac4778b1f3d7f7887d749f891ca9187.tar.gz
tutor-module-edabd9afdac4778b1f3d7f7887d749f891ca9187.tar.xz
tutor-module-edabd9afdac4778b1f3d7f7887d749f891ca9187.zip
Vorbereitung Multithreading
-rw-r--r--Dozentenmodul/bin/gui/intro/Login_GUI.classbin9484 -> 9481 bytes
-rw-r--r--Dozentenmodul/bin/thrift/MasterThriftConnection.classbin2125 -> 2122 bytes
-rw-r--r--Dozentenmodul/src/thrift/MasterThriftConnection.java4
-rw-r--r--Dozentenmodulserver/bin/server/BinaryListener.classbin2464 -> 3002 bytes
-rw-r--r--Dozentenmodulserver/bin/server/ServerHandler.classbin14495 -> 14495 bytes
-rw-r--r--Dozentenmodulserver/bin/server/startServer.classbin2057 -> 2057 bytes
-rw-r--r--Dozentenmodulserver/src/server/BinaryListener.java14
-rw-r--r--Dozentenmodulserver/src/server/Image.java2
-rw-r--r--Dozentenmodulserver/src/server/ServerHandler.java2
-rw-r--r--Dozentenmodulserver/src/server/TBinaryProtocolSafe.java123
-rw-r--r--Dozentenmodulserver/src/server/startServer.java28
11 files changed, 167 insertions, 6 deletions
diff --git a/Dozentenmodul/bin/gui/intro/Login_GUI.class b/Dozentenmodul/bin/gui/intro/Login_GUI.class
index a24c4490..616eb572 100644
--- a/Dozentenmodul/bin/gui/intro/Login_GUI.class
+++ b/Dozentenmodul/bin/gui/intro/Login_GUI.class
Binary files differ
diff --git a/Dozentenmodul/bin/thrift/MasterThriftConnection.class b/Dozentenmodul/bin/thrift/MasterThriftConnection.class
index 9b587dd3..5b666704 100644
--- a/Dozentenmodul/bin/thrift/MasterThriftConnection.class
+++ b/Dozentenmodul/bin/thrift/MasterThriftConnection.class
Binary files differ
diff --git a/Dozentenmodul/src/thrift/MasterThriftConnection.java b/Dozentenmodul/src/thrift/MasterThriftConnection.java
index 24d034f2..41e89182 100644
--- a/Dozentenmodul/src/thrift/MasterThriftConnection.java
+++ b/Dozentenmodul/src/thrift/MasterThriftConnection.java
@@ -14,7 +14,9 @@ import thrift.ImageServer.Client;
public class MasterThriftConnection {
- public static final String MASTERSERVERIP="132.230.4.16";
+ //public static final String MASTERSERVERIP="132.230.4.16";
+ public static final String MASTERSERVERIP="127.0.0.1";
+
final TTransport transport = new TSocket(MASTERSERVERIP, 9090);
public Client getMasterThriftConnection()
diff --git a/Dozentenmodulserver/bin/server/BinaryListener.class b/Dozentenmodulserver/bin/server/BinaryListener.class
index 4a135f2d..1b204bfe 100644
--- a/Dozentenmodulserver/bin/server/BinaryListener.class
+++ b/Dozentenmodulserver/bin/server/BinaryListener.class
Binary files differ
diff --git a/Dozentenmodulserver/bin/server/ServerHandler.class b/Dozentenmodulserver/bin/server/ServerHandler.class
index 95ad3b3f..6f11b771 100644
--- a/Dozentenmodulserver/bin/server/ServerHandler.class
+++ b/Dozentenmodulserver/bin/server/ServerHandler.class
Binary files differ
diff --git a/Dozentenmodulserver/bin/server/startServer.class b/Dozentenmodulserver/bin/server/startServer.class
index 14dc0861..0d223e85 100644
--- a/Dozentenmodulserver/bin/server/startServer.class
+++ b/Dozentenmodulserver/bin/server/startServer.class
Binary files differ
diff --git a/Dozentenmodulserver/src/server/BinaryListener.java b/Dozentenmodulserver/src/server/BinaryListener.java
index 97793778..a6dd4496 100644
--- a/Dozentenmodulserver/src/server/BinaryListener.java
+++ b/Dozentenmodulserver/src/server/BinaryListener.java
@@ -3,9 +3,10 @@ package server;
import java.util.Date;
import org.apache.log4j.Logger;
+import org.apache.thrift.protocol.TProtocolFactory;
import org.apache.thrift.server.TServer;
-import org.apache.thrift.server.TServer.Args;
-import org.apache.thrift.server.TSimpleServer;
+import org.apache.thrift.server.TThreadPoolServer.Args;
+import org.apache.thrift.server.TThreadPoolServer;
import org.apache.thrift.transport.TServerSocket;
import org.apache.thrift.transport.TServerTransport;
import org.apache.thrift.transport.TTransportException;
@@ -20,6 +21,7 @@ public class BinaryListener implements Runnable
final ServerHandler handler = new ServerHandler();
final Server.Processor<ServerHandler> processor = new Server.Processor<ServerHandler>( handler );
final TServerTransport transport;
+ final TProtocolFactory protFactory = new TBinaryProtocolSafe.Factory( true, true );
try {
transport = new TServerSocket( 9090 );
log.info(new Date()+" - Connected to Port 9090");
@@ -27,7 +29,13 @@ public class BinaryListener implements Runnable
log.fatal( new Date() +" - Could not listen on port 9090" );
return;
}
- TServer server = new TSimpleServer( new Args( transport ).processor( processor ) );
+ //TServer server = new TSimpleServer( new Args( transport ).processor( processor ) );
+ //TServer server = new TThreadPoolServer( new Args( transport ).protocolFactory( protFactory ).processor( processor ).minWorkerThreads( 4 ).maxWorkerThreads( 8 ) );
+ //TServer server = new TThreadPoolServer( new Args( transport ).protocolFactory( protFactory ).processor( processor ) );
+ //TThreadPoolServer server = new TThreadPoolServer( new Args( transport ).protocolFactory( protFactory ).processor( processor ).minWorkerThreads( 4 ).maxWorkerThreads( 8 ) );
+
+ TServer server = new TThreadPoolServer( new Args( transport ).protocolFactory( protFactory ).processor( processor ).minWorkerThreads( 4 ).maxWorkerThreads( 8 ) );
+
log.info(new Date() +" - Started running BinaryListener");
server.serve();
}
diff --git a/Dozentenmodulserver/src/server/Image.java b/Dozentenmodulserver/src/server/Image.java
index 34c2b45c..e82aca0f 100644
--- a/Dozentenmodulserver/src/server/Image.java
+++ b/Dozentenmodulserver/src/server/Image.java
@@ -43,7 +43,7 @@ public class Image implements org.apache.thrift.TBase<Image, Image._Fields>, jav
private static final org.apache.thrift.protocol.TField LECTURE_NAME_FIELD_DESC = new org.apache.thrift.protocol.TField("lectureName", org.apache.thrift.protocol.TType.STRING, (short)-6);
private static final org.apache.thrift.protocol.TField UPDATE_TIME_FIELD_DESC = new org.apache.thrift.protocol.TField("updateTime", org.apache.thrift.protocol.TType.STRING, (short)-7);
private static final org.apache.thrift.protocol.TField USER_DATA_FIELD_DESC = new org.apache.thrift.protocol.TField("userData", org.apache.thrift.protocol.TType.STRING, (short)-8);
-
+
private static final Map<Class<? extends IScheme>, SchemeFactory> schemes = new HashMap<Class<? extends IScheme>, SchemeFactory>();
static {
schemes.put(StandardScheme.class, new ImageStandardSchemeFactory());
diff --git a/Dozentenmodulserver/src/server/ServerHandler.java b/Dozentenmodulserver/src/server/ServerHandler.java
index 5e736554..63970d34 100644
--- a/Dozentenmodulserver/src/server/ServerHandler.java
+++ b/Dozentenmodulserver/src/server/ServerHandler.java
@@ -25,6 +25,8 @@ import org.apache.thrift.TException;
import sql.SQL;
import util.XMLCreator;
+
+
public class ServerHandler implements Server.Iface {
static SQL sql = new SQL();
diff --git a/Dozentenmodulserver/src/server/TBinaryProtocolSafe.java b/Dozentenmodulserver/src/server/TBinaryProtocolSafe.java
new file mode 100644
index 00000000..843b58b1
--- /dev/null
+++ b/Dozentenmodulserver/src/server/TBinaryProtocolSafe.java
@@ -0,0 +1,123 @@
+package server;
+
+import java.io.UnsupportedEncodingException;
+import java.nio.ByteBuffer;
+
+import org.apache.thrift.TException;
+import org.apache.thrift.protocol.TBinaryProtocol;
+import org.apache.thrift.protocol.TMessage;
+import org.apache.thrift.protocol.TProtocol;
+import org.apache.thrift.protocol.TProtocolException;
+import org.apache.thrift.protocol.TProtocolFactory;
+import org.apache.thrift.transport.TTransport;
+
+/**
+ * Binary protocol implementation for thrift.
+ * Will not read messages bigger than 12MiB.
+ *
+ */
+public class TBinaryProtocolSafe extends TBinaryProtocol
+{
+ /**
+ * Factory
+ */
+ @SuppressWarnings( "serial" )
+ public static class Factory implements TProtocolFactory
+ {
+
+ protected boolean strictRead_ = false;
+ protected boolean strictWrite_ = true;
+
+ public Factory()
+ {
+ this( false, true );
+ }
+
+ public Factory(boolean strictRead, boolean strictWrite)
+ {
+ strictRead_ = strictRead;
+ strictWrite_ = strictWrite;
+ }
+
+ public TProtocol getProtocol( TTransport trans )
+ {
+ return new TBinaryProtocolSafe( trans, strictRead_, strictWrite_ );
+ }
+ }
+
+ private static final int maxLen = 12 * 1024 * 1024; // 12 MiB
+
+ /**
+ * Constructor
+ */
+ public TBinaryProtocolSafe(TTransport trans)
+ {
+ this( trans, false, true );
+ }
+
+ public TBinaryProtocolSafe(TTransport trans, boolean strictRead, boolean strictWrite)
+ {
+ super( trans );
+ strictRead_ = strictRead;
+ strictWrite_ = strictWrite;
+ }
+
+ /**
+ * Reading methods.
+ */
+
+ public TMessage readMessageBegin() throws TException
+ {
+ int size = readI32();
+ if ( size > maxLen )
+ throw new TProtocolException( TProtocolException.SIZE_LIMIT, "Payload too big." );
+ if ( size < 0 ) {
+ int version = size & VERSION_MASK;
+ if ( version != VERSION_1 ) {
+ throw new TProtocolException( TProtocolException.BAD_VERSION, "Bad version in readMessageBegin" );
+ }
+ return new TMessage( readString(), (byte) ( size & 0x000000ff ), readI32() );
+ } else {
+ if ( strictRead_ ) {
+ throw new TProtocolException( TProtocolException.BAD_VERSION, "Missing version in readMessageBegin, old client?" );
+ }
+ return new TMessage( readStringBody( size ), readByte(), readI32() );
+ }
+ }
+
+ public String readString() throws TException
+ {
+ int size = readI32();
+ if ( size > maxLen )
+ throw new TProtocolException( TProtocolException.SIZE_LIMIT, "Payload too big." );
+ if ( trans_.getBytesRemainingInBuffer() >= size ) {
+ try {
+ String s = new String( trans_.getBuffer(), trans_.getBufferPosition(), size, "UTF-8" );
+ trans_.consumeBuffer( size );
+ return s;
+ } catch ( UnsupportedEncodingException e ) {
+ throw new TException( "JVM DOES NOT SUPPORT UTF-8" );
+ }
+ }
+
+ return readStringBody( size );
+ }
+
+ public ByteBuffer readBinary() throws TException
+ {
+ int size = readI32();
+ if ( size > maxLen )
+ throw new TProtocolException( TProtocolException.SIZE_LIMIT, "Payload too big." );
+ if ( trans_.getBytesRemainingInBuffer() >= size ) {
+ ByteBuffer bb = ByteBuffer.wrap( trans_.getBuffer(), trans_.getBufferPosition(), size );
+ trans_.consumeBuffer( size );
+ return bb;
+ }
+
+ byte[] buf = new byte[ size ];
+ trans_.readAll( buf, 0, size );
+ return ByteBuffer.wrap( buf );
+ }
+
+}
+
diff --git a/Dozentenmodulserver/src/server/startServer.java b/Dozentenmodulserver/src/server/startServer.java
index 542c92b8..6f3d5a3d 100644
--- a/Dozentenmodulserver/src/server/startServer.java
+++ b/Dozentenmodulserver/src/server/startServer.java
@@ -10,6 +10,13 @@ import org.apache.log4j.Logger;
import server.BinaryListener;
+import org.apache.thrift.protocol.TProtocolFactory;
+import org.apache.thrift.server.TServer;
+import org.apache.thrift.server.TThreadPoolServer;
+import org.apache.thrift.transport.TServerSocket;
+import org.apache.thrift.transport.TServerTransport;
+import org.apache.thrift.transport.TTransportException;
+import org.apache.thrift.server.TThreadPoolServer.Args;
public class startServer {
/**
@@ -22,6 +29,25 @@ public class startServer {
public static void main(String[] args) {
+
+
+ //final ImageServerHandler handler = new ImageServerHandler();
+ //final ImageServer.Processor<ImageServerHandler> processor = new ImageServer.Processor<ImageServerHandler>(handler);
+
+ /*
+ try{
+ TServerTransport serverTransport = new TServerSocket(9090);
+ //TServer server = new TSimpleServer(new Args(serverTransport).processor(processor));
+ TServer server = new TThreadPoolServer(new TThreadPoolServer.Args(serverTransport).processor(processor));
+ server.serve();
+ } catch (Exception e){
+ e.printStackTrace();
+ }
+ */
+
+ //deprecated
+
+
BasicConfigurator.configure();
log.info( new Date() + " - starting Application\n" );
Thread t;
@@ -45,7 +71,7 @@ public class startServer {
}
}
log.info( new Date()+" - all Servers shut down, exiting...\n" );
-
+
}
}