001/*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements.  See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License.  You may obtain a copy of the License at
008 *
009 *      http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017package org.apache.juneau.console.bus;
018
019import org.apache.juneau.marshall.collections.*;
020
021/**
022 * Handles one upstream topic (page → server, WebSocket bridges only).  Runs on the container's WebSocket thread;
023 * keep it short or hand off.  An exception is logged and answered with a generic {@code bus:upstream-failed} frame.
024 *
025 * <h5 class='section'>Example:</h5>
026 * <p class='bjava'>
027 *   UpstreamHandler <jv>cancelAll</jv> = (<jv>session</jv>, <jv>topic</jv>, <jv>payload</jv>) -&gt; {
028 *     <jv>jobs</jv>.running().forEach(AsyncJob::cancel);
029 *   };
030 *   BusPolicy.<jsm>create</jsm>().upstream(<js>"ops.cancel-all"</js>, <jv>cancelAll</jv>);
031 * </p>
032 *
033 * @since 10.0.0
034 */
035@FunctionalInterface
036public interface UpstreamHandler {
037
038   /**
039    * Handles one upstream publish.
040    *
041    * @param session The session that sent it.  Never <jk>null</jk>.
042    * @param topic The topic, already checked against the session's upstream grant.
043    * @param payload The JSON-object payload.  Never <jk>null</jk>.
044    * @throws Exception Any failure; it is logged and never crosses the wire.
045    */
046   @SuppressWarnings({
047      "java:S112" // SPI: any implementer failure is logged and never crosses the wire
048   })
049   void handle(BusSession session, String topic, JsonMap payload) throws Exception;
050}