01: /*
02: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
03: */
04: package com.tc.objectserver.persistence.impl;
05:
06: import com.tc.net.protocol.tcm.ChannelID;
07: import com.tc.objectserver.persistence.api.ClientStatePersistor;
08: import com.tc.util.sequence.MutableSequence;
09:
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
16: ClientStatePersistor {
17:
18: private final Map clients = new HashMap();
19: private final MutableSequence connectionIDSequence = new InMemorySequenceProvider();
20:
21: public MutableSequence getConnectionIDSequence() {
22: return this .connectionIDSequence;
23: }
24:
25: public Set loadClientIDs() {
26: synchronized (clients) {
27: return new HashSet(clients.keySet());
28: }
29: }
30:
31: public boolean containsClient(ChannelID id) {
32: synchronized (clients) {
33: return clients.containsKey(id);
34: }
35: }
36:
37: public void saveClientState(ChannelID cid) {
38: synchronized (clients) {
39: if (!containsClient(cid))
40: clients.put(cid, new Object());
41: }
42: }
43:
44: public void deleteClientState(ChannelID id)
45: throws ClientNotFoundException {
46: Object removed = null;
47: synchronized (clients) {
48: removed = clients.remove(id);
49: }
50: if (removed == null)
51: throw new ClientNotFoundException("Client not found: " + id);
52: }
53:
54: }
|