001/*
002 * Copyright 2002-2018 the original author or authors.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *      https://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016
017package org.springframework.jms.core;
018
019import javax.jms.JMSException;
020import javax.jms.Session;
021
022import org.springframework.lang.Nullable;
023
024/**
025 * Callback for executing any number of operations on a provided {@link Session}.
026 *
027 * <p>To be used with the {@link JmsTemplate#execute(SessionCallback)} method,
028 * often implemented as an anonymous inner class or as a lambda expression.
029 *
030 * @author Mark Pollack
031 * @since 1.1
032 * @param <T> the result type
033 * @see JmsTemplate#execute(SessionCallback)
034 */
035@FunctionalInterface
036public interface SessionCallback<T> {
037
038        /**
039         * Execute any number of operations against the supplied JMS {@link Session},
040         * possibly returning a result.
041         * @param session the JMS {@code Session}
042         * @return a result object from working with the {@code Session}, if any
043         * (or {@code null} if none)
044         * @throws javax.jms.JMSException if thrown by JMS API methods
045         */
046        @Nullable
047        T doInJms(Session session) throws JMSException;
048
049}