View Javadoc

1   /*
2    * #%L
3    * bitrepository-access-client
4    * *
5    * $Id$
6    * $HeadURL$
7    * %%
8    * Copyright (C) 2010 - 2011 The State and University Library, The Royal Library and The State Archives, Denmark
9    * %%
10   * This program is free software: you can redistribute it and/or modify
11   * it under the terms of the GNU Lesser General Public License as 
12   * published by the Free Software Foundation, either version 2.1 of the 
13   * License, or (at your option) any later version.
14   * 
15   * This program is distributed in the hope that it will be useful,
16   * but WITHOUT ANY WARRANTY; without even the implied warranty of
17   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18   * GNU General Lesser Public License for more details.
19   * 
20   * You should have received a copy of the GNU General Lesser Public 
21   * License along with this program.  If not, see
22   * <http://www.gnu.org/licenses/lgpl-2.1.html>.
23   * #L%
24   */
25  package org.bitrepository.pillar.referencepillar.messagehandler;
26  
27  import java.util.ArrayList;
28  import java.util.List;
29  
30  import org.bitrepository.common.filestore.FileStore;
31  import org.bitrepository.pillar.common.MessageHandlerContext;
32  import org.bitrepository.pillar.common.PillarMediator;
33  import org.bitrepository.pillar.referencepillar.archive.ReferenceChecksumManager;
34  import org.bitrepository.protocol.messagebus.MessageBus;
35  import org.bitrepository.service.contributor.handler.GetAuditTrailsRequestHandler;
36  import org.bitrepository.service.contributor.handler.GetStatusRequestHandler;
37  import org.bitrepository.service.contributor.handler.IdentifyContributorsForGetAuditTrailsRequestHandler;
38  import org.bitrepository.service.contributor.handler.IdentifyContributorsForGetStatusRequestHandler;
39  import org.bitrepository.service.contributor.handler.RequestHandler;
40  
41  /**
42   * This instance handles the conversations for the reference pillar.
43   * It only responds to requests. It does not it self start conversations, though it might send Alarms when something 
44   * is not right.
45   * All other messages than requests are considered garbage.
46   * Every message (even garbage) is put into the audit trails.
47   */
48  public class ReferencePillarMediator extends PillarMediator {
49      /**
50       * The archive for this pillar mediator.
51       */
52      private final FileStore archives;
53      /** The manager of the checksums.*/
54      private final ReferenceChecksumManager csManager;
55      
56      /**
57       * Constructor.
58       * @param messageBus The message bus to listen to.
59       * @param context The context for the pillar.
60       * @param archives The manager of the archives with regards to the collection ids.
61       * @param manager The manager of checksums.
62       */
63      public ReferencePillarMediator(MessageBus messageBus, MessageHandlerContext context, 
64              FileStore archives, ReferenceChecksumManager manager) {
65          super(messageBus, context);
66          this.archives = archives;
67          this.csManager = manager;
68      }
69  
70      @SuppressWarnings("rawtypes")
71      @Override
72      protected RequestHandler[] createListOfHandlers() {
73          List<RequestHandler> handlers = new ArrayList<RequestHandler>();
74          
75          handlers.add(new IdentifyPillarsForGetFileRequestHandler(context, archives, csManager));
76          handlers.add(new GetFileRequestHandler(context, archives, csManager));
77          handlers.add(new IdentifyPillarsForGetFileIDsRequestHandler(context, archives, csManager));
78          handlers.add(new GetFileIDsRequestHandler(context, archives, csManager));
79          handlers.add(new IdentifyPillarsForGetChecksumsRequestHandler(context, archives, csManager));
80          handlers.add(new GetChecksumsRequestHandler(context, archives, csManager));
81          
82          handlers.add(new IdentifyContributorsForGetStatusRequestHandler(getContext()));
83          handlers.add(new GetStatusRequestHandler(getContext()));
84          handlers.add(new IdentifyContributorsForGetAuditTrailsRequestHandler(getContext()));
85          handlers.add(new GetAuditTrailsRequestHandler(getContext(), context.getAuditTrailManager()));
86          
87          handlers.add(new IdentifyPillarsForPutFileRequestHandler(context, archives, csManager));
88          handlers.add(new PutFileRequestHandler(context, archives, csManager));
89          handlers.add(new IdentifyPillarsForDeleteFileRequestHandler(context, archives, csManager));
90          handlers.add(new DeleteFileRequestHandler(context, archives, csManager));
91          handlers.add(new IdentifyPillarsForReplaceFileRequestHandler(context, archives, csManager));
92          handlers.add(new ReplaceFileRequestHandler(context, archives, csManager));
93          
94          return handlers.toArray(new RequestHandler[handlers.size()]);
95      }    
96  }