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.wicket.protocol.ws.api;
018
019import org.apache.wicket.protocol.http.WebApplication;
020import org.apache.wicket.protocol.ws.WebSocketSettings;
021
022/**
023 * Processes web socket messages.
024 *
025 * @since 6.0
026 */
027public interface IWebSocketProcessor
028{
029        /**
030         * Called when then {@link org.apache.wicket.protocol.ws.api.IWebSocketSession} is being opened: to allow to configure
031         * the underlying web socket session.
032         *
033         * @param webSocketSession
034         *                      the {@link org.apache.wicket.protocol.ws.api.IWebSocketSession}
035         * @param application
036         *          the {@link org.apache.wicket.protocol.http.WebApplication}
037         */
038        default void onOpen(IWebSocketSession webSocketSession, final WebApplication application) {
039                // find the current org.apache.wicket.protocol.ws.api.IWebSocketSessionConfigurer and use it
040                // in order to configure the session
041                WebSocketSettings.Holder.get(application).getSocketSessionConfigurer().configureSession(webSocketSession);
042        }
043
044        /**
045         * Called when a text message arrives from the client
046         *
047         * @param message
048         *      the text message from the client
049         */
050        void onMessage(final String message);
051
052        /**
053         * Called when a binary message arrives from the client
054         *
055         * @param data
056         *      the binary message from the client
057         * @param offset
058         *      the offset to read from
059         * @param length
060         *      how much data to read
061         */
062        void onMessage(byte[] data, int offset, int length);
063
064        /**
065         * A client successfully has made a web socket connection.
066         *
067         * @param containerConnection
068         *      the web socket connection to use to communicate with the client
069         */
070        void onOpen(Object containerConnection);
071
072        /**
073         * A notification after the close of the web socket connection.
074         * The connection could be closed by either the client or the server
075         *
076         * @param closeCode
077         *              The close code
078         * @param message
079         *          the message
080         */
081        void onClose(int closeCode, String message);
082
083        /**
084         * A notification after a communication error.
085         *
086         * @param t
087         *      The throwable for the communication problem
088         */
089        void onError(Throwable t);
090}