📄 keepalivefilter.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><!--NewPage--><HTML><HEAD><!-- Generated by javadoc (build 1.6.0_04) on Tue Feb 19 10:50:44 MST 2008 --><META http-equiv="Content-Type" content="text/html; charset=UTF-8"><TITLE>KeepAliveFilter (Apache MINA 2.0.0-M1 API Documentation)</TITLE><META NAME="date" CONTENT="2008-02-19"><LINK REL ="stylesheet" TYPE="text/css" HREF="../../../../../stylesheet.css" TITLE="Style"><SCRIPT type="text/javascript">function windowTitle(){ if (location.href.indexOf('is-external=true') == -1) { parent.document.title="KeepAliveFilter (Apache MINA 2.0.0-M1 API Documentation)"; }}</SCRIPT><NOSCRIPT></NOSCRIPT></HEAD><BODY BGCOLOR="white" onload="windowTitle();"><HR><!-- ========= START OF TOP NAVBAR ======= --><A NAME="navbar_top"><!-- --></A><A HREF="#skip-navbar_top" title="Skip navigation links"></A><TABLE BORDER="0" WIDTH="100%" CELLPADDING="1" CELLSPACING="0" SUMMARY=""><TR><TD COLSPAN=2 BGCOLOR="#EEEEFF" CLASS="NavBarCell1"><A NAME="navbar_top_firstrow"><!-- --></A><TABLE BORDER="0" CELLPADDING="0" CELLSPACING="3" SUMMARY=""> <TR ALIGN="center" VALIGN="top"> <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../../../overview-summary.html"><FONT CLASS="NavBarFont1"><B>Overview</B></FONT></A> </TD> <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="package-summary.html"><FONT CLASS="NavBarFont1"><B>Package</B></FONT></A> </TD> <TD BGCOLOR="#FFFFFF" CLASS="NavBarCell1Rev"> <FONT CLASS="NavBarFont1Rev"><B>Class</B></FONT> </TD> <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="class-use/KeepAliveFilter.html"><FONT CLASS="NavBarFont1"><B>Use</B></FONT></A> </TD> <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="package-tree.html"><FONT CLASS="NavBarFont1"><B>Tree</B></FONT></A> </TD> <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../../../deprecated-list.html"><FONT CLASS="NavBarFont1"><B>Deprecated</B></FONT></A> </TD> <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../../../index-all.html"><FONT CLASS="NavBarFont1"><B>Index</B></FONT></A> </TD> <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../../../help-doc.html"><FONT CLASS="NavBarFont1"><B>Help</B></FONT></A> </TD> </TR></TABLE></TD><TD ALIGN="right" VALIGN="top" ROWSPAN=3><EM></EM></TD></TR><TR><TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2"> PREV CLASS <A HREF="../../../../../org/apache/mina/filter/keepalive/KeepAliveMessageFactory.html" title="interface in org.apache.mina.filter.keepalive"><B>NEXT CLASS</B></A></FONT></TD><TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2"> <A HREF="../../../../../index.html?org/apache/mina/filter/keepalive/KeepAliveFilter.html" target="_top"><B>FRAMES</B></A> <A HREF="KeepAliveFilter.html" target="_top"><B>NO FRAMES</B></A> <SCRIPT type="text/javascript"> <!-- if(window==top) { document.writeln('<A HREF="../../../../../allclasses-noframe.html"><B>All Classes</B></A>'); } //--></SCRIPT><NOSCRIPT> <A HREF="../../../../../allclasses-noframe.html"><B>All Classes</B></A></NOSCRIPT></FONT></TD></TR><TR><TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2"> SUMMARY: NESTED | FIELD | <A HREF="#constructor_summary">CONSTR</A> | <A HREF="#method_summary">METHOD</A></FONT></TD><TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2">DETAIL: FIELD | <A HREF="#constructor_detail">CONSTR</A> | <A HREF="#method_detail">METHOD</A></FONT></TD></TR></TABLE><A NAME="skip-navbar_top"></A><!-- ========= END OF TOP NAVBAR ========= --><HR><!-- ======== START OF CLASS DATA ======== --><H2><FONT SIZE="-1">org.apache.mina.filter.keepalive</FONT><BR>Class KeepAliveFilter</H2><PRE><A HREF="http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Object.html?is-external=true" title="class or interface in java.lang">java.lang.Object</A> <IMG SRC="../../../../../resources/inherit.gif" ALT="extended by "><A HREF="../../../../../org/apache/mina/common/IoFilterAdapter.html" title="class in org.apache.mina.common">org.apache.mina.common.IoFilterAdapter</A> <IMG SRC="../../../../../resources/inherit.gif" ALT="extended by "><B>org.apache.mina.filter.keepalive.KeepAliveFilter</B></PRE><DL><DT><B>All Implemented Interfaces:</B> <DD><A HREF="../../../../../org/apache/mina/common/IoFilter.html" title="interface in org.apache.mina.common">IoFilter</A></DD></DL><HR><DL><DT><PRE>public class <B>KeepAliveFilter</B><DT>extends <A HREF="../../../../../org/apache/mina/common/IoFilterAdapter.html" title="class in org.apache.mina.common">IoFilterAdapter</A></DL></PRE><P>An <A HREF="../../../../../org/apache/mina/common/IoFilter.html" title="interface in org.apache.mina.common"><CODE>IoFilter</CODE></A> that sends a keep-alive request on <tt>sessionIdle</tt> event with <A HREF="../../../../../org/apache/mina/common/IdleStatus.html#READER_IDLE"><CODE>IdleStatus.READER_IDLE</CODE></A> and sends back the response for the keep-alive request. <h2>Interference with <A HREF="../../../../../org/apache/mina/common/IoSessionConfig.html#setIdleTime(org.apache.mina.common.IdleStatus, int)"><CODE>IoSessionConfig.setIdleTime(IdleStatus, int)</CODE></A></h2> This filter adjusts <tt>idleTime</tt> property for <A HREF="../../../../../org/apache/mina/common/IdleStatus.html#READER_IDLE"><CODE>IdleStatus.READER_IDLE</CODE></A> automatically. Changing the <tt>idleTime</tt> property for <A HREF="../../../../../org/apache/mina/common/IdleStatus.html#READER_IDLE"><CODE>IdleStatus.READER_IDLE</CODE></A> will lead this filter to a unexpected behavior. <h2>Implementing <A HREF="../../../../../org/apache/mina/filter/keepalive/KeepAliveMessageFactory.html" title="interface in org.apache.mina.filter.keepalive"><CODE>KeepAliveMessageFactory</CODE></A></h2> To use this filter, you have to provide an implementation of <A HREF="../../../../../org/apache/mina/filter/keepalive/KeepAliveMessageFactory.html" title="interface in org.apache.mina.filter.keepalive"><CODE>KeepAliveMessageFactory</CODE></A>, which determines a received or sent message is a keep-alive message or not and creates a new keep-alive message: <table border="1"> <tr> <th>Name</th><th>Description</th><th>Implementation</th> </tr> <tr valign="top"> <td>Active</td> <td>You want a keep-alive request is sent when the reader is idle. Once the request is sent, the response for the request should be received within <tt>keepAliveRequestTimeout</tt> seconds. Otherwise, the specified <A HREF="../../../../../org/apache/mina/filter/keepalive/KeepAlivePolicy.html" title="enum in org.apache.mina.filter.keepalive"><CODE>KeepAlivePolicy</CODE></A> will be enforced. If a keep-alive request is received, its response also should be sent back.</td> <td>Both <A HREF="../../../../../org/apache/mina/filter/keepalive/KeepAliveMessageFactory.html#getRequest(org.apache.mina.common.IoSession)"><CODE>KeepAliveMessageFactory.getRequest(IoSession)</CODE></A> and <A HREF="../../../../../org/apache/mina/filter/keepalive/KeepAliveMessageFactory.html#getResponse(org.apache.mina.common.IoSession, java.lang.Object)"><CODE>KeepAliveMessageFactory.getResponse(IoSession, Object)</CODE></A> must return a non-<tt>null</tt>.</td> </tr> <tr valign="top"> <td>Semi-active</td> <td>You want a keep-alive request to be sent when the reader is idle. However, you don't really care if the response is received or not. If a keep-alive request is received, its response should also be sent back. </td> <td>Both <A HREF="../../../../../org/apache/mina/filter/keepalive/KeepAliveMessageFactory.html#getRequest(org.apache.mina.common.IoSession)"><CODE>KeepAliveMessageFactory.getRequest(IoSession)</CODE></A> and <A HREF="../../../../../org/apache/mina/filter/keepalive/KeepAliveMessageFactory.html#getResponse(org.apache.mina.common.IoSession, java.lang.Object)"><CODE>KeepAliveMessageFactory.getResponse(IoSession, Object)</CODE></A> must return a non-<tt>null</tt>, and the <tt>policy</tt> property should be set to <A HREF="../../../../../org/apache/mina/filter/keepalive/KeepAlivePolicy.html#OFF"><CODE>KeepAlivePolicy.OFF</CODE></A> or <A HREF="../../../../../org/apache/mina/filter/keepalive/KeepAlivePolicy.html#LOG"><CODE>KeepAlivePolicy.LOG</CODE></A>. </td> </tr> <tr valign="top"> <td>Passive</td> <td>You don't want to send a keep-alive request by yourself, but the response should be sent back if a keep-alive request is received.</td> <td><A HREF="../../../../../org/apache/mina/filter/keepalive/KeepAliveMessageFactory.html#getRequest(org.apache.mina.common.IoSession)"><CODE>KeepAliveMessageFactory.getRequest(IoSession)</CODE></A> must return <tt>null</tt> and <A HREF="../../../../../org/apache/mina/filter/keepalive/KeepAliveMessageFactory.html#getResponse(org.apache.mina.common.IoSession, java.lang.Object)"><CODE>KeepAliveMessageFactory.getResponse(IoSession, Object)</CODE></A> must return a non-<tt>null</tt>.</td> </tr> <tr valign="top"> <td>Deaf Speaker</td> <td>You want a keep-alive request to be sent when the reader is idle, but you don't want to send any response back.</td> <td><A HREF="../../../../../org/apache/mina/filter/keepalive/KeepAliveMessageFactory.html#getRequest(org.apache.mina.common.IoSession)"><CODE>KeepAliveMessageFactory.getRequest(IoSession)</CODE></A> must return a non-<tt>null</tt> and <A HREF="../../../../../org/apache/mina/filter/keepalive/KeepAliveMessageFactory.html#getResponse(org.apache.mina.common.IoSession, java.lang.Object)"><CODE>KeepAliveMessageFactory.getResponse(IoSession, Object)</CODE></A> must return <tt>null</tt>.</td> </tr> <tr valign="top"> <td>Silent Listener</td> <td>You don't want to send a keep-alive request by yourself nor send any response back.</td> <td>Both <A HREF="../../../../../org/apache/mina/filter/keepalive/KeepAliveMessageFactory.html#getRequest(org.apache.mina.common.IoSession)"><CODE>KeepAliveMessageFactory.getRequest(IoSession)</CODE></A> and <A HREF="../../../../../org/apache/mina/filter/keepalive/KeepAliveMessageFactory.html#getResponse(org.apache.mina.common.IoSession, java.lang.Object)"><CODE>KeepAliveMessageFactory.getResponse(IoSession, Object)</CODE></A> must return <tt>null</tt>.</td> </tr> </table> Please note that you must implement <A HREF="../../../../../org/apache/mina/filter/keepalive/KeepAliveMessageFactory.html#isRequest(org.apache.mina.common.IoSession, java.lang.Object)"><CODE>KeepAliveMessageFactory.isRequest(IoSession, Object)</CODE></A> and <A HREF="../../../../../org/apache/mina/filter/keepalive/KeepAliveMessageFactory.html#isResponse(org.apache.mina.common.IoSession, java.lang.Object)"><CODE>KeepAliveMessageFactory.isResponse(IoSession, Object)</CODE></A> properly whatever case you chose. <h2>Enforcing a policy</h2> You can enforce a predefined policy by specifying a <A HREF="../../../../../org/apache/mina/filter/keepalive/KeepAlivePolicy.html" title="enum in org.apache.mina.filter.keepalive"><CODE>KeepAlivePolicy</CODE></A>. The default policy is <A HREF="../../../../../org/apache/mina/filter/keepalive/KeepAlivePolicy.html#CLOSE"><CODE>KeepAlivePolicy.CLOSE</CODE></A>. Setting the policy
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -