@Test public void concurrencyStrategy() { LeaseAcquirerServerService serverService = new LeaseAcquirerServerService(); ConcurrencyStrategy<LeaseMessage> concurrencyStrategy = serverService.getConcurrencyStrategy(new byte[0]); assertEquals(ConcurrencyStrategy.UNIVERSAL_KEY, concurrencyStrategy.concurrencyKey(new LeaseRequest(0))); assertEquals(ConcurrencyStrategy.MANAGEMENT_KEY, concurrencyStrategy.concurrencyKey(new LeaseReconnectFinished(UUID.randomUUID()))); }
@Override public ConcurrencyStrategy<LeaseMessage> getConcurrencyStrategy(byte[] bytes) { return new ConcurrencyStrategy<LeaseMessage>() { @Override public int concurrencyKey(LeaseMessage leaseMessage) { LeaseMessageType messageType = leaseMessage.getType(); switch (messageType) { case LEASE_REQUEST: return ConcurrencyStrategy.UNIVERSAL_KEY; case LEASE_RECONNECT_FINISHED: return ConcurrencyStrategy.MANAGEMENT_KEY; default: throw new AssertionError("Unknown LeaseMessage type: " + messageType); } } @Override public Set<Integer> getKeysForSynchronization() { return Collections.emptySet(); } }; }
LeaseAcquirerServerService implements EntityServerService<LeaseMessage, LeaseResponse> { @Override public ConcurrencyStrategy<LeaseMessage> getConcurrencyStrategy(byte[] bytes) { return new ConcurrencyStrategy<LeaseMessage>() { @Override public int concurrencyKey(LeaseMessage leaseMessage) { LeaseMessageType messageType = leaseMessage.getType(); switch (messageType) { case LEASE_REQUEST: return ConcurrencyStrategy.UNIVERSAL_KEY; case LEASE_RECONNECT_FINISHED: return ConcurrencyStrategy.MANAGEMENT_KEY; default: throw new AssertionError("Unknown LeaseMessage type: " + messageType); } } @Override public Set<Integer> getKeysForSynchronization() { return Collections.emptySet(); } }; } }
LeaseAcquirerServerService implements EntityServerService<LeaseMessage, LeaseResponse> { @Override public ConcurrencyStrategy<LeaseMessage> getConcurrencyStrategy(byte[] bytes) { return new ConcurrencyStrategy<LeaseMessage>() { @Override public int concurrencyKey(LeaseMessage leaseMessage) { LeaseMessageType messageType = leaseMessage.getType(); switch (messageType) { case LEASE_REQUEST: return ConcurrencyStrategy.UNIVERSAL_KEY; case LEASE_RECONNECT_FINISHED: return ConcurrencyStrategy.MANAGEMENT_KEY; default: throw new AssertionError("Unknown LeaseMessage type: " + messageType); } } @Override public Set<Integer> getKeysForSynchronization() { return Collections.emptySet(); } }; }  }
LeaseAcquirerServerService implements EntityServerService<LeaseMessage, LeaseResponse> { @Override public ConcurrencyStrategy<LeaseMessage> getConcurrencyStrategy(byte[] bytes) { return new ConcurrencyStrategy<LeaseMessage>() { @Override public int concurrencyKey(LeaseMessage leaseMessage) { LeaseMessageType messageType = leaseMessage.getType(); switch (messageType) { case LEASE_REQUEST: return ConcurrencyStrategy.UNIVERSAL_KEY; case LEASE_RECONNECT_FINISHED: return ConcurrencyStrategy.MANAGEMENT_KEY; default: throw new AssertionError("Unknown LeaseMessage type: " + messageType); } } @Override public Set<Integer> getKeysForSynchronization() { return Collections.emptySet(); } }; }  @Override long getVersion(); @Override boolean handlesEntityType(String typeName); @SuppressWarnings("unchecked") @Override ActiveServerEntity<LeaseMessage, LeaseResponse> createActiveEntity(ServiceRegistry serviceRegistry, byte[] bytes); @Override PassiveServerEntity<LeaseMessage, LeaseResponse> createPassiveEntity(ServiceRegistry serviceRegistry, byte[] bytes); @Override ConcurrencyStrategy<LeaseMessage> getConcurrencyStrategy(byte[] bytes); @Override MessageCodec<LeaseMessage, LeaseResponse> getMessageCodec(); @Override SyncMessageCodec<LeaseMessage> getSyncMessageCodec(); }
LeaseAcquirerServerService implements EntityServerService<LeaseMessage, LeaseResponse> { @Override public ConcurrencyStrategy<LeaseMessage> getConcurrencyStrategy(byte[] bytes) { return new ConcurrencyStrategy<LeaseMessage>() { @Override public int concurrencyKey(LeaseMessage leaseMessage) { LeaseMessageType messageType = leaseMessage.getType(); switch (messageType) { case LEASE_REQUEST: return ConcurrencyStrategy.UNIVERSAL_KEY; case LEASE_RECONNECT_FINISHED: return ConcurrencyStrategy.MANAGEMENT_KEY; default: throw new AssertionError("Unknown LeaseMessage type: " + messageType); } } @Override public Set<Integer> getKeysForSynchronization() { return Collections.emptySet(); } }; }  @Override long getVersion(); @Override boolean handlesEntityType(String typeName); @SuppressWarnings("unchecked") @Override ActiveServerEntity<LeaseMessage, LeaseResponse> createActiveEntity(ServiceRegistry serviceRegistry, byte[] bytes); @Override PassiveServerEntity<LeaseMessage, LeaseResponse> createPassiveEntity(ServiceRegistry serviceRegistry, byte[] bytes); @Override ConcurrencyStrategy<LeaseMessage> getConcurrencyStrategy(byte[] bytes); @Override MessageCodec<LeaseMessage, LeaseResponse> getMessageCodec(); @Override SyncMessageCodec<LeaseMessage> getSyncMessageCodec();  }