2020-01-28 19:25:30 +01:00
|
|
|
package envoy.server.processors;
|
|
|
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
2020-03-25 16:34:55 +01:00
|
|
|
import envoy.data.IDGenerator;
|
|
|
|
import envoy.event.IDGeneratorRequest;
|
2020-10-19 18:17:51 +02:00
|
|
|
|
2020-09-25 14:29:23 +02:00
|
|
|
import envoy.server.data.*;
|
2020-01-28 19:25:30 +01:00
|
|
|
import envoy.server.net.ObjectWriteProxy;
|
|
|
|
|
|
|
|
/**
|
2020-01-29 07:45:59 +01:00
|
|
|
* @author Kai S. K. Engelbart
|
2020-03-25 18:22:58 +01:00
|
|
|
* @author Maximilian Käfer
|
2020-01-28 19:25:30 +01:00
|
|
|
* @since Envoy Server Standalone v0.1-alpha
|
|
|
|
*/
|
2020-08-22 13:37:07 +02:00
|
|
|
public final class IDGeneratorRequestProcessor implements ObjectProcessor<IDGeneratorRequest> {
|
2020-01-28 19:25:30 +01:00
|
|
|
|
2020-02-12 07:53:54 +01:00
|
|
|
private static final long ID_RANGE = 200;
|
2020-01-28 19:25:30 +01:00
|
|
|
|
|
|
|
@Override
|
2020-10-19 18:17:51 +02:00
|
|
|
public void process(IDGeneratorRequest input, long socketID, ObjectWriteProxy writeProxy)
|
|
|
|
throws IOException {
|
2020-06-20 09:57:54 +02:00
|
|
|
writeProxy.write(socketID, createIDGenerator());
|
2020-01-28 19:25:30 +01:00
|
|
|
}
|
2020-03-25 18:22:58 +01:00
|
|
|
|
2020-03-26 17:09:52 +01:00
|
|
|
/**
|
|
|
|
* @return a new IDGenerator
|
|
|
|
* @since Envoy Server Standalone v0.1-beta
|
|
|
|
*/
|
2020-10-19 18:17:51 +02:00
|
|
|
public static IDGenerator createIDGenerator() {
|
|
|
|
return createIDGenerator(ID_RANGE);
|
|
|
|
}
|
2020-03-25 18:22:58 +01:00
|
|
|
|
2020-03-26 17:09:52 +01:00
|
|
|
/**
|
|
|
|
* @param range of IDs used by the new IDGenerator
|
|
|
|
* @return a new IDGenerator with a specific range of IDs
|
|
|
|
* @since Envoy Server Standalone v0.1-beta
|
|
|
|
*/
|
2020-03-25 18:22:58 +01:00
|
|
|
public static IDGenerator createIDGenerator(long range) {
|
2020-10-19 18:17:51 +02:00
|
|
|
ConfigItem currentID =
|
|
|
|
PersistenceManager.getInstance().getConfigItemByID("currentMessageId");
|
2020-03-26 20:14:09 +01:00
|
|
|
IDGenerator generator = new IDGenerator(Integer.parseInt(currentID.getValue()), range);
|
|
|
|
currentID.setValue(String.valueOf(Integer.parseInt(currentID.getValue()) + range));
|
|
|
|
PersistenceManager.getInstance().updateConfigItem(currentID);
|
2020-03-25 18:22:58 +01:00
|
|
|
return generator;
|
|
|
|
}
|
2020-01-28 19:25:30 +01:00
|
|
|
}
|