diff options
Diffstat (limited to 'Dozentenmodulserver/src/server')
| -rw-r--r-- | Dozentenmodulserver/src/server/BinaryListener.java | 43 | ||||
| -rw-r--r-- | Dozentenmodulserver/src/server/Server.java | 252 | ||||
| -rw-r--r-- | Dozentenmodulserver/src/server/ServerHandler.java | 293 | ||||
| -rw-r--r-- | Dozentenmodulserver/src/server/TBinaryProtocolSafe.java | 123 | ||||
| -rw-r--r-- | Dozentenmodulserver/src/server/startServer.java | 35 |
5 files changed, 497 insertions, 249 deletions
diff --git a/Dozentenmodulserver/src/server/BinaryListener.java b/Dozentenmodulserver/src/server/BinaryListener.java index a48b381e..ffeb9bd5 100644 --- a/Dozentenmodulserver/src/server/BinaryListener.java +++ b/Dozentenmodulserver/src/server/BinaryListener.java @@ -3,33 +3,46 @@ 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; -public class BinaryListener implements Runnable -{ - private static Logger log = Logger.getLogger( BinaryListener.class ); +public class BinaryListener implements Runnable { + private static Logger log = Logger.getLogger(BinaryListener.class); + + private final int MINWORKERTHREADS = 20; // keine ahnung ob das passt... + private final int MAXWORKERTHREADS = 80; // ebenso @Override - public void run() - { + public void run() { final ServerHandler handler = new ServerHandler(); - final Server.Processor<ServerHandler> processor = new Server.Processor<ServerHandler>( handler ); + 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"); - } catch ( TTransportException e ) { - log.fatal( new Date() +" - Could not listen on port 9090" ); + transport = new TServerSocket(9090); + log.info(new Date() + " - Connected to Port 9090"); + + } catch (TTransportException e) { + log.fatal(new Date() + " - Could not listen on port 9090"); return; } - TServer server = new TSimpleServer( new Args( transport ).processor( processor ) ); - log.info(new Date() +" - Started running BinaryListener"); + TServer server = new TThreadPoolServer(new Args(transport) + .protocolFactory(protFactory).processor(processor) + .minWorkerThreads(MINWORKERTHREADS) + .maxWorkerThreads(MAXWORKERTHREADS)); + + log.info(new Date() + " - Started running BinaryListener"); + log.info(new Date() + " - MINWORKERTHREADS=" + MINWORKERTHREADS + + " and MAXWORKERTHREADS=" + MAXWORKERTHREADS + "\n"); server.serve(); + } - + } diff --git a/Dozentenmodulserver/src/server/Server.java b/Dozentenmodulserver/src/server/Server.java index ef434865..b652bf7a 100644 --- a/Dozentenmodulserver/src/server/Server.java +++ b/Dozentenmodulserver/src/server/Server.java @@ -42,7 +42,7 @@ public class Server { public String getPathOfImage(String image_id, String version) throws org.apache.thrift.TException; - public boolean writeVLdata(String imagename, String login, String firstname, String lastname, String university, String Mail, String Tel, String Fak, boolean license, boolean internet, long ram, long cpu, String imagePath, boolean isTemplate, long filesize) throws org.apache.thrift.TException; + public boolean writeVLdata(String imagename, String login, String firstname, String lastname, String university, String Mail, String Tel, String Fak, boolean license, boolean internet, long ram, long cpu, String imagePath, boolean isTemplate, long filesize, long shareMode) throws org.apache.thrift.TException; public List<Image> getImageList() throws org.apache.thrift.TException; @@ -58,7 +58,7 @@ public class Server { public Map<String,String> getImageData(String imageid, String imageversion) throws org.apache.thrift.TException; - public boolean updateImageData(String name, String newName, String image_path, boolean license, boolean internet, long ram, long cpu, String id, String version, boolean isTemplate, long filesize) throws org.apache.thrift.TException; + public boolean updateImageData(String name, String newName, String image_path, boolean license, boolean internet, long ram, long cpu, String id, String version, boolean isTemplate, long filesize, long shareMode) throws org.apache.thrift.TException; public Map<String,String> getLectureData(String lecturename) throws org.apache.thrift.TException; @@ -82,7 +82,7 @@ public class Server { public void getPathOfImage(String image_id, String version, org.apache.thrift.async.AsyncMethodCallback resultHandler) throws org.apache.thrift.TException; - public void writeVLdata(String imagename, String login, String firstname, String lastname, String university, String Mail, String Tel, String Fak, boolean license, boolean internet, long ram, long cpu, String imagePath, boolean isTemplate, long filesize, org.apache.thrift.async.AsyncMethodCallback resultHandler) throws org.apache.thrift.TException; + public void writeVLdata(String imagename, String login, String firstname, String lastname, String university, String Mail, String Tel, String Fak, boolean license, boolean internet, long ram, long cpu, String imagePath, boolean isTemplate, long filesize, long shareMode, org.apache.thrift.async.AsyncMethodCallback resultHandler) throws org.apache.thrift.TException; public void getImageList(org.apache.thrift.async.AsyncMethodCallback resultHandler) throws org.apache.thrift.TException; @@ -98,7 +98,7 @@ public class Server { public void getImageData(String imageid, String imageversion, org.apache.thrift.async.AsyncMethodCallback resultHandler) throws org.apache.thrift.TException; - public void updateImageData(String name, String newName, String image_path, boolean license, boolean internet, long ram, long cpu, String id, String version, boolean isTemplate, long filesize, org.apache.thrift.async.AsyncMethodCallback resultHandler) throws org.apache.thrift.TException; + public void updateImageData(String name, String newName, String image_path, boolean license, boolean internet, long ram, long cpu, String id, String version, boolean isTemplate, long filesize, long shareMode, org.apache.thrift.async.AsyncMethodCallback resultHandler) throws org.apache.thrift.TException; public void getLectureData(String lecturename, org.apache.thrift.async.AsyncMethodCallback resultHandler) throws org.apache.thrift.TException; @@ -203,13 +203,13 @@ public class Server { throw new org.apache.thrift.TApplicationException(org.apache.thrift.TApplicationException.MISSING_RESULT, "getPathOfImage failed: unknown result"); } - public boolean writeVLdata(String imagename, String login, String firstname, String lastname, String university, String Mail, String Tel, String Fak, boolean license, boolean internet, long ram, long cpu, String imagePath, boolean isTemplate, long filesize) throws org.apache.thrift.TException + public boolean writeVLdata(String imagename, String login, String firstname, String lastname, String university, String Mail, String Tel, String Fak, boolean license, boolean internet, long ram, long cpu, String imagePath, boolean isTemplate, long filesize, long shareMode) throws org.apache.thrift.TException { - send_writeVLdata(imagename, login, firstname, lastname, university, Mail, Tel, Fak, license, internet, ram, cpu, imagePath, isTemplate, filesize); + send_writeVLdata(imagename, login, firstname, lastname, university, Mail, Tel, Fak, license, internet, ram, cpu, imagePath, isTemplate, filesize, shareMode); return recv_writeVLdata(); } - public void send_writeVLdata(String imagename, String login, String firstname, String lastname, String university, String Mail, String Tel, String Fak, boolean license, boolean internet, long ram, long cpu, String imagePath, boolean isTemplate, long filesize) throws org.apache.thrift.TException + public void send_writeVLdata(String imagename, String login, String firstname, String lastname, String university, String Mail, String Tel, String Fak, boolean license, boolean internet, long ram, long cpu, String imagePath, boolean isTemplate, long filesize, long shareMode) throws org.apache.thrift.TException { writeVLdata_args args = new writeVLdata_args(); args.setImagename(imagename); @@ -227,6 +227,7 @@ public class Server { args.setImagePath(imagePath); args.setIsTemplate(isTemplate); args.setFilesize(filesize); + args.setShareMode(shareMode); sendBase("writeVLdata", args); } @@ -413,13 +414,13 @@ public class Server { throw new org.apache.thrift.TApplicationException(org.apache.thrift.TApplicationException.MISSING_RESULT, "getImageData failed: unknown result"); } - public boolean updateImageData(String name, String newName, String image_path, boolean license, boolean internet, long ram, long cpu, String id, String version, boolean isTemplate, long filesize) throws org.apache.thrift.TException + public boolean updateImageData(String name, String newName, String image_path, boolean license, boolean internet, long ram, long cpu, String id, String version, boolean isTemplate, long filesize, long shareMode) throws org.apache.thrift.TException { - send_updateImageData(name, newName, image_path, license, internet, ram, cpu, id, version, isTemplate, filesize); + send_updateImageData(name, newName, image_path, license, internet, ram, cpu, id, version, isTemplate, filesize, shareMode); return recv_updateImageData(); } - public void send_updateImageData(String name, String newName, String image_path, boolean license, boolean internet, long ram, long cpu, String id, String version, boolean isTemplate, long filesize) throws org.apache.thrift.TException + public void send_updateImageData(String name, String newName, String image_path, boolean license, boolean internet, long ram, long cpu, String id, String version, boolean isTemplate, long filesize, long shareMode) throws org.apache.thrift.TException { updateImageData_args args = new updateImageData_args(); args.setName(name); @@ -433,6 +434,7 @@ public class Server { args.setVersion(version); args.setIsTemplate(isTemplate); args.setFilesize(filesize); + args.setShareMode(shareMode); sendBase("updateImageData", args); } @@ -717,9 +719,9 @@ public class Server { } } - public void writeVLdata(String imagename, String login, String firstname, String lastname, String university, String Mail, String Tel, String Fak, boolean license, boolean internet, long ram, long cpu, String imagePath, boolean isTemplate, long filesize, org.apache.thrift.async.AsyncMethodCallback resultHandler) throws org.apache.thrift.TException { + public void writeVLdata(String imagename, String login, String firstname, String lastname, String university, String Mail, String Tel, String Fak, boolean license, boolean internet, long ram, long cpu, String imagePath, boolean isTemplate, long filesize, long shareMode, org.apache.thrift.async.AsyncMethodCallback resultHandler) throws org.apache.thrift.TException { checkReady(); - writeVLdata_call method_call = new writeVLdata_call(imagename, login, firstname, lastname, university, Mail, Tel, Fak, license, internet, ram, cpu, imagePath, isTemplate, filesize, resultHandler, this, ___protocolFactory, ___transport); + writeVLdata_call method_call = new writeVLdata_call(imagename, login, firstname, lastname, university, Mail, Tel, Fak, license, internet, ram, cpu, imagePath, isTemplate, filesize, shareMode, resultHandler, this, ___protocolFactory, ___transport); this.___currentMethod = method_call; ___manager.call(method_call); } @@ -740,7 +742,8 @@ public class Server { private String imagePath; private boolean isTemplate; private long filesize; - public writeVLdata_call(String imagename, String login, String firstname, String lastname, String university, String Mail, String Tel, String Fak, boolean license, boolean internet, long ram, long cpu, String imagePath, boolean isTemplate, long filesize, org.apache.thrift.async.AsyncMethodCallback resultHandler, org.apache.thrift.async.TAsyncClient client, org.apache.thrift.protocol.TProtocolFactory protocolFactory, org.apache.thrift.transport.TNonblockingTransport transport) throws org.apache.thrift.TException { + private long shareMode; + public writeVLdata_call(String imagename, String login, String firstname, String lastname, String university, String Mail, String Tel, String Fak, boolean license, boolean internet, long ram, long cpu, String imagePath, boolean isTemplate, long filesize, long shareMode, org.apache.thrift.async.AsyncMethodCallback resultHandler, org.apache.thrift.async.TAsyncClient client, org.apache.thrift.protocol.TProtocolFactory protocolFactory, org.apache.thrift.transport.TNonblockingTransport transport) throws org.apache.thrift.TException { super(client, protocolFactory, transport, resultHandler, false); this.imagename = imagename; this.login = login; @@ -757,6 +760,7 @@ public class Server { this.imagePath = imagePath; this.isTemplate = isTemplate; this.filesize = filesize; + this.shareMode = shareMode; } public void write_args(org.apache.thrift.protocol.TProtocol prot) throws org.apache.thrift.TException { @@ -777,6 +781,7 @@ public class Server { args.setImagePath(imagePath); args.setIsTemplate(isTemplate); args.setFilesize(filesize); + args.setShareMode(shareMode); args.write(prot); prot.writeMessageEnd(); } @@ -1051,9 +1056,9 @@ public class Server { } } - public void updateImageData(String name, String newName, String image_path, boolean license, boolean internet, long ram, long cpu, String id, String version, boolean isTemplate, long filesize, org.apache.thrift.async.AsyncMethodCallback resultHandler) throws org.apache.thrift.TException { + public void updateImageData(String name, String newName, String image_path, boolean license, boolean internet, long ram, long cpu, String id, String version, boolean isTemplate, long filesize, long shareMode, org.apache.thrift.async.AsyncMethodCallback resultHandler) throws org.apache.thrift.TException { checkReady(); - updateImageData_call method_call = new updateImageData_call(name, newName, image_path, license, internet, ram, cpu, id, version, isTemplate, filesize, resultHandler, this, ___protocolFactory, ___transport); + updateImageData_call method_call = new updateImageData_call(name, newName, image_path, license, internet, ram, cpu, id, version, isTemplate, filesize, shareMode, resultHandler, this, ___protocolFactory, ___transport); this.___currentMethod = method_call; ___manager.call(method_call); } @@ -1070,7 +1075,8 @@ public class Server { private String version; private boolean isTemplate; private long filesize; - public updateImageData_call(String name, String newName, String image_path, boolean license, boolean internet, long ram, long cpu, String id, String version, boolean isTemplate, long filesize, org.apache.thrift.async.AsyncMethodCallback resultHandler, org.apache.thrift.async.TAsyncClient client, org.apache.thrift.protocol.TProtocolFactory protocolFactory, org.apache.thrift.transport.TNonblockingTransport transport) throws org.apache.thrift.TException { + private long shareMode; + public updateImageData_call(String name, String newName, String image_path, boolean license, boolean internet, long ram, long cpu, String id, String version, boolean isTemplate, long filesize, long shareMode, org.apache.thrift.async.AsyncMethodCallback resultHandler, org.apache.thrift.async.TAsyncClient client, org.apache.thrift.protocol.TProtocolFactory protocolFactory, org.apache.thrift.transport.TNonblockingTransport transport) throws org.apache.thrift.TException { super(client, protocolFactory, transport, resultHandler, false); this.name = name; this.newName = newName; @@ -1083,6 +1089,7 @@ public class Server { this.version = version; this.isTemplate = isTemplate; this.filesize = filesize; + this.shareMode = shareMode; } public void write_args(org.apache.thrift.protocol.TProtocol prot) throws org.apache.thrift.TException { @@ -1099,6 +1106,7 @@ public class Server { args.setVersion(version); args.setIsTemplate(isTemplate); args.setFilesize(filesize); + args.setShareMode(shareMode); args.write(prot); prot.writeMessageEnd(); } @@ -1472,7 +1480,7 @@ public class Server { public writeVLdata_result getResult(I iface, writeVLdata_args args) throws org.apache.thrift.TException { writeVLdata_result result = new writeVLdata_result(); - result.success = iface.writeVLdata(args.imagename, args.login, args.firstname, args.lastname, args.university, args.Mail, args.Tel, args.Fak, args.license, args.internet, args.ram, args.cpu, args.imagePath, args.isTemplate, args.filesize); + result.success = iface.writeVLdata(args.imagename, args.login, args.firstname, args.lastname, args.university, args.Mail, args.Tel, args.Fak, args.license, args.internet, args.ram, args.cpu, args.imagePath, args.isTemplate, args.filesize, args.shareMode); result.setSuccessIsSet(true); return result; } @@ -1635,7 +1643,7 @@ public class Server { public updateImageData_result getResult(I iface, updateImageData_args args) throws org.apache.thrift.TException { updateImageData_result result = new updateImageData_result(); - result.success = iface.updateImageData(args.name, args.newName, args.image_path, args.license, args.internet, args.ram, args.cpu, args.id, args.version, args.isTemplate, args.filesize); + result.success = iface.updateImageData(args.name, args.newName, args.image_path, args.license, args.internet, args.ram, args.cpu, args.id, args.version, args.isTemplate, args.filesize, args.shareMode); result.setSuccessIsSet(true); return result; } @@ -2002,7 +2010,7 @@ public class Server { } public void start(I iface, writeVLdata_args args, org.apache.thrift.async.AsyncMethodCallback<Boolean> resultHandler) throws TException { - iface.writeVLdata(args.imagename, args.login, args.firstname, args.lastname, args.university, args.Mail, args.Tel, args.Fak, args.license, args.internet, args.ram, args.cpu, args.imagePath, args.isTemplate, args.filesize,resultHandler); + iface.writeVLdata(args.imagename, args.login, args.firstname, args.lastname, args.university, args.Mail, args.Tel, args.Fak, args.license, args.internet, args.ram, args.cpu, args.imagePath, args.isTemplate, args.filesize, args.shareMode,resultHandler); } } @@ -2413,7 +2421,7 @@ public class Server { } public void start(I iface, updateImageData_args args, org.apache.thrift.async.AsyncMethodCallback<Boolean> resultHandler) throws TException { - iface.updateImageData(args.name, args.newName, args.image_path, args.license, args.internet, args.ram, args.cpu, args.id, args.version, args.isTemplate, args.filesize,resultHandler); + iface.updateImageData(args.name, args.newName, args.image_path, args.license, args.internet, args.ram, args.cpu, args.id, args.version, args.isTemplate, args.filesize, args.shareMode,resultHandler); } } @@ -4869,6 +4877,7 @@ public class Server { private static final org.apache.thrift.protocol.TField IMAGE_PATH_FIELD_DESC = new org.apache.thrift.protocol.TField("imagePath", org.apache.thrift.protocol.TType.STRING, (short)-13); private static final org.apache.thrift.protocol.TField IS_TEMPLATE_FIELD_DESC = new org.apache.thrift.protocol.TField("isTemplate", org.apache.thrift.protocol.TType.BOOL, (short)-14); private static final org.apache.thrift.protocol.TField FILESIZE_FIELD_DESC = new org.apache.thrift.protocol.TField("filesize", org.apache.thrift.protocol.TType.I64, (short)-15); + private static final org.apache.thrift.protocol.TField SHARE_MODE_FIELD_DESC = new org.apache.thrift.protocol.TField("shareMode", org.apache.thrift.protocol.TType.I64, (short)-16); private static final Map<Class<? extends IScheme>, SchemeFactory> schemes = new HashMap<Class<? extends IScheme>, SchemeFactory>(); static { @@ -4891,6 +4900,7 @@ public class Server { public String imagePath; // required public boolean isTemplate; // required public long filesize; // required + public long shareMode; // required /** The set of fields this struct contains, along with convenience methods for finding and manipulating them. */ public enum _Fields implements org.apache.thrift.TFieldIdEnum { @@ -4908,7 +4918,8 @@ public class Server { CPU((short)-12, "cpu"), IMAGE_PATH((short)-13, "imagePath"), IS_TEMPLATE((short)-14, "isTemplate"), - FILESIZE((short)-15, "filesize"); + FILESIZE((short)-15, "filesize"), + SHARE_MODE((short)-16, "shareMode"); private static final Map<String, _Fields> byName = new HashMap<String, _Fields>(); @@ -4953,6 +4964,8 @@ public class Server { return IS_TEMPLATE; case -15: // FILESIZE return FILESIZE; + case -16: // SHARE_MODE + return SHARE_MODE; default: return null; } @@ -4999,6 +5012,7 @@ public class Server { private static final int __CPU_ISSET_ID = 3; private static final int __ISTEMPLATE_ISSET_ID = 4; private static final int __FILESIZE_ISSET_ID = 5; + private static final int __SHAREMODE_ISSET_ID = 6; private byte __isset_bitfield = 0; public static final Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> metaDataMap; static { @@ -5033,6 +5047,8 @@ public class Server { new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.BOOL))); tmpMap.put(_Fields.FILESIZE, new org.apache.thrift.meta_data.FieldMetaData("filesize", org.apache.thrift.TFieldRequirementType.DEFAULT, new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.I64))); + tmpMap.put(_Fields.SHARE_MODE, new org.apache.thrift.meta_data.FieldMetaData("shareMode", org.apache.thrift.TFieldRequirementType.DEFAULT, + new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.I64 , "int"))); metaDataMap = Collections.unmodifiableMap(tmpMap); org.apache.thrift.meta_data.FieldMetaData.addStructMetaDataMap(writeVLdata_args.class, metaDataMap); } @@ -5055,7 +5071,8 @@ public class Server { long cpu, String imagePath, boolean isTemplate, - long filesize) + long filesize, + long shareMode) { this(); this.imagename = imagename; @@ -5079,6 +5096,8 @@ public class Server { setIsTemplateIsSet(true); this.filesize = filesize; setFilesizeIsSet(true); + this.shareMode = shareMode; + setShareModeIsSet(true); } /** @@ -5119,6 +5138,7 @@ public class Server { } this.isTemplate = other.isTemplate; this.filesize = other.filesize; + this.shareMode = other.shareMode; } public writeVLdata_args deepCopy() { @@ -5148,6 +5168,8 @@ public class Server { this.isTemplate = false; setFilesizeIsSet(false); this.filesize = 0; + setShareModeIsSet(false); + this.shareMode = 0; } public String getImagename() { @@ -5504,6 +5526,29 @@ public class Server { __isset_bitfield = EncodingUtils.setBit(__isset_bitfield, __FILESIZE_ISSET_ID, value); } + public long getShareMode() { + return this.shareMode; + } + + public writeVLdata_args setShareMode(long shareMode) { + this.shareMode = shareMode; + setShareModeIsSet(true); + return this; + } + + public void unsetShareMode() { + __isset_bitfield = EncodingUtils.clearBit(__isset_bitfield, __SHAREMODE_ISSET_ID); + } + + /** Returns true if field shareMode is set (has been assigned a value) and false otherwise */ + public boolean isSetShareMode() { + return EncodingUtils.testBit(__isset_bitfield, __SHAREMODE_ISSET_ID); + } + + public void setShareModeIsSet(boolean value) { + __isset_bitfield = EncodingUtils.setBit(__isset_bitfield, __SHAREMODE_ISSET_ID, value); + } + public void setFieldValue(_Fields field, Object value) { switch (field) { case IMAGENAME: @@ -5626,6 +5671,14 @@ public class Server { } break; + case SHARE_MODE: + if (value == null) { + unsetShareMode(); + } else { + setShareMode((Long)value); + } + break; + } } @@ -5676,6 +5729,9 @@ public class Server { case FILESIZE: return Long.valueOf(getFilesize()); + case SHARE_MODE: + return Long.valueOf(getShareMode()); + } throw new IllegalStateException(); } @@ -5717,6 +5773,8 @@ public class Server { return isSetIsTemplate(); case FILESIZE: return isSetFilesize(); + case SHARE_MODE: + return isSetShareMode(); } throw new IllegalStateException(); } @@ -5869,6 +5927,15 @@ public class Server { return false; } + boolean this_present_shareMode = true; + boolean that_present_shareMode = true; + if (this_present_shareMode || that_present_shareMode) { + if (!(this_present_shareMode && that_present_shareMode)) + return false; + if (this.shareMode != that.shareMode) + return false; + } + return true; } @@ -6035,6 +6102,16 @@ public class Server { return lastComparison; } } + lastComparison = Boolean.valueOf(isSetShareMode()).compareTo(other.isSetShareMode()); + if (lastComparison != 0) { + return lastComparison; + } + if (isSetShareMode()) { + lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.shareMode, other.shareMode); + if (lastComparison != 0) { + return lastComparison; + } + } return 0; } @@ -6150,6 +6227,10 @@ public class Server { sb.append("filesize:"); sb.append(this.filesize); first = false; + if (!first) sb.append(", "); + sb.append("shareMode:"); + sb.append(this.shareMode); + first = false; sb.append(")"); return sb.toString(); } @@ -6315,6 +6396,14 @@ public class Server { org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); } break; + case -16: // SHARE_MODE + if (schemeField.type == org.apache.thrift.protocol.TType.I64) { + struct.shareMode = iprot.readI64(); + struct.setShareModeIsSet(true); + } else { + org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); + } + break; default: org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); } @@ -6330,6 +6419,9 @@ public class Server { struct.validate(); oprot.writeStructBegin(STRUCT_DESC); + oprot.writeFieldBegin(SHARE_MODE_FIELD_DESC); + oprot.writeI64(struct.shareMode); + oprot.writeFieldEnd(); oprot.writeFieldBegin(FILESIZE_FIELD_DESC); oprot.writeI64(struct.filesize); oprot.writeFieldEnd(); @@ -6456,7 +6548,10 @@ public class Server { if (struct.isSetFilesize()) { optionals.set(14); } - oprot.writeBitSet(optionals, 15); + if (struct.isSetShareMode()) { + optionals.set(15); + } + oprot.writeBitSet(optionals, 16); if (struct.isSetImagename()) { oprot.writeString(struct.imagename); } @@ -6502,12 +6597,15 @@ public class Server { if (struct.isSetFilesize()) { oprot.writeI64(struct.filesize); } + if (struct.isSetShareMode()) { + oprot.writeI64(struct.shareMode); + } } @Override public void read(org.apache.thrift.protocol.TProtocol prot, writeVLdata_args struct) throws org.apache.thrift.TException { TTupleProtocol iprot = (TTupleProtocol) prot; - BitSet incoming = iprot.readBitSet(15); + BitSet incoming = iprot.readBitSet(16); if (incoming.get(0)) { struct.imagename = iprot.readString(); struct.setImagenameIsSet(true); @@ -6568,6 +6666,10 @@ public class Server { struct.filesize = iprot.readI64(); struct.setFilesizeIsSet(true); } + if (incoming.get(15)) { + struct.shareMode = iprot.readI64(); + struct.setShareModeIsSet(true); + } } } @@ -13332,6 +13434,7 @@ public class Server { private static final org.apache.thrift.protocol.TField VERSION_FIELD_DESC = new org.apache.thrift.protocol.TField("version", org.apache.thrift.protocol.TType.STRING, (short)-9); private static final org.apache.thrift.protocol.TField IS_TEMPLATE_FIELD_DESC = new org.apache.thrift.protocol.TField("isTemplate", org.apache.thrift.protocol.TType.BOOL, (short)-10); private static final org.apache.thrift.protocol.TField FILESIZE_FIELD_DESC = new org.apache.thrift.protocol.TField("filesize", org.apache.thrift.protocol.TType.I64, (short)-11); + private static final org.apache.thrift.protocol.TField SHARE_MODE_FIELD_DESC = new org.apache.thrift.protocol.TField("shareMode", org.apache.thrift.protocol.TType.I64, (short)-12); private static final Map<Class<? extends IScheme>, SchemeFactory> schemes = new HashMap<Class<? extends IScheme>, SchemeFactory>(); static { @@ -13350,6 +13453,7 @@ public class Server { public String version; // required public boolean isTemplate; // required public long filesize; // required + public long shareMode; // required /** The set of fields this struct contains, along with convenience methods for finding and manipulating them. */ public enum _Fields implements org.apache.thrift.TFieldIdEnum { @@ -13363,7 +13467,8 @@ public class Server { ID((short)-8, "id"), VERSION((short)-9, "version"), IS_TEMPLATE((short)-10, "isTemplate"), - FILESIZE((short)-11, "filesize"); + FILESIZE((short)-11, "filesize"), + SHARE_MODE((short)-12, "shareMode"); private static final Map<String, _Fields> byName = new HashMap<String, _Fields>(); @@ -13400,6 +13505,8 @@ public class Server { return IS_TEMPLATE; case -11: // FILESIZE return FILESIZE; + case -12: // SHARE_MODE + return SHARE_MODE; default: return null; } @@ -13446,6 +13553,7 @@ public class Server { private static final int __CPU_ISSET_ID = 3; private static final int __ISTEMPLATE_ISSET_ID = 4; private static final int __FILESIZE_ISSET_ID = 5; + private static final int __SHAREMODE_ISSET_ID = 6; private byte __isset_bitfield = 0; public static final Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> metaDataMap; static { @@ -13472,6 +13580,8 @@ public class Server { new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.BOOL))); tmpMap.put(_Fields.FILESIZE, new org.apache.thrift.meta_data.FieldMetaData("filesize", org.apache.thrift.TFieldRequirementType.DEFAULT, new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.I64))); + tmpMap.put(_Fields.SHARE_MODE, new org.apache.thrift.meta_data.FieldMetaData("shareMode", org.apache.thrift.TFieldRequirementType.DEFAULT, + new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.I64 , "int"))); metaDataMap = Collections.unmodifiableMap(tmpMap); org.apache.thrift.meta_data.FieldMetaData.addStructMetaDataMap(updateImageData_args.class, metaDataMap); } @@ -13490,7 +13600,8 @@ public class Server { String id, String version, boolean isTemplate, - long filesize) + long filesize, + long shareMode) { this(); this.name = name; @@ -13510,6 +13621,8 @@ public class Server { setIsTemplateIsSet(true); this.filesize = filesize; setFilesizeIsSet(true); + this.shareMode = shareMode; + setShareModeIsSet(true); } /** @@ -13538,6 +13651,7 @@ public class Server { } this.isTemplate = other.isTemplate; this.filesize = other.filesize; + this.shareMode = other.shareMode; } public updateImageData_args deepCopy() { @@ -13563,6 +13677,8 @@ public class Server { this.isTemplate = false; setFilesizeIsSet(false); this.filesize = 0; + setShareModeIsSet(false); + this.shareMode = 0; } public String getName() { @@ -13823,6 +13939,29 @@ public class Server { __isset_bitfield = EncodingUtils.setBit(__isset_bitfield, __FILESIZE_ISSET_ID, value); } + public long getShareMode() { + return this.shareMode; + } + + public updateImageData_args setShareMode(long shareMode) { + this.shareMode = shareMode; + setShareModeIsSet(true); + return this; + } + + public void unsetShareMode() { + __isset_bitfield = EncodingUtils.clearBit(__isset_bitfield, __SHAREMODE_ISSET_ID); + } + + /** Returns true if field shareMode is set (has been assigned a value) and false otherwise */ + public boolean isSetShareMode() { + return EncodingUtils.testBit(__isset_bitfield, __SHAREMODE_ISSET_ID); + } + + public void setShareModeIsSet(boolean value) { + __isset_bitfield = EncodingUtils.setBit(__isset_bitfield, __SHAREMODE_ISSET_ID, value); + } + public void setFieldValue(_Fields field, Object value) { switch (field) { case NAME: @@ -13913,6 +14052,14 @@ public class Server { } break; + case SHARE_MODE: + if (value == null) { + unsetShareMode(); + } else { + setShareMode((Long)value); + } + break; + } } @@ -13951,6 +14098,9 @@ public class Server { case FILESIZE: return Long.valueOf(getFilesize()); + case SHARE_MODE: + return Long.valueOf(getShareMode()); + } throw new IllegalStateException(); } @@ -13984,6 +14134,8 @@ public class Server { return isSetIsTemplate(); case FILESIZE: return isSetFilesize(); + case SHARE_MODE: + return isSetShareMode(); } throw new IllegalStateException(); } @@ -14100,6 +14252,15 @@ public class Server { return false; } + boolean this_present_shareMode = true; + boolean that_present_shareMode = true; + if (this_present_shareMode || that_present_shareMode) { + if (!(this_present_shareMode && that_present_shareMode)) + return false; + if (this.shareMode != that.shareMode) + return false; + } + return true; } @@ -14226,6 +14387,16 @@ public class Server { return lastComparison; } } + lastComparison = Boolean.valueOf(isSetShareMode()).compareTo(other.isSetShareMode()); + if (lastComparison != 0) { + return lastComparison; + } + if (isSetShareMode()) { + lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.shareMode, other.shareMode); + if (lastComparison != 0) { + return lastComparison; + } + } return 0; } @@ -14309,6 +14480,10 @@ public class Server { sb.append("filesize:"); sb.append(this.filesize); first = false; + if (!first) sb.append(", "); + sb.append("shareMode:"); + sb.append(this.shareMode); + first = false; sb.append(")"); return sb.toString(); } @@ -14442,6 +14617,14 @@ public class Server { org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); } break; + case -12: // SHARE_MODE + if (schemeField.type == org.apache.thrift.protocol.TType.I64) { + struct.shareMode = iprot.readI64(); + struct.setShareModeIsSet(true); + } else { + org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); + } + break; default: org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); } @@ -14457,6 +14640,9 @@ public class Server { struct.validate(); oprot.writeStructBegin(STRUCT_DESC); + oprot.writeFieldBegin(SHARE_MODE_FIELD_DESC); + oprot.writeI64(struct.shareMode); + oprot.writeFieldEnd(); oprot.writeFieldBegin(FILESIZE_FIELD_DESC); oprot.writeI64(struct.filesize); oprot.writeFieldEnd(); @@ -14551,7 +14737,10 @@ public class Server { if (struct.isSetFilesize()) { optionals.set(10); } - oprot.writeBitSet(optionals, 11); + if (struct.isSetShareMode()) { + optionals.set(11); + } + oprot.writeBitSet(optionals, 12); if (struct.isSetName()) { oprot.writeString(struct.name); } @@ -14585,12 +14774,15 @@ public class Server { if (struct.isSetFilesize()) { oprot.writeI64(struct.filesize); } + if (struct.isSetShareMode()) { + oprot.writeI64(struct.shareMode); + } } @Override public void read(org.apache.thrift.protocol.TProtocol prot, updateImageData_args struct) throws org.apache.thrift.TException { TTupleProtocol iprot = (TTupleProtocol) prot; - BitSet incoming = iprot.readBitSet(11); + BitSet incoming = iprot.readBitSet(12); if (incoming.get(0)) { struct.name = iprot.readString(); struct.setNameIsSet(true); @@ -14635,6 +14827,10 @@ public class Server { struct.filesize = iprot.readI64(); struct.setFilesizeIsSet(true); } + if (incoming.get(11)) { + struct.shareMode = iprot.readI64(); + struct.setShareModeIsSet(true); + } } } diff --git a/Dozentenmodulserver/src/server/ServerHandler.java b/Dozentenmodulserver/src/server/ServerHandler.java index 5744003a..5ce72615 100644 --- a/Dozentenmodulserver/src/server/ServerHandler.java +++ b/Dozentenmodulserver/src/server/ServerHandler.java @@ -8,10 +8,7 @@ import java.nio.file.Path; import java.nio.file.Paths; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; -import java.sql.Connection; -import java.sql.ResultSet; import java.sql.SQLException; -import java.util.ArrayList; import java.util.Date; import java.util.HashMap; import java.util.List; @@ -26,9 +23,11 @@ import org.apache.thrift.TException; import sql.SQL; import util.XMLCreator; + + public class ServerHandler implements Server.Iface { static SQL sql = new SQL(); - static Connection con = sql.getConnection(); + private static Logger log = Logger.getLogger(ServerHandler.class); @Override @@ -38,18 +37,15 @@ public class ServerHandler implements Server.Iface { user.setUserName(UUID.randomUUID().toString().substring(0, 8)); user.setPassword(getEncodedSha1Sum(UUID.randomUUID().toString() .substring(0, 8))); - if(Configuration.config.getAbsolute_path().endsWith("/")) - { + if (Configuration.config.getAbsolute_path().endsWith("/")) { user.setPath(Configuration.config.getAbsolute_path()); + } else { + user.setPath(Configuration.config.getAbsolute_path() + "/"); } - else{ - user.setPath(Configuration.config.getAbsolute_path()+"/"); - } - SQL sql = new SQL(); - Connection con = sql.getConnection(); + // check if folder temp exists if (folderTempExists() == true) { - sql.writeFTPUser(con, user.getUserName(), user.getPassword()); + sql.writeFTPUser(user.getUserName(), user.getPassword()); return user; } else { log.info(new Date() + " - returning null user"); @@ -59,15 +55,11 @@ public class ServerHandler implements Server.Iface { public boolean folderTempExists() { // check if folder temp exists, otherwise create it - Path path=null; - if(Configuration.config.getAbsolute_path().endsWith("/")) - { - path = Paths - .get(Configuration.config.getAbsolute_path() + "temp"); - } - else{ - path = Paths - .get(Configuration.config.getAbsolute_path() + "/temp"); + Path path = null; + if (Configuration.config.getAbsolute_path().endsWith("/")) { + path = Paths.get(Configuration.config.getAbsolute_path() + "temp"); + } else { + path = Paths.get(Configuration.config.getAbsolute_path() + "/temp"); } if (Files.exists(path) == true) { @@ -83,9 +75,9 @@ public class ServerHandler implements Server.Iface { + "'"); return false; } else { - //set permissions + // set permissions try { - Runtime.getRuntime().exec("chmod 777 "+path); + Runtime.getRuntime().exec("chmod 777 " + path); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); @@ -112,26 +104,16 @@ public class ServerHandler implements Server.Iface { @Override public long DeleteFtpUser(String user) throws TException { - int ret = sql.DeleteUser(con, user); - return ret; + return sql.DeleteUser(user); } @Override public String getPathOfImage(String image_id, String version) throws TException { + log.info(new Date() + " - successfully returned PathOfImage: " + + sql.getPathOfImage(image_id, version)); + return sql.getPathOfImage(image_id, version); - try { - ResultSet rs = sql.getPathOfImage(con, image_id, version); - rs.next(); - log.info(new Date() + " - successfully returned PathOfImage: " - + rs.getString("image_path")); - return rs.getString("image_path"); - } catch (SQLException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - log.info(new Date() + " - returning PathOfImage: null"); - return null; } @Override @@ -139,15 +121,25 @@ public class ServerHandler implements Server.Iface { String firstname, String lastname, String university, String Mail, String Tel, String Fak, boolean license, boolean internet, long ram, long cpu, String imagePath, boolean isTemplate, - long filesize) throws TException { + long filesize, long shareMode) throws TException { + + String mode=null; + + if(shareMode==0) + { + mode="only_local"; + } + else{ + mode="to_be_published"; + } - String pk_institution = sql.setInstitution(con, university); + String pk_institution = sql.setInstitution(university); - String pk_person = sql.setPerson(con, login, lastname, firstname, Mail, + String pk_person = sql.setPerson(login, lastname, firstname, Mail, new Date(), pk_institution); - - sql.setImageData(con, pk_person, license, internet, cpu, ram, - imagename, imagePath, isTemplate, filesize); + + sql.setImageData(pk_person, license, internet, cpu, ram, imagename, + imagePath, isTemplate, filesize,mode); log.info(new Date() + " - written VLdata"); // TODO Auto-generated method stub @@ -156,73 +148,21 @@ public class ServerHandler implements Server.Iface { @Override public List<Image> getImageList() throws TException { - ResultSet res = sql.getImageList(con); - - List<Image> list = new ArrayList<Image>(); + return sql.getImageList(); - try { - - while (res.next()) { - - list.add(new Image(res.getString("GUID_imageID"), res - .getString("imageVersion"), - res.getString("image_name"), res - .getString("cond_hasLicenseRestriction"), res - .getString("name"), res.getString("lecture"), - res.getString("image_update_time"), res - .getString("user"))); - - } - - return list; - } catch (SQLException e1) { - // TODO Auto-generated catch block - e1.printStackTrace(); - } - log.info(new Date() + " - returning ImageList: " + list.size() - + " items."); - return null; } @Override public List<String> getAllOS() throws TException { - List<String> list = new ArrayList<>(); - ResultSet rs = sql.getAllOS(con); - try { - while (rs.next()) { - list.add(rs.getString("name")); - } - return list; - } catch (SQLException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - return null; + return sql.getAllOS(); + } @Override public Map<String, String> getPersonData(String Vorname, String Nachname) throws TException { - Map<String, String> map = new HashMap<String, String>(); - - ResultSet rs = sql.getPersonData(con, Vorname, Nachname); - try { - while (rs.next()) { - - map.put("mail", rs.getString("mail")); - map.put("Nachname", rs.getString("Nachname")); - map.put("Vorname", rs.getString("Vorname")); - map.put("Hochschule", rs.getString("name")); + return sql.getPersonData(Vorname, Nachname); - } - return map; - } catch (SQLException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - log.info(new Date() + " - returning PersonData: " + map.size() - + " items."); - return null; } @Override @@ -232,27 +172,19 @@ public class ServerHandler implements Server.Iface { String university, String Mail, String Tel, String Fak) throws TException { String pk_image = null; - + Map<String, String> map = new HashMap<String, String>(); int imageversion = 0; - String pk_institution = sql.setInstitution(con, university); - String pk_person = sql.setPerson(con, login, lastname, firstname, Mail, + String pk_institution = sql.setInstitution(university); + String pk_person = sql.setPerson(login, lastname, firstname, Mail, new Date(), pk_institution); - ResultSet image = sql.getImageIDandVersion(con, imagename); - - try { - while (image.next()) { - pk_image = image.getString("GUID_imageID"); - imageversion = image.getInt("imageVersion"); - } - } catch (SQLException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } + map = sql.getImageIDandVersion(imagename); - sql.setLectureData(con, pk_person, pk_image, imageversion, name, desc, + pk_image = map.get("GUID"); + imageversion = Integer.parseInt(map.get("version")); + sql.setLectureData(pk_person, pk_image, imageversion, name, desc, shortdesc, startDate, endDate, isActive); - XMLCreator xml = new XMLCreator(con, name); + XMLCreator xml = new XMLCreator(sql.getConnection(), name); try { xml.create(name); log.info(new Date() + " - XML created."); @@ -271,6 +203,7 @@ public class ServerHandler implements Server.Iface { @Override public boolean startFileCopy(String filename) throws TException { + //copy file from folder temp to folder prod String file = Configuration.config.getAbsolute_path() + "temp/" + filename; File tmpFile = new File(file); @@ -279,17 +212,13 @@ public class ServerHandler implements Server.Iface { + " - Trying to move file to '/srv/openslx/nfs/prod/" + tmpFile.getName() + "'"); try { - - // der übergebene Filename ist falsch - hier muss der generierte - // name geholt werden, nicht der ursprüngliche name. wo wird dieser - // eingelesen? - FileUtils.moveFile(tmpFile, new File(Configuration.config.getAbsolute_path() + "prod/" + filename)); - int ret = sql.UpdateImagePath(con, filename); - log.info(new Date() + " - update " + ret); - log.info(new Date() + " - file moved"); + // int ret = sql.UpdateImagePath(filename); + if (sql.UpdateImagePath(filename) == 0) { + log.info(new Date() + " - file moved and database updated."); + } } catch (IOException e) { // TODO Auto-generated catch block @@ -302,43 +231,27 @@ public class ServerHandler implements Server.Iface { @Override public Map<String, String> getImageData(String imageid, String imageversion) throws TException { - - ResultSet data = sql.getImageData(con, imageid, imageversion); - - Map<String, String> map = new HashMap<String, String>(); - try { - while (data.next()) { - System.out.println(data - .getString("cond_hasInternetRestriction") - + data.getString("cond_hasLicenseRestriction") - + data.getString("cond_minCPUs") - + data.getString("cond_minRAM")); - map.put("name", data.getString("image_name")); - map.put("internet", - data.getString("cond_hasInternetRestriction")); - map.put("license", data.getString("cond_hasLicenseRestriction")); - map.put("cpu", data.getString("cond_minCPUs")); - map.put("ram", data.getString("cond_minRAM")); - - } - return map; - } catch (SQLException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - log.info(new Date() + " - returning ImageData: " + map.size() - + "items."); - return null; - + log.info(new Date() + " - returning ImageData: " + + sql.getImageData(imageid, imageversion).size() + "items."); + return sql.getImageData(imageid, imageversion); } @Override public boolean updateImageData(String name, String newName, String image_path, boolean license, boolean internet, long ram, long cpu, String id, String version, boolean isTemplate, - long filesize) throws TException { - sql.UpdateImageData(con, name, newName, image_path, license, internet, - cpu, ram, id, version, isTemplate, filesize); + long filesize, long shareMode) throws TException { + String mode=null; + + if(shareMode==0) + { + mode="only_local"; + } + else{ + mode="to_be_published"; + } + sql.UpdateImageData(name, newName, image_path, license, internet, cpu, + ram, id, version, isTemplate, filesize,mode); return false; } @@ -351,29 +264,13 @@ public class ServerHandler implements Server.Iface { @Override public List<Lecture> getLectureList() throws TException { - ResultSet res = sql.getLectureList(con); - List<Lecture> list = new ArrayList<Lecture>(); - try { - - while (res.next()) { - - list.add(new Lecture(res.getString("lectureID"), res - .getString("name"), res.getString("isActive"), res - .getString("startTime"), res.getString("endTime"), res - .getString("lastUsed"), res.getString("description"), - res.getString("image_name"), res.getString("user"))); + log.info(new Date().toString() + " - returning LectureList: " + + sql.getLectureList().size() + " items."); + return sql.getLectureList(); + - } - return list; - } catch (SQLException e1) { - // TODO Auto-generated catch block - e1.printStackTrace(); - } - log.info(new Date() + " - returning LectureList: " + list.size() - + " items."); - return null; } @Override @@ -384,21 +281,14 @@ public class ServerHandler implements Server.Iface { String Fak, String id) throws TException { String pk_image = ""; int imageversion = 0; - ResultSet image = sql.getImageIDandVersion(con, imagename); + Map<String, String> image = sql.getImageIDandVersion(imagename); - try { - while (image.next()) { - pk_image = image.getString("GUID_imageID"); - imageversion = image.getInt("imageVersion"); - } - } catch (SQLException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - sql.updateLectureData(con, pk_image, imageversion, lastname, newName, - desc, shortdesc, startDate, endDate, isActive, id); + pk_image = image.get("GUID"); + imageversion = Integer.parseInt(image.get("version")); + sql.updateLectureData(pk_image, imageversion, lastname, newName, desc, + shortdesc, startDate, endDate, isActive, id); - XMLCreator xml = new XMLCreator(con, newName); + XMLCreator xml = new XMLCreator(sql.getConnection(), newName); try { xml.create(newName); } catch (SQLException | ParserConfigurationException @@ -416,14 +306,14 @@ public class ServerHandler implements Server.Iface { public boolean deleteImageServer(String imageid, String imageversion) throws TException { - String stringFile = sql.getFile(con, imageid, imageversion); + String stringFile = sql.getFile(imageid, imageversion); log.info(new Date() + " - File to Delete: " + stringFile); File tmpFile = new File(Configuration.config.getAbsolute_path() + stringFile); try { - // File wird von Server gelöscht + // File wird von Server gel�scht FileUtils.forceDelete(tmpFile); return true; @@ -439,36 +329,33 @@ public class ServerHandler implements Server.Iface { @Override public boolean deleteImageData(String id, String version) throws TException { - return sql.deleteImage(con, id, version); + return sql.deleteImage(id, version); } @Override public boolean connectedToLecture(String id, String version) throws TException { // TODO Auto-generated method stub - return sql.connectedToLecture(con, id, version); + return sql.connectedToLecture(id, version); } public boolean deleteLecture(String id, String hs, String user) { - ResultSet rs = sql.getDeleteXMLData(con, id); + Map<String, String> map = new HashMap<String, String>(); + map = sql.getDeleteXMLData(id); try { - rs.next(); - String date = rs.getString("admin_createTime").replace(" ", "") - .replace("-", "").replace(":", ""); - String name = rs.getString("name"); - String path = Configuration.config.getAbsolute_path() + "temp/" - + date.substring(0, date.length() - 2) + "_" + hs + "_" - + user + "_" + name + ".xml"; + + String path = Configuration.config.getAbsolute_path() + + "temp/" + + map.get("date") + .substring(0, map.get("date").length() - 2) + "_" + + hs + "_" + user + "_" + map.get("name") + ".xml"; File xmlFile = new File(path); FileUtils.forceDelete(xmlFile); - } catch (SQLException e) { - log.info(new Date() + " - Failed to execute deleteLecture"); - e.printStackTrace(); } catch (IOException e) { log.info(new Date() + " - Failed to execute deleteLecture"); e.printStackTrace(); } - return sql.deleteLecture(con, id); + return sql.deleteLecture(id); } 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 949b3538..a5509d04 100644 --- a/Dozentenmodulserver/src/server/startServer.java +++ b/Dozentenmodulserver/src/server/startServer.java @@ -16,6 +16,13 @@ import org.ini4j.Wini; 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 { /** @@ -28,6 +35,27 @@ 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 + + + //get Configuration try { Wini ini=new Wini(new File("Server_Config.ini")); @@ -43,14 +71,15 @@ public class startServer { e1.printStackTrace(); } //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); t.start(); //information - log.info( new Date()+" - new thread created. Now "+servers.size()+" thread(s).\n" ); + //log.info( new Date()+" - new thread created. Now "+servers.size()+" thread(s).\n" ); // Run more servers // ... // Wait for all servers to die @@ -66,7 +95,7 @@ public class startServer { } } log.info( new Date()+" - all Servers shut down, exiting...\n" ); - + } } |
