1 /* 2 * Copyright 2002-2018 the original author or authors. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 module hunt.stomp.core.AbstractMessageReceivingTemplate; 18 19 import hunt.stomp.core.AbstractMessageSendingTemplate; 20 import hunt.stomp.core.MessageReceivingOperations; 21 22 import hunt.stomp.Message; 23 24 import hunt.stomp.converter.MessageConverter; 25 26 /** 27 * An extension of {@link AbstractMessageSendingTemplate} that adds support for 28 * receive style operations as defined by {@link MessageReceivingOperations}. 29 * 30 * @author Mark Fisher 31 * @author Rossen Stoyanchev 32 * @author Stephane Nicoll 33 * @since 4.1 34 * @param (T) the destination type 35 */ 36 abstract class AbstractMessageReceivingTemplate(T) : AbstractMessageSendingTemplate!(T), 37 MessageReceivingOperations!(T) { 38 39 // override 40 41 // public Message!(T) receive() { 42 // return doReceive(getRequiredDefaultDestination()); 43 // } 44 45 // override 46 47 // public Message!(T) receive(T destination) { 48 // return doReceive(destination); 49 // } 50 51 // /** 52 // * Actually receive a message from the given destination. 53 // * @param destination the target destination 54 // * @return the received message, possibly {@code null} if the message could not 55 // * be received, for example due to a timeout 56 // */ 57 58 // protected abstract Message!(T) doReceive(T destination); 59 60 61 // override 62 63 // public <T> T receiveAndConvert(Class!(T) targetClass) { 64 // return receiveAndConvert(getRequiredDefaultDestination(), targetClass); 65 // } 66 67 // override 68 69 // public <T> T receiveAndConvert(T destination, Class!(T) targetClass) { 70 // MessageBase message = doReceive(destination); 71 // if (message !is null) { 72 // return doConvert(message, targetClass); 73 // } 74 // else { 75 // return null; 76 // } 77 // } 78 79 // /** 80 // * Convert from the given message to the given target class. 81 // * @param message the message to convert 82 // * @param targetClass the target class to convert the payload to 83 // * @return the converted payload of the reply message (never {@code null}) 84 // */ 85 86 87 // protected <T> T doConvert(MessageBase message, Class!(T) targetClass) { 88 // MessageConverter messageConverter = getMessageConverter(); 89 // T value = (T) messageConverter.fromMessage(message, targetClass); 90 // if (value is null) { 91 // throw new MessageConversionException(message, "Unable to convert payload [" ~ message.getPayload() + 92 // "] to type [" ~ targetClass ~ "] using converter [" ~ messageConverter ~ "]"); 93 // } 94 // return value; 95 // } 96 97 }