View Javadoc

1   /*
2    * #%L
3    * Bitrepository Service
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.service.contributor;
23  
24  import org.bitrepository.bitrepositorymessages.MessageRequest;
25  import org.bitrepository.bitrepositorymessages.MessageResponse;
26  import org.bitrepository.common.settings.Settings;
27  import org.bitrepository.protocol.messagebus.MessageSender;
28  
29  /**
30   * Provides the general functionality for sending reponses from a contributor.
31   */
32  public class ResponseDispatcher extends MessageDispatcher {
33  
34      public ResponseDispatcher(Settings settings, MessageSender sender) {
35          super(settings, sender);
36      }
37  
38      /**
39       * Completes and sends a given response.
40       * All the values of the specific response elements has to be set, including the ResponseInfo.
41       * <br/> Sets the fields:
42       * <br/> CollectionID
43       * <br/> CorrelationID
44       * <br/> From
45       * <br/> MinVersion
46       * <br/> ReplyTo
47       * <br/> To
48       * <br/> Version
49       *
50       * @param response The response which only needs the basic information to be send.
51       * @param request The original request to respond to.
52       */
53      public void dispatchResponse(MessageResponse response, MessageRequest request) {
54          response.setCorrelationID(request.getCorrelationID());
55          response.setCollectionID(request.getCollectionID());
56          response.setReplyTo(settings.getContributorDestinationID());
57          response.setDestination(request.getReplyTo());
58          response.setTo(request.getFrom());
59          dispatchMessage(response);
60      }
61  }