View Javadoc

1   /*
2    * #%L
3    * Bitrepository Access
4    * %%
5    * Copyright (C) 2010 - 2012 The State and University Library, The Royal Library and The State Archives, Denmark
6    * %%
7    * This program is free software: you can redistribute it and/or modify
8    * it under the terms of the GNU Lesser General Public License as 
9    * published by the Free Software Foundation, either version 2.1 of the 
10   * License, or (at your option) any later version.
11   * 
12   * This program is distributed in the hope that it will be useful,
13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15   * GNU General Lesser Public License for more details.
16   * 
17   * You should have received a copy of the GNU General Lesser Public 
18   * License along with this program.  If not, see
19   * <http://www.gnu.org/licenses/lgpl-2.1.html>.
20   * #L%
21   */
22  package org.bitrepository.access.getstatus.conversation;
23  
24  import java.util.Collection;
25  import org.bitrepository.bitrepositorymessages.GetStatusFinalResponse;
26  import org.bitrepository.bitrepositorymessages.GetStatusRequest;
27  import org.bitrepository.bitrepositorymessages.MessageResponse;
28  import org.bitrepository.client.conversation.ConversationContext;
29  import org.bitrepository.client.conversation.PerformingOperationState;
30  import org.bitrepository.client.conversation.selector.SelectedComponentInfo;
31  import org.bitrepository.client.exceptions.UnexpectedResponseException;
32  
33  public class GettingStatus extends PerformingOperationState {
34      private final GetStatusConversationContext context;
35  
36      /*
37      * @param context The conversation context.
38      * @param contributors The list of components the fileIDs should be collected from.
39      */
40      public GettingStatus(GetStatusConversationContext context, Collection<SelectedComponentInfo> contributors) {
41          super(contributors);
42          this.context = context;
43      }
44  
45      @Override
46      protected void generateContributorCompleteEvent(MessageResponse msg) throws UnexpectedResponseException {
47          GetStatusFinalResponse response = (GetStatusFinalResponse) msg;
48          getContext().getMonitor().contributorComplete(
49                  new StatusCompleteContributorEvent(msg.getFrom(), response.getCollectionID(), response.getResultingStatus()));
50      }
51  
52      @Override
53      protected void sendRequest() {
54          GetStatusRequest request = new GetStatusRequest();
55          initializeMessage(request);
56  
57          context.getMonitor().requestSent("Sending GetStatusRequest", activeContributors.keySet().toString());
58          for(String ID : activeContributors.keySet()) {
59              request.setContributor(ID);
60              request.setDestination(activeContributors.get(ID));
61              context.getMessageSender().sendMessage(request);
62          }
63      }
64  
65      @Override
66      protected ConversationContext getContext() {
67          return context;
68      }
69  
70      @Override
71      protected String getPrimitiveName() {
72          return "GetStatus";
73      }
74  }