From bf0e4b090f6b2d00363d4e61b3323f40b8dc8fe1 Mon Sep 17 00:00:00 2001 From: Michael Wilson Date: Thu, 22 May 2014 13:37:11 +0200 Subject: Ausgaben geändert --- Dozentenmodulserver/src/server/startServer.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Dozentenmodulserver/src/server/startServer.java') diff --git a/Dozentenmodulserver/src/server/startServer.java b/Dozentenmodulserver/src/server/startServer.java index 949b3538..824242d4 100644 --- a/Dozentenmodulserver/src/server/startServer.java +++ b/Dozentenmodulserver/src/server/startServer.java @@ -44,7 +44,7 @@ public class startServer { } //Start Server BasicConfigurator.configure(); - log.info( new Date() + " - starting Application\n" ); + log.info("***** "+ new Date() + " - starting Application *****" ); Thread t; t = new Thread(new BinaryListener()); servers.add(t); -- cgit v1.2.3-55-g7522 From edabd9afdac4778b1f3d7f7887d749f891ca9187 Mon Sep 17 00:00:00 2001 From: Nino Breuer Date: Thu, 22 May 2014 14:31:47 +0200 Subject: Vorbereitung Multithreading --- Dozentenmodul/bin/gui/intro/Login_GUI.class | Bin 9484 -> 9481 bytes .../bin/thrift/MasterThriftConnection.class | Bin 2125 -> 2122 bytes .../src/thrift/MasterThriftConnection.java | 4 +- .../bin/server/BinaryListener.class | Bin 2464 -> 3002 bytes Dozentenmodulserver/bin/server/ServerHandler.class | Bin 14495 -> 14495 bytes Dozentenmodulserver/bin/server/startServer.class | Bin 2057 -> 2057 bytes Dozentenmodulserver/src/server/BinaryListener.java | 14 ++- Dozentenmodulserver/src/server/Image.java | 2 +- Dozentenmodulserver/src/server/ServerHandler.java | 2 + .../src/server/TBinaryProtocolSafe.java | 123 +++++++++++++++++++++ Dozentenmodulserver/src/server/startServer.java | 28 ++++- 11 files changed, 167 insertions(+), 6 deletions(-) create mode 100644 Dozentenmodulserver/src/server/TBinaryProtocolSafe.java (limited to 'Dozentenmodulserver/src/server/startServer.java') diff --git a/Dozentenmodul/bin/gui/intro/Login_GUI.class b/Dozentenmodul/bin/gui/intro/Login_GUI.class index a24c4490..616eb572 100644 Binary files a/Dozentenmodul/bin/gui/intro/Login_GUI.class and b/Dozentenmodul/bin/gui/intro/Login_GUI.class differ diff --git a/Dozentenmodul/bin/thrift/MasterThriftConnection.class b/Dozentenmodul/bin/thrift/MasterThriftConnection.class index 9b587dd3..5b666704 100644 Binary files a/Dozentenmodul/bin/thrift/MasterThriftConnection.class and b/Dozentenmodul/bin/thrift/MasterThriftConnection.class 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 Binary files a/Dozentenmodulserver/bin/server/BinaryListener.class and b/Dozentenmodulserver/bin/server/BinaryListener.class differ diff --git a/Dozentenmodulserver/bin/server/ServerHandler.class b/Dozentenmodulserver/bin/server/ServerHandler.class index 95ad3b3f..6f11b771 100644 Binary files a/Dozentenmodulserver/bin/server/ServerHandler.class and b/Dozentenmodulserver/bin/server/ServerHandler.class differ diff --git a/Dozentenmodulserver/bin/server/startServer.class b/Dozentenmodulserver/bin/server/startServer.class index 14dc0861..0d223e85 100644 Binary files a/Dozentenmodulserver/bin/server/startServer.class and b/Dozentenmodulserver/bin/server/startServer.class 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 processor = new Server.Processor( 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, 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, SchemeFactory> schemes = new HashMap, 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 processor = new ImageServer.Processor(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" ); - + } } -- cgit v1.2.3-55-g7522