EMMA Coverage Report (generated Wed Feb 13 07:49:24 ICT 2008)
[all classes][net.sourceforge.hiveboard.model]

COVERAGE SUMMARY FOR SOURCE FILE [AccountRepositoryImpl.java]

nameclass, %method, %block, %line, %
AccountRepositoryImpl.java100% (5/5)100% (11/11)100% (185/185)100% (34/34)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class AccountRepositoryImpl100% (1/1)100% (3/3)100% (125/125)100% (22/22)
AccountRepositoryImpl (Channel): void 100% (1/1)100% (110/110)100% (20/20)
getAccount (int): Account 100% (1/1)100% (7/7)100% (1/1)
getAccounts (): Account [] 100% (1/1)100% (8/8)100% (1/1)
     
class AccountRepositoryImpl$1100% (1/1)100% (2/2)100% (17/17)100% (3/3)
AccountRepositoryImpl$1 (AccountRepositoryImpl): void 100% (1/1)100% (6/6)100% (1/1)
pushEvent (Event): void 100% (1/1)100% (11/11)100% (2/2)
     
class AccountRepositoryImpl$2100% (1/1)100% (2/2)100% (15/15)100% (3/3)
AccountRepositoryImpl$2 (AccountRepositoryImpl): void 100% (1/1)100% (6/6)100% (1/1)
pushEvent (Event): void 100% (1/1)100% (9/9)100% (2/2)
     
class AccountRepositoryImpl$3100% (1/1)100% (2/2)100% (14/14)100% (3/3)
AccountRepositoryImpl$3 (AccountRepositoryImpl): void 100% (1/1)100% (6/6)100% (1/1)
pushEvent (Event): void 100% (1/1)100% (8/8)100% (2/2)
     
class AccountRepositoryImpl$4100% (1/1)100% (2/2)100% (14/14)100% (3/3)
AccountRepositoryImpl$4 (AccountRepositoryImpl): void 100% (1/1)100% (6/6)100% (1/1)
pushEvent (Event): void 100% (1/1)100% (8/8)100% (2/2)

1//  Copyright 2004-2007 Jean-Francois Poilpret
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14 
15package net.sourceforge.hiveboard.model;
16 
17import java.util.HashMap;
18import java.util.Map;
19 
20import net.sourceforge.hiveboard.Account;
21import net.sourceforge.hiveboard.Event;
22import net.sourceforge.hiveboard.EventType;
23import net.sourceforge.hiveboard.event.ConstraintEventFilter;
24import net.sourceforge.hiveboard.event.Constraints;
25import net.sourceforge.hiveboard.event.EventsPriorities;
26import net.sourceforge.hiveboard.event.PersistentDeferredConsumer;
27import net.sourceforge.hiveevents.Channel;
28import net.sourceforge.hiveevents.Filter;
29 
30/**
31 * Service acting as a memory repository of all active Accounts in the system.
32 * <p>
33 * This service must use the singleton service model.
34 *
35 * @author Jean-Francois Poilpret
36 */
37public class AccountRepositoryImpl implements AccountRepository
38{
39        public AccountRepositoryImpl(Channel<Event> eventChannel)
40        {
41                // Add events listeners                
42                int priority = EventsPriorities.ACCOUNT_REPOSITORY_UPDATE;
43                String constraint = Constraints.eventType(        EventType.EVT_CREATE_ACCOUNT,
44                                                                                                        EventType.EVT_MODIFY_ACCOUNT);
45                Filter<Event> filter = new ConstraintEventFilter(constraint);
46                PersistentDeferredConsumer consumer = new PersistentDeferredConsumer()
47                {
48                        @Override protected void pushEvent(Event event)
49                        {
50                                _accounts.put(event.getWho(), event.getAccount());
51                        }
52                };
53 
54                eventChannel.registerPushConsumer(priority, filter, consumer);
55 
56                constraint = Constraints.eventType(EventType.EVT_DESTROY_ACCOUNT);
57                filter = new ConstraintEventFilter(constraint);
58                consumer = new PersistentDeferredConsumer()
59                {
60                        @Override protected void pushEvent(Event event)
61                        {
62                                _accounts.remove(event.getWho());
63                        }
64                };
65                eventChannel.registerPushConsumer(priority, filter, consumer);
66 
67                constraint = Constraints.eventType(EventType.EVT_LOGIN);
68                filter = new ConstraintEventFilter(constraint);
69                consumer = new PersistentDeferredConsumer()
70                {
71                        @Override protected void pushEvent(Event event)
72                        {
73                                getAccount(event.getWho()).setConnected(true);
74                        }
75                };
76                eventChannel.registerPushConsumer(priority, filter, consumer);
77 
78                constraint = Constraints.eventType(EventType.EVT_LOGOUT);
79                filter = new ConstraintEventFilter(constraint);
80                consumer = new PersistentDeferredConsumer()
81                {
82                        @Override protected void pushEvent(Event event)
83                        {
84                                getAccount(event.getWho()).setConnected(false);
85                        }
86                };
87                eventChannel.registerPushConsumer(priority, filter, consumer);
88        }
89        
90        public Account                getAccount(int id)
91        {
92                return _accounts.get(id);
93        }
94        
95        public Account[]        getAccounts()
96        {
97                return _accounts.values().toArray(new Account[0]);
98        }
99 
100        protected final Map<Integer, Account>        _accounts = new HashMap<Integer, Account>();
101}

[all classes][net.sourceforge.hiveboard.model]
EMMA 2.0.5312 (C) Vladimir Roubtsov