001 /*
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements. See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership. The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License. You may obtain a copy of the License at
009 *
010 * http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing,
013 * software distributed under the License is distributed on an
014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015 * KIND, either express or implied. See the License for the
016 * specific language governing permissions and limitations
017 * under the License.
018 */
019
020 package org.apache.geronimo.gshell.whisper.request;
021
022 import org.apache.geronimo.gshell.common.tostring.ToStringBuilder;
023 import org.apache.geronimo.gshell.common.tostring.ToStringStyle;
024 import org.apache.geronimo.gshell.whisper.message.Message;
025
026 //
027 // NOTE: Snatched and massaged from Apache Mina
028 //
029
030 /**
031 * Represents a response to a request message.
032 *
033 * @version $Rev: 580691 $ $Date: 2007-09-30 03:36:37 -0700 (Sun, 30 Sep 2007) $
034 */
035 public class ResponseHandle
036 {
037 private final RequestHandle request;
038
039 private final Type type;
040
041 private final Message message;
042
043 public ResponseHandle(final RequestHandle request, final Message message, final Type type) {
044 this.request = request;
045 this.type = type;
046 this.message = message;
047 }
048
049 public int hashCode() {
050 return getRequest().getId().hashCode();
051 }
052
053 public boolean equals(Object obj) {
054 if (obj == this) {
055 return true;
056 }
057 else if (obj == null) {
058 return false;
059 }
060 else if (!(obj instanceof ResponseHandle)) {
061 return false;
062 }
063
064 ResponseHandle resp = (ResponseHandle) obj;
065
066 return getRequest().equals(resp.getRequest()) && getType().equals(resp.getType());
067 }
068
069 public String toString() {
070 return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE)
071 .append("id", getId())
072 .append("responseTo", getRequest().getId())
073 .append("message", message)
074 .toString();
075 }
076
077 public RequestHandle getRequest() {
078 return request;
079 }
080
081 public Type getType() {
082 return type;
083 }
084
085 public Message getMessage() {
086 return message;
087 }
088
089 public Message.ID getId() {
090 return getMessage().getId();
091 }
092
093 //
094 // Response Type
095 //
096
097 public static enum Type
098 {
099 WHOLE,
100 PARTIAL,
101 PARTIAL_LAST
102 }
103 }