| 1 | package com.hammurapi.eventbus.local; |
| 2 | |
| 3 | import java.util.concurrent.locks.ReadWriteLock; |
| 4 | |
| 5 | import com.hammurapi.eventbus.AbstractEventBus; |
| 6 | import com.hammurapi.eventbus.HandleExtractor; |
| 7 | import com.hammurapi.extract.Predicate; |
| 8 | import com.hammurapi.store.AbstractStore; |
| 9 | import com.hammurapi.store.DeputyStore; |
| 10 | import com.hammurapi.store.LiveView; |
| 11 | import com.hammurapi.store.UnmodifiableStore; |
| 12 | import com.hammurapi.store.local.LocalStoreBase; |
| 13 | |
| 14 | /** |
| 15 | * Implementation of event store. |
| 16 | * @author Pavel Vlasov |
| 17 | * |
| 18 | * @param <E> |
| 19 | * @param <P> |
| 20 | * @param <C> |
| 21 | */ |
| 22 | public class LocalEventStoreImpl<E,P extends Comparable<P>,C> extends LocalStoreBase<AbstractEventBus.Handle<E,P,C,Long>, E, LocalEventStore<E,P,C>> implements LocalEventStore<E,P,C> { |
| 23 | |
| 24 | /** |
| 25 | * Config class with bound generic parameters. |
| 26 | * @author Pavel Vlasov |
| 27 | * |
| 28 | */ |
| 29 | public static class Config<E,P extends Comparable<P>,C> extends LocalStoreBase.Config<AbstractEventBus.Handle<E,P,C,Long>, E, LocalEventStore<E,P,C>> { |
| 30 | |
| 31 | public Config() { |
| 32 | setPrimaryKeyExtractor(new HandleExtractor<E, P, C, Long, AbstractEventBus.Handle<E,P,C,Long>, LocalEventStore<E,P,C>>()); |
| 33 | } |
| 34 | } |
| 35 | |
| 36 | public LocalEventStoreImpl(Config<E,P,C> config) { |
| 37 | super(config); |
| 38 | } |
| 39 | |
| 40 | protected static class LocalEventDeputyStore<E,P extends Comparable<P>,C> extends DeputyStore<AbstractEventBus.Handle<E,P,C,Long>, E, LocalEventStore<E,P,C>> implements LocalEventStore<E,P,C> { |
| 41 | |
| 42 | public LocalEventDeputyStore( |
| 43 | AbstractStore<AbstractEventBus.Handle<E, P, C, Long>, E, LocalEventStore<E, P, C>> master, |
| 44 | ReadWriteLock masterLock) { |
| 45 | super(master, masterLock); |
| 46 | } |
| 47 | |
| 48 | @Override |
| 49 | protected LocalEventStore<E,P,C> createDeputy() { |
| 50 | return new LocalEventDeputyStore<E,P,C>(this, createMasterLock()); |
| 51 | } |
| 52 | |
| 53 | @Override |
| 54 | public LocalEventStore<E,P,C> createUnmodifiableFacade() { |
| 55 | return new LocalEventUnmodifiableStore<E,P,C>(this); |
| 56 | } |
| 57 | |
| 58 | @Override |
| 59 | protected LocalEventStore<E,P,C> createLiveView(Predicate<AbstractEventBus.Handle<E,P,C,Long>, LocalEventStore<E,P,C>> selector) { |
| 60 | return new LocalEventLiveView<E,P,C>(this, selector); |
| 61 | } |
| 62 | |
| 63 | } |
| 64 | |
| 65 | protected static class LocalEventUnmodifiableStore<E,P extends Comparable<P>,C> extends UnmodifiableStore<AbstractEventBus.Handle<E,P,C,Long>, E, LocalEventStore<E,P,C>> implements LocalEventStore<E,P,C> { |
| 66 | |
| 67 | public LocalEventUnmodifiableStore(LocalEventStore<E, P, C> master) { |
| 68 | super(master); |
| 69 | } |
| 70 | |
| 71 | |
| 72 | } |
| 73 | |
| 74 | protected static class LocalEventLiveView<E,P extends Comparable<P>,C> extends LiveView<AbstractEventBus.Handle<E,P,C,Long>, E, LocalEventStore<E,P,C>> implements LocalEventStore<E,P,C> { |
| 75 | |
| 76 | public LocalEventLiveView( |
| 77 | LocalEventStore<E, P, C> master, |
| 78 | Predicate<AbstractEventBus.Handle<E, P, C, Long>, LocalEventStore<E, P, C>> selector) { |
| 79 | super(master, selector); |
| 80 | } |
| 81 | |
| 82 | @Override |
| 83 | public LocalEventStore<E,P,C> createUnmodifiableFacade() { |
| 84 | return new LocalEventUnmodifiableStore(this); |
| 85 | } |
| 86 | |
| 87 | } |
| 88 | |
| 89 | @Override |
| 90 | protected LocalEventStore<E,P,C> createDeputy() { |
| 91 | return new LocalEventDeputyStore<E,P,C>(this, createMasterLock()); |
| 92 | } |
| 93 | |
| 94 | @Override |
| 95 | public LocalEventStore<E,P,C> createUnmodifiableFacade() { |
| 96 | return new LocalEventUnmodifiableStore<E,P,C>(this); |
| 97 | } |
| 98 | |
| 99 | @Override |
| 100 | protected LocalEventStore<E,P,C> createLiveView(Predicate<AbstractEventBus.Handle<E,P,C,Long>, LocalEventStore<E,P,C>> selector) { |
| 101 | return new LocalEventLiveView<E,P,C>(this, selector); |
| 102 | } |
| 103 | |
| 104 | } |