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-01-28 20:46:27 +01:00
|
|
|
import envoy.server.data.ConfigItem;
|
2020-02-15 22:43:20 +01:00
|
|
|
import envoy.server.data.PersistenceManager;
|
2020-01-28 19:25:30 +01:00
|
|
|
import envoy.server.net.ObjectWriteProxy;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Project: <strong>envoy-server-standalone</strong><br>
|
2020-03-24 18:41:26 +01:00
|
|
|
* File: <strong>IDGeneratorRequestProcessor.java</strong><br>
|
2020-01-28 19:25:30 +01:00
|
|
|
* Created: <strong>28 Jan 2020</strong><br>
|
|
|
|
*
|
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-03-25 16:34:55 +01:00
|
|
|
public 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-03-25 16:34:55 +01:00
|
|
|
public Class<IDGeneratorRequest> getInputClass() { return IDGeneratorRequest.class; }
|
2020-01-28 19:25:30 +01:00
|
|
|
|
|
|
|
@Override
|
2020-03-26 20:14:09 +01: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-03-25 18:22:58 +01:00
|
|
|
public static IDGenerator createIDGenerator() { return createIDGenerator(ID_RANGE); }
|
|
|
|
|
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-04-06 22:55:27 +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
|
|
|
}
|