1 4 package com.tc.objectserver.persistence.impl; 5 6 import com.tc.net.protocol.tcm.ChannelID; 7 import com.tc.objectserver.persistence.api.ClientStatePersistor; 8 import com.tc.objectserver.persistence.api.PersistentSequence; 9 10 import java.util.HashMap ; 11 import java.util.HashSet ; 12 import java.util.Map ; 13 import java.util.Set ; 14 15 public class InMemoryClientStatePersistor implements ClientStatePersistor { 16 17 private final Map clients = new HashMap (); 18 private final PersistentSequence connectionIDSequence = new InMemorySequenceProvider(); 19 20 public PersistentSequence getConnectionIDSequence() { 21 return this.connectionIDSequence; 22 } 23 24 public Set loadClientIDs() { 25 synchronized (clients) { 26 return new HashSet (clients.keySet()); 27 } 28 } 29 30 public boolean containsClient(ChannelID id) { 31 synchronized (clients) { 32 return clients.containsKey(id); 33 } 34 } 35 36 public void saveClientState(ChannelID cid) { 37 synchronized (clients) { 38 if (!containsClient(cid)) clients.put(cid, new Object ()); 39 } 40 } 41 42 public void deleteClientState(ChannelID id) throws ClientNotFoundException { 43 Object removed = null; 44 synchronized (clients) { 45 removed = clients.remove(id); 46 } 47 if (removed == null) throw new ClientNotFoundException("Client not found: " + id); 48 } 49 50 } 51 | Popular Tags |