KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ozoneDB > core > storage > gammaStore > Deleter


1 // You can redistribute this software and/or modify it under the terms of
2
// the Ozone Core License version 1 published by ozone-db.org.
3
//
4
// Copyright (C) 2003-@year@, Leo Mekenkamp. All rights reserved.
5
//
6
// $Id: Deleter.java,v 1.1.2.1 2004/03/28 16:40:03 per_nyfelt Exp $
7

8 package org.ozoneDB.core.storage.gammaStore;
9
10 import java.io.ByteArrayOutputStream JavaDoc;
11 import java.io.IOException JavaDoc;
12 import java.io.ObjectOutputStream JavaDoc;
13 import java.util.Collections JavaDoc;
14 import java.util.HashSet JavaDoc;
15 import java.util.Iterator JavaDoc;
16 import java.util.LinkedHashMap JavaDoc;
17 import java.util.LinkedHashSet JavaDoc;
18 import java.util.Map JavaDoc;
19 import java.util.Set JavaDoc;
20 import java.util.Map.Entry;
21 import java.util.logging.Level JavaDoc;
22 import java.util.logging.Logger JavaDoc;
23 import org.ozoneDB.OzoneInternalException;
24
25 /**
26  * <p>Takes care of <code>Storable</code> implemeting instances, in that it
27  * has different threads for serializing and writing to <code>Storage</code>.
28  * <code>Remove()</code> ensures that if a null is
29  * returned that the <code>Storable</code> for the given key has been
30  * completely written to <code>Storage</code>.</p>
31  *
32  * <p>For every instance of this class 2 threads are created, so keep this in
33  * mind when creating instances; this might be a resource hog...</p>
34  *
35  * @author leo
36  */

37 public class Deleter {
38     
39     private class DeleteTask implements Runnable JavaDoc {
40     
41         private Storable storable;
42         private StorageFactory storageFactory;
43         
44         DeleteTask(Storable storable, StorageFactory storageFactory) {
45             this.storable = storable;
46             this.storageFactory = storageFactory;
47         }
48         
49         public void run() {
50             try {
51                 storageFactory.delete(storable.getStorageName());
52             } catch (IOException JavaDoc e) {
53                 throw new OzoneInternalException(e);
54             }
55         }
56         
57         public boolean equals(Object JavaDoc obj) {
58             return false;
59         }
60         
61     }
62     
63     private static final Logger JavaDoc log = Logger.getLogger(Deleter.class.getName());
64     
65     private AsyncExec asyncExec;
66
67     public Deleter(String JavaDoc name) {
68         asyncExec = new AsyncExec(name, Thread.MIN_PRIORITY, true);
69     }
70     
71     /**
72      * Places a storable into a delete queue. Works like 'Fire and forget'.
73      */

74     public void delete(Storable storable, StorageFactory storageFactory) {
75         if (log.isLoggable(Level.FINER)) log.finer("enqueueing " + storable + " for deletion");
76         DeleteTask deleteTask = new DeleteTask(storable, storageFactory);
77         asyncExec.put(deleteTask, deleteTask);
78     }
79     
80     public int size() {
81         return asyncExec.size();
82     }
83     
84     public void stopWhenReady() {
85         asyncExec.stopWhenReady();
86     }
87     
88 }
89
Popular Tags