Skip to content

Package: ClientEndpoint

ClientEndpoint

Coverage

1: /*
2: * Copyright (c) 2018, 2019 Oracle and/or its affiliates and others.
3: * All rights reserved.
4: *
5: * This program and the accompanying materials are made available under the
6: * terms of the Eclipse Public License v. 2.0, which is available at
7: * http://www.eclipse.org/legal/epl-2.0.
8: *
9: * This Source Code may also be made available under the following Secondary
10: * Licenses when the conditions for such availability set forth in the
11: * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
12: * version 2 with the GNU Classpath Exception, which is available at
13: * https://www.gnu.org/software/classpath/license.html.
14: *
15: * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
16: */
17:
18: package jakarta.websocket;
19:
20: import java.lang.annotation.ElementType;
21: import java.lang.annotation.Retention;
22: import java.lang.annotation.RetentionPolicy;
23: import java.lang.annotation.Target;
24:
25: /**
26: * The ClientEndpoint annotation a class level annotation is used to denote that a POJO is a web socket client and can
27: * be deployed as such. Similar to {@code jakarta.websocket.server.ServerEndpoint}, POJOs that are annotated with this
28: * annotation can have methods that, using the web socket method level annotations, are web socket lifecycle methods.
29: * <p>
30: * For example:
31: *
32: * <pre>
33: * <code>
34: * @ClientEndpoint(subprotocols="chat")
35: * public class HelloServer {
36: *
37: * @OnMessage
38: * public void processMessageFromServer(String message, Session session) {
39: * System.out.println("Message came from the server ! " + message);
40: * }
41: *
42: * }
43: * </code>
44: * </pre>
45: *
46: * @author dannycoward
47: */
48: @Retention(RetentionPolicy.RUNTIME)
49: @Target(ElementType.TYPE)
50: public @interface ClientEndpoint {
51:
52: /**
53: * The names of the subprotocols this client supports.
54: *
55: * @return the array of names of the subprotocols.
56: */
57: String[] subprotocols() default {};
58:
59: /**
60: * The array of Java classes that are to act as Decoders for messages coming into the client.
61: *
62: * @return the array of decoders.
63: */
64: Class<? extends Decoder>[] decoders() default {};
65:
66: /**
67: * The array of Java classes that are to act as Encoders for messages sent by the client.
68: *
69: * @return the array of decoders.
70: */
71: Class<? extends Encoder>[] encoders() default {};
72:
73: /**
74: * An optional custom configurator class that the developer would like to use to provide custom configuration of new
75: * instances of this endpoint. The implementation creates a new instance of the configurator per logical endpoint.
76: *
77: * @return the custom configurator class, or ClientEndpointConfigurator.class if none was provided in the
78: * annotation.
79: */
80: public Class<? extends ClientEndpointConfig.Configurator> configurator() default ClientEndpointConfig.Configurator.class;
81: }