blob: 2998791deae5c3402e8b6d7b2a0fb7dfc6c1b7f5 [file] [log] [blame]
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<!-- NewPage -->
<html lang="en">
<head>
<title>Endpoint</title>
<link rel="stylesheet" type="text/css" href="../../stylesheet.css" title="Style">
<script type="text/javascript" src="../../script.js"></script>
</head>
<body>
<script type="text/javascript"><!--
try {
if (location.href.indexOf('is-external=true') == -1) {
parent.document.title="Endpoint";
}
}
catch(err) {
}
//-->
var methods = {"i0":10,"i1":10,"i2":6};
var tabs = {65535:["t0","All Methods"],2:["t2","Instance Methods"],4:["t3","Abstract Methods"],8:["t4","Concrete Methods"]};
var altColor = "altColor";
var rowColor = "rowColor";
var tableTab = "tableTab";
var activeTableTab = "activeTableTab";
</script>
<noscript>
<div>JavaScript is disabled on your browser.</div>
</noscript>
<!-- ========= START OF TOP NAVBAR ======= -->
<div class="topNav"><a name="navbar.top">
<!-- -->
</a>
<div class="skipNav"><a href="#skip.navbar.top" title="Skip navigation links">Skip navigation links</a></div>
<a name="navbar.top.firstrow">
<!-- -->
</a>
<ul class="navList" title="Navigation">
<li><a href="../../overview-summary.html">Overview</a></li>
<li><a href="package-summary.html">Package</a></li>
<li class="navBarCell1Rev">Class</li>
<li><a href="package-tree.html">Tree</a></li>
<li><a href="../../deprecated-list.html">Deprecated</a></li>
<li><a href="../../index-all.html">Index</a></li>
<li><a href="../../help-doc.html">Help</a></li>
</ul>
</div>
<div class="subNav">
<ul class="navList">
<li><a href="../../javax/websocket/Encoder.TextStream.html" title="interface in javax.websocket"><span class="typeNameLink">Prev&nbsp;Class</span></a></li>
<li><a href="../../javax/websocket/EndpointConfig.html" title="interface in javax.websocket"><span class="typeNameLink">Next&nbsp;Class</span></a></li>
</ul>
<ul class="navList">
<li><a href="../../index.html?javax/websocket/Endpoint.html" target="_top">Frames</a></li>
<li><a href="Endpoint.html" target="_top">No&nbsp;Frames</a></li>
</ul>
<ul class="navList" id="allclasses_navbar_top">
<li><a href="../../allclasses-noframe.html">All&nbsp;Classes</a></li>
</ul>
<div>
<script type="text/javascript"><!--
allClassesLink = document.getElementById("allclasses_navbar_top");
if(window==top) {
allClassesLink.style.display = "block";
}
else {
allClassesLink.style.display = "none";
}
//-->
</script>
</div>
<div>
<ul class="subNavList">
<li>Summary:&nbsp;</li>
<li>Nested&nbsp;|&nbsp;</li>
<li>Field&nbsp;|&nbsp;</li>
<li><a href="#constructor.summary">Constr</a>&nbsp;|&nbsp;</li>
<li><a href="#method.summary">Method</a></li>
</ul>
<ul class="subNavList">
<li>Detail:&nbsp;</li>
<li>Field&nbsp;|&nbsp;</li>
<li><a href="#constructor.detail">Constr</a>&nbsp;|&nbsp;</li>
<li><a href="#method.detail">Method</a></li>
</ul>
</div>
<a name="skip.navbar.top">
<!-- -->
</a></div>
<!-- ========= END OF TOP NAVBAR ========= -->
<!-- ======== START OF CLASS DATA ======== -->
<div class="header">
<div class="subTitle">javax.websocket</div>
<h2 title="Class Endpoint" class="title">Class Endpoint</h2>
</div>
<div class="contentContainer">
<ul class="inheritance">
<li>java.lang.Object</li>
<li>
<ul class="inheritance">
<li>javax.websocket.Endpoint</li>
</ul>
</li>
</ul>
<div class="description">
<ul class="blockList">
<li class="blockList">
<hr>
<br>
<pre>public abstract class <span class="typeNameLabel">Endpoint</span>
extends java.lang.Object</pre>
<div class="block">The Web Socket Endpoint represents an object that can handle websocket conversations. Developers may extend this
class in order to implement a programmatic websocket endpoint. The Endpoint class holds lifecycle methods that may be
overridden to intercept websocket open, error and close events. By implementing the
<a href="../../javax/websocket/Endpoint.html#onOpen-javax.websocket.Session-javax.websocket.EndpointConfig-"><code>onOpen</code></a> method, the programmatic
endpoint gains access to the <a href="../../javax/websocket/Session.html" title="interface in javax.websocket"><code>Session</code></a> object, to which the developer may add <a href="../../javax/websocket/MessageHandler.html" title="interface in javax.websocket"><code>MessageHandler</code></a>
implementations in order to intercept incoming websocket messages. Each instance of a websocket endpoint is
guaranteed not to be called by more than one thread at a time per active connection.
<p>
If deployed as a client endpoint, it will be instantiated once for the single connection to the server.
<p>
When deployed as a server endpoint, the implementation uses the
<code>javax.websocket.server.ServerEndpointConfig.Configurator#getEndpointInstance</code> method to obtain the endpoint
instance it will use for each new client connection. If the developer uses the default
<code>javax.websocket.server.ServerEndpointConfig.Configurator</code>, there will be precisely one endpoint instance per
active client connection. Consequently, in this typical case, when implementing/overriding the methods of Endpoint,
the developer is guaranteed that there will be at most one thread calling each endpoint instance at a time.
<p>
If the developer provides a custom <code>javax.websocket.server.ServerEndpointConfig.Configurator</code> which overrides
the default policy for endpoint instance creation, for example, using a single Endpoint instance for multiple client
connections, the developer may need to write code that can execute concurrently.
<p>
Here is an example of a simple endpoint that echoes any incoming text message back to the sender.
<pre>
<code>
public class EchoServer extends Endpoint {
public void onOpen(Session session, EndpointConfig config) {
final RemoteEndpoint remote = session.getBasicRemote();
session.addMessageHandler(String.class, new MessageHandler.Whole&lt;String&lt;() {
public void onMessage(String text) {
try {
remote.sendString("Got your message (" + text + "). Thanks !");
} catch (IOException ioe) {
// handle send failure here
}
}
});
}
}
</code>
</pre></div>
</li>
</ul>
</div>
<div class="summary">
<ul class="blockList">
<li class="blockList">
<!-- ======== CONSTRUCTOR SUMMARY ======== -->
<ul class="blockList">
<li class="blockList"><a name="constructor.summary">
<!-- -->
</a>
<h3>Constructor Summary</h3>
<table class="memberSummary" border="0" cellpadding="3" cellspacing="0" summary="Constructor Summary table, listing constructors, and an explanation">
<caption><span>Constructors</span><span class="tabEnd">&nbsp;</span></caption>
<tr>
<th class="colOne" scope="col">Constructor and Description</th>
</tr>
<tr class="altColor">
<td class="colOne"><code><span class="memberNameLink"><a href="../../javax/websocket/Endpoint.html#Endpoint--">Endpoint</a></span>()</code>&nbsp;</td>
</tr>
</table>
</li>
</ul>
<!-- ========== METHOD SUMMARY =========== -->
<ul class="blockList">
<li class="blockList"><a name="method.summary">
<!-- -->
</a>
<h3>Method Summary</h3>
<table class="memberSummary" border="0" cellpadding="3" cellspacing="0" summary="Method Summary table, listing methods, and an explanation">
<caption><span id="t0" class="activeTableTab"><span>All Methods</span><span class="tabEnd">&nbsp;</span></span><span id="t2" class="tableTab"><span><a href="javascript:show(2);">Instance Methods</a></span><span class="tabEnd">&nbsp;</span></span><span id="t3" class="tableTab"><span><a href="javascript:show(4);">Abstract Methods</a></span><span class="tabEnd">&nbsp;</span></span><span id="t4" class="tableTab"><span><a href="javascript:show(8);">Concrete Methods</a></span><span class="tabEnd">&nbsp;</span></span></caption>
<tr>
<th class="colFirst" scope="col">Modifier and Type</th>
<th class="colLast" scope="col">Method and Description</th>
</tr>
<tr id="i0" class="altColor">
<td class="colFirst"><code>void</code></td>
<td class="colLast"><code><span class="memberNameLink"><a href="../../javax/websocket/Endpoint.html#onClose-javax.websocket.Session-javax.websocket.CloseReason-">onClose</a></span>(<a href="../../javax/websocket/Session.html" title="interface in javax.websocket">Session</a>&nbsp;session,
<a href="../../javax/websocket/CloseReason.html" title="class in javax.websocket">CloseReason</a>&nbsp;closeReason)</code>
<div class="block">This method is called immediately prior to the session with the remote peer being closed.</div>
</td>
</tr>
<tr id="i1" class="rowColor">
<td class="colFirst"><code>void</code></td>
<td class="colLast"><code><span class="memberNameLink"><a href="../../javax/websocket/Endpoint.html#onError-javax.websocket.Session-java.lang.Throwable-">onError</a></span>(<a href="../../javax/websocket/Session.html" title="interface in javax.websocket">Session</a>&nbsp;session,
java.lang.Throwable&nbsp;thr)</code>
<div class="block">Developers may implement this method when the web socket session creates some kind of error that is not modeled
in the web socket protocol.</div>
</td>
</tr>
<tr id="i2" class="altColor">
<td class="colFirst"><code>abstract void</code></td>
<td class="colLast"><code><span class="memberNameLink"><a href="../../javax/websocket/Endpoint.html#onOpen-javax.websocket.Session-javax.websocket.EndpointConfig-">onOpen</a></span>(<a href="../../javax/websocket/Session.html" title="interface in javax.websocket">Session</a>&nbsp;session,
<a href="../../javax/websocket/EndpointConfig.html" title="interface in javax.websocket">EndpointConfig</a>&nbsp;config)</code>
<div class="block">Developers must implement this method to be notified when a new conversation has just begun.</div>
</td>
</tr>
</table>
<ul class="blockList">
<li class="blockList"><a name="methods.inherited.from.class.java.lang.Object">
<!-- -->
</a>
<h3>Methods inherited from class&nbsp;java.lang.Object</h3>
<code>clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait</code></li>
</ul>
</li>
</ul>
</li>
</ul>
</div>
<div class="details">
<ul class="blockList">
<li class="blockList">
<!-- ========= CONSTRUCTOR DETAIL ======== -->
<ul class="blockList">
<li class="blockList"><a name="constructor.detail">
<!-- -->
</a>
<h3>Constructor Detail</h3>
<a name="Endpoint--">
<!-- -->
</a>
<ul class="blockListLast">
<li class="blockList">
<h4>Endpoint</h4>
<pre>public&nbsp;Endpoint()</pre>
</li>
</ul>
</li>
</ul>
<!-- ============ METHOD DETAIL ========== -->
<ul class="blockList">
<li class="blockList"><a name="method.detail">
<!-- -->
</a>
<h3>Method Detail</h3>
<a name="onOpen-javax.websocket.Session-javax.websocket.EndpointConfig-">
<!-- -->
</a>
<ul class="blockList">
<li class="blockList">
<h4>onOpen</h4>
<pre>public abstract&nbsp;void&nbsp;onOpen(<a href="../../javax/websocket/Session.html" title="interface in javax.websocket">Session</a>&nbsp;session,
<a href="../../javax/websocket/EndpointConfig.html" title="interface in javax.websocket">EndpointConfig</a>&nbsp;config)</pre>
<div class="block">Developers must implement this method to be notified when a new conversation has just begun.</div>
<dl>
<dt><span class="paramLabel">Parameters:</span></dt>
<dd><code>session</code> - the session that has just been activated.</dd>
<dd><code>config</code> - the configuration used to configure this endpoint.</dd>
</dl>
</li>
</ul>
<a name="onClose-javax.websocket.Session-javax.websocket.CloseReason-">
<!-- -->
</a>
<ul class="blockList">
<li class="blockList">
<h4>onClose</h4>
<pre>public&nbsp;void&nbsp;onClose(<a href="../../javax/websocket/Session.html" title="interface in javax.websocket">Session</a>&nbsp;session,
<a href="../../javax/websocket/CloseReason.html" title="class in javax.websocket">CloseReason</a>&nbsp;closeReason)</pre>
<div class="block">This method is called immediately prior to the session with the remote peer being closed. It is called whether
the session is being closed because the remote peer initiated a close and sent a close frame, or whether the
local websocket container or this endpoint requests to close the session. The developer may take this last
opportunity to retrieve session attributes such as the ID, or any application data it holds before it becomes
unavailable after the completion of the method. Developers should not attempt to modify the session from within
this method, or send new messages from this call as the underlying connection will not be able to send them at
this stage.</div>
<dl>
<dt><span class="paramLabel">Parameters:</span></dt>
<dd><code>session</code> - the session about to be closed.</dd>
<dd><code>closeReason</code> - the reason the session was closed.</dd>
</dl>
</li>
</ul>
<a name="onError-javax.websocket.Session-java.lang.Throwable-">
<!-- -->
</a>
<ul class="blockListLast">
<li class="blockList">
<h4>onError</h4>
<pre>public&nbsp;void&nbsp;onError(<a href="../../javax/websocket/Session.html" title="interface in javax.websocket">Session</a>&nbsp;session,
java.lang.Throwable&nbsp;thr)</pre>
<div class="block">Developers may implement this method when the web socket session creates some kind of error that is not modeled
in the web socket protocol. This may for example be a notification that an incoming message is too big to handle,
or that the incoming message could not be encoded.
<p>
There are a number of categories of exception that this method is (currently) defined to handle:
<ul>
<li>connection problems, for example, a socket failure that occurs before the web socket connection can be
formally closed. These are modeled as <a href="../../javax/websocket/SessionException.html" title="class in javax.websocket"><code>SessionException</code></a>s</li>
<li>runtime errors thrown by developer created message handlers calls.</li>
<li>conversion errors encoding incoming messages before any message handler has been called. These are modeled as
<a href="../../javax/websocket/DecodeException.html" title="class in javax.websocket"><code>DecodeException</code></a>s</li>
</ul></div>
<dl>
<dt><span class="paramLabel">Parameters:</span></dt>
<dd><code>session</code> - the session in use when the error occurs.</dd>
<dd><code>thr</code> - the throwable representing the problem.</dd>
</dl>
</li>
</ul>
</li>
</ul>
</li>
</ul>
</div>
</div>
<!-- ========= END OF CLASS DATA ========= -->
<!-- ======= START OF BOTTOM NAVBAR ====== -->
<div class="bottomNav"><a name="navbar.bottom">
<!-- -->
</a>
<div class="skipNav"><a href="#skip.navbar.bottom" title="Skip navigation links">Skip navigation links</a></div>
<a name="navbar.bottom.firstrow">
<!-- -->
</a>
<ul class="navList" title="Navigation">
<li><a href="../../overview-summary.html">Overview</a></li>
<li><a href="package-summary.html">Package</a></li>
<li class="navBarCell1Rev">Class</li>
<li><a href="package-tree.html">Tree</a></li>
<li><a href="../../deprecated-list.html">Deprecated</a></li>
<li><a href="../../index-all.html">Index</a></li>
<li><a href="../../help-doc.html">Help</a></li>
</ul>
</div>
<div class="subNav">
<ul class="navList">
<li><a href="../../javax/websocket/Encoder.TextStream.html" title="interface in javax.websocket"><span class="typeNameLink">Prev&nbsp;Class</span></a></li>
<li><a href="../../javax/websocket/EndpointConfig.html" title="interface in javax.websocket"><span class="typeNameLink">Next&nbsp;Class</span></a></li>
</ul>
<ul class="navList">
<li><a href="../../index.html?javax/websocket/Endpoint.html" target="_top">Frames</a></li>
<li><a href="Endpoint.html" target="_top">No&nbsp;Frames</a></li>
</ul>
<ul class="navList" id="allclasses_navbar_bottom">
<li><a href="../../allclasses-noframe.html">All&nbsp;Classes</a></li>
</ul>
<div>
<script type="text/javascript"><!--
allClassesLink = document.getElementById("allclasses_navbar_bottom");
if(window==top) {
allClassesLink.style.display = "block";
}
else {
allClassesLink.style.display = "none";
}
//-->
</script>
</div>
<div>
<ul class="subNavList">
<li>Summary:&nbsp;</li>
<li>Nested&nbsp;|&nbsp;</li>
<li>Field&nbsp;|&nbsp;</li>
<li><a href="#constructor.summary">Constr</a>&nbsp;|&nbsp;</li>
<li><a href="#method.summary">Method</a></li>
</ul>
<ul class="subNavList">
<li>Detail:&nbsp;</li>
<li>Field&nbsp;|&nbsp;</li>
<li><a href="#constructor.detail">Constr</a>&nbsp;|&nbsp;</li>
<li><a href="#method.detail">Method</a></li>
</ul>
</div>
<a name="skip.navbar.bottom">
<!-- -->
</a></div>
<!-- ======== END OF BOTTOM NAVBAR ======= -->
</body>
</html>