KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tc > objectserver > persistence > impl > InMemoryClassPersistor


1 /*
2  * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
3  */

4 package com.tc.objectserver.persistence.impl;
5
6 import com.tc.exception.TCRuntimeException;
7 import com.tc.objectserver.persistence.api.ClassPersistor;
8
9 import java.util.HashMap JavaDoc;
10 import java.util.Map JavaDoc;
11
12 public class InMemoryClassPersistor implements ClassPersistor {
13
14   Map JavaDoc clazzes = new HashMap JavaDoc();
15
16   public InMemoryClassPersistor() {
17     super();
18   }
19
20   public void storeClass(int clazzId, byte[] clazzBytes) {
21     clazzes.put(new Integer JavaDoc(clazzId), clazzBytes);
22   }
23
24   public byte[] retrieveClass(int clazzId) {
25     byte[] clazzbytes = (byte[]) clazzes.get(new Integer JavaDoc(clazzId));
26     if (clazzbytes == null) { throw new TCRuntimeException("Class bytes not found : " + clazzId); }
27     return clazzbytes;
28   }
29
30   public Map JavaDoc retrieveAllClasses() {
31     return new HashMap JavaDoc(clazzes);
32   }
33
34 }
35
Popular Tags