• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java ObjectReader类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.apache.catalina.tribes.io.ObjectReader的典型用法代码示例。如果您正苦于以下问题:Java ObjectReader类的具体用法?Java ObjectReader怎么用?Java ObjectReader使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



ObjectReader类属于org.apache.catalina.tribes.io包,在下文中一共展示了ObjectReader类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: cancelKey

import org.apache.catalina.tribes.io.ObjectReader; //导入依赖的package包/类
private void cancelKey(final SelectionKey key) {
    if ( log.isTraceEnabled() )
        log.trace("Adding key for cancel event:"+key);

    ObjectReader reader = (ObjectReader)key.attachment();
    if ( reader != null ) {
        reader.setCancelled(true);
        reader.finish();
    }
    Runnable cx = new Runnable() {
        @Override
        public void run() {
            if ( log.isTraceEnabled() )
                log.trace("Cancelling key:"+key);

            NioReceiver.cancelledKey(key);
        }
    };
    receiver.addEvent(cx);
}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:21,代码来源:NioReplicationTask.java


示例2: cancelKey

import org.apache.catalina.tribes.io.ObjectReader; //导入依赖的package包/类
private void cancelKey(final SelectionKey key) {
	if (log.isTraceEnabled())
		log.trace("Adding key for cancel event:" + key);

	ObjectReader reader = (ObjectReader) key.attachment();
	if (reader != null) {
		reader.setCancelled(true);
		reader.finish();
	}
	Runnable cx = new Runnable() {
		@Override
		public void run() {
			if (log.isTraceEnabled())
				log.trace("Cancelling key:" + key);

			NioReceiver.cancelledKey(key);
		}
	};
	receiver.addEvent(cx);
}
 
开发者ID:how2j,项目名称:lazycat,代码行数:21,代码来源:NioReplicationTask.java


示例3: registerForRead

import org.apache.catalina.tribes.io.ObjectReader; //导入依赖的package包/类
protected void registerForRead(final SelectionKey key, ObjectReader reader) {
    if ( log.isTraceEnabled() )
        log.trace("Adding key for read event:"+key);
    reader.finish();
    //register our OP_READ interest
    Runnable r = new Runnable() {
        @Override
        public void run() {
            try {
                if (key.isValid()) {
                    // cycle the selector so this key is active again
                    key.selector().wakeup();
                    // resume interest in OP_READ, OP_WRITE
                    int resumeOps = key.interestOps() | SelectionKey.OP_READ;
                    key.interestOps(resumeOps);
                    if ( log.isTraceEnabled() )
                        log.trace("Registering key for read:"+key);
                }
            } catch (CancelledKeyException ckx ) {
                NioReceiver.cancelledKey(key);
                if ( log.isTraceEnabled() )
                    log.trace("CKX Cancelling key:"+key);

            } catch (Exception x) {
                log.error("Error registering key for read:"+key,x);
            }
        }
    };
    receiver.addEvent(r);
}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:31,代码来源:NioReplicationTask.java


示例4: socketTimeouts

import org.apache.catalina.tribes.io.ObjectReader; //导入依赖的package包/类
protected void socketTimeouts() {
        long now = System.currentTimeMillis();
        if ( (now-lastCheck) < getSelectorTimeout() ) return;
        //timeout
        Selector tmpsel = this.selector.get();
        Set<SelectionKey> keys =  (isListening()&&tmpsel!=null)?tmpsel.keys():null;
        if ( keys == null ) return;
        for (Iterator<SelectionKey> iter = keys.iterator(); iter.hasNext();) {
            SelectionKey key = iter.next();
            try {
//                if (key.interestOps() == SelectionKey.OP_READ) {
//                    //only timeout sockets that we are waiting for a read from
//                    ObjectReader ka = (ObjectReader) key.attachment();
//                    long delta = now - ka.getLastAccess();
//                    if (delta > (long) getTimeout()) {
//                        cancelledKey(key);
//                    }
//                }
//                else
                if ( key.interestOps() == 0 ) {
                    //check for keys that didn't make it in.
                    ObjectReader ka = (ObjectReader) key.attachment();
                    if ( ka != null ) {
                        long delta = now - ka.getLastAccess();
                        if (delta > getTimeout() && (!ka.isAccessed())) {
                            if (log.isWarnEnabled())
                                log.warn("Channel key is registered, but has had no interest ops for the last "+getTimeout()+" ms. (cancelled:"+ka.isCancelled()+"):"+key+" last access:"+new java.sql.Timestamp(ka.getLastAccess())+" Possible cause: all threads used, perform thread dump");
                            ka.setLastAccess(now);
                            //key.interestOps(SelectionKey.OP_READ);
                        }//end if
                    } else {
                        cancelledKey(key);
                    }//end if
                }//end if
            }catch ( CancelledKeyException ckx ) {
                cancelledKey(key);
            }
        }
        lastCheck = System.currentTimeMillis();
    }
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:41,代码来源:NioReceiver.java


示例5: listen

import org.apache.catalina.tribes.io.ObjectReader; //导入依赖的package包/类
public void listen() throws Exception {
    if (doListen()) {
        log.warn("ServerSocket already started");
        return;
    }
    setListen(true);

    while ( doListen() ) {
        Socket socket = null;
        if ( getTaskPool().available() < 1 ) {
            if ( log.isWarnEnabled() )
                log.warn("All BIO server replication threads are busy, unable to handle more requests until a thread is freed up.");
        }
        BioReplicationTask task = (BioReplicationTask)getTaskPool().getRxTask();
        if ( task == null ) continue; //should never happen
        try {
            socket = serverSocket.accept();
        }catch ( Exception x ) {
            if ( doListen() ) throw x;
        }
        if ( !doListen() ) {
            task.setDoRun(false);
            task.serviceSocket(null,null);
            getExecutor().execute(task);
            break; //regular shutdown
        }
        if ( socket == null ) continue;
        socket.setReceiveBufferSize(getRxBufSize());
        socket.setSendBufferSize(getTxBufSize());
        socket.setTcpNoDelay(getTcpNoDelay());
        socket.setKeepAlive(getSoKeepAlive());
        socket.setOOBInline(getOoBInline());
        socket.setReuseAddress(getSoReuseAddress());
        socket.setSoLinger(getSoLingerOn(),getSoLingerTime());
        socket.setSoTimeout(getTimeout());
        ObjectReader reader = new ObjectReader(socket);
        task.serviceSocket(socket,reader);
        getExecutor().execute(task);
    }//while
}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:41,代码来源:BioReceiver.java


示例6: execute

import org.apache.catalina.tribes.io.ObjectReader; //导入依赖的package包/类
protected void execute(ObjectReader reader) throws Exception{
    int pkgcnt = reader.count();

    if ( pkgcnt > 0 ) {
        ChannelMessage[] msgs = reader.execute();
        for ( int i=0; i<msgs.length; i++ ) {
            /**
             * Use send ack here if you want to ack the request to the remote 
             * server before completing the request
             * This is considered an asynchronized request
             */
            if (ChannelData.sendAckAsync(msgs[i].getOptions())) sendAck(Constants.ACK_COMMAND);
            try {
                //process the message
                getCallback().messageDataReceived(msgs[i]);
                /**
                 * Use send ack here if you want the request to complete on this
                 * server before sending the ack to the remote server
                 * This is considered a synchronized request
                 */
                if (ChannelData.sendAckSync(msgs[i].getOptions())) sendAck(Constants.ACK_COMMAND);
            }catch  ( Exception x ) {
                if (ChannelData.sendAckSync(msgs[i].getOptions())) sendAck(Constants.FAIL_ACK_COMMAND);
                log.error("Error thrown from messageDataReceived.",x);
            }
            if ( getUseBufferPool() ) {
                BufferPool.getBufferPool().returnBuffer(msgs[i].getMessage());
                msgs[i].setMessage(null);
            }
        }                       
    }

   
}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:35,代码来源:BioReplicationTask.java


示例7: serviceChannel

import org.apache.catalina.tribes.io.ObjectReader; //导入依赖的package包/类
/**
 * Called to initiate a unit of work by this worker thread on the provided
 * SelectionKey object. This method is synchronized, as is the run() method,
 * so only one key can be serviced at a given time. Before waking the worker
 * thread, and before returning to the main selection loop, this key's
 * interest set is updated to remove OP_READ. This will cause the selector
 * to ignore read-readiness for this channel while the worker thread is
 * servicing it.
 */
public synchronized void serviceChannel(SelectionKey key) {
	if (log.isTraceEnabled())
		log.trace("About to service key:" + key);
	ObjectReader reader = (ObjectReader) key.attachment();
	if (reader != null)
		reader.setLastAccess(System.currentTimeMillis());
	this.key = key;
	key.interestOps(key.interestOps() & (~SelectionKey.OP_READ));
	key.interestOps(key.interestOps() & (~SelectionKey.OP_WRITE));
}
 
开发者ID:how2j,项目名称:lazycat,代码行数:20,代码来源:NioReplicationTask.java


示例8: registerForRead

import org.apache.catalina.tribes.io.ObjectReader; //导入依赖的package包/类
protected void registerForRead(final SelectionKey key, ObjectReader reader) {
	if (log.isTraceEnabled())
		log.trace("Adding key for read event:" + key);
	reader.finish();
	// register our OP_READ interest
	Runnable r = new Runnable() {
		@Override
		public void run() {
			try {
				if (key.isValid()) {
					// cycle the selector so this key is active again
					key.selector().wakeup();
					// resume interest in OP_READ, OP_WRITE
					int resumeOps = key.interestOps() | SelectionKey.OP_READ;
					key.interestOps(resumeOps);
					if (log.isTraceEnabled())
						log.trace("Registering key for read:" + key);
				}
			} catch (CancelledKeyException ckx) {
				NioReceiver.cancelledKey(key);
				if (log.isTraceEnabled())
					log.trace("CKX Cancelling key:" + key);

			} catch (Exception x) {
				log.error("Error registering key for read:" + key, x);
			}
		}
	};
	receiver.addEvent(r);
}
 
开发者ID:how2j,项目名称:lazycat,代码行数:31,代码来源:NioReplicationTask.java


示例9: execute

import org.apache.catalina.tribes.io.ObjectReader; //导入依赖的package包/类
protected void execute(ObjectReader reader) throws Exception {
	int pkgcnt = reader.count();

	if (pkgcnt > 0) {
		ChannelMessage[] msgs = reader.execute();
		for (int i = 0; i < msgs.length; i++) {
			/**
			 * Use send ack here if you want to ack the request to the
			 * remote server before completing the request This is
			 * considered an asynchronous request
			 */
			if (ChannelData.sendAckAsync(msgs[i].getOptions()))
				sendAck(Constants.ACK_COMMAND);
			try {
				// process the message
				getCallback().messageDataReceived(msgs[i]);
				/**
				 * Use send ack here if you want the request to complete on
				 * this server before sending the ack to the remote server
				 * This is considered a synchronized request
				 */
				if (ChannelData.sendAckSync(msgs[i].getOptions()))
					sendAck(Constants.ACK_COMMAND);
			} catch (Exception x) {
				if (ChannelData.sendAckSync(msgs[i].getOptions()))
					sendAck(Constants.FAIL_ACK_COMMAND);
				log.error("Error thrown from messageDataReceived.", x);
			}
			if (getUseBufferPool()) {
				BufferPool.getBufferPool().returnBuffer(msgs[i].getMessage());
				msgs[i].setMessage(null);
			}
		}
	}

}
 
开发者ID:how2j,项目名称:lazycat,代码行数:37,代码来源:BioReplicationTask.java


示例10: socketTimeouts

import org.apache.catalina.tribes.io.ObjectReader; //导入依赖的package包/类
protected void socketTimeouts() {
        long now = System.currentTimeMillis();
        if ( (now-lastCheck) < getSelectorTimeout() ) return;
        //timeout
        Selector tmpsel = selector;
        Set<SelectionKey> keys =  (isListening()&&tmpsel!=null)?tmpsel.keys():null;
        if ( keys == null ) return;
        for (Iterator<SelectionKey> iter = keys.iterator(); iter.hasNext();) {
            SelectionKey key = iter.next();
            try {
//                if (key.interestOps() == SelectionKey.OP_READ) {
//                    //only timeout sockets that we are waiting for a read from
//                    ObjectReader ka = (ObjectReader) key.attachment();
//                    long delta = now - ka.getLastAccess();
//                    if (delta > (long) getTimeout()) {
//                        cancelledKey(key);
//                    }
//                }
//                else
                if ( key.interestOps() == 0 ) {
                    //check for keys that didn't make it in.
                    ObjectReader ka = (ObjectReader) key.attachment();
                    if ( ka != null ) {
                        long delta = now - ka.getLastAccess();
                        if (delta > getTimeout() && (!ka.isAccessed())) {
                            if (log.isWarnEnabled())
                                log.warn("Channel key is registered, but has had no interest ops for the last "+getTimeout()+" ms. (cancelled:"+ka.isCancelled()+"):"+key+" last access:"+new java.sql.Timestamp(ka.getLastAccess())+" Possible cause: all threads used, perform thread dump");
                            ka.setLastAccess(now);
                            //key.interestOps(SelectionKey.OP_READ);
                        }//end if
                    } else {
                        cancelledKey(key);
                    }//end if
                }//end if
            }catch ( CancelledKeyException ckx ) {
                cancelledKey(key);
            }
        }
        lastCheck = System.currentTimeMillis();
    }
 
开发者ID:WhiteBearSolutions,项目名称:WBSAirback,代码行数:41,代码来源:NioReceiver.java


示例11: run

import org.apache.catalina.tribes.io.ObjectReader; //导入依赖的package包/类
@Override
public synchronized void run() {
    if ( buffer == null ) {
        int size = getRxBufSize();
        if (key.channel() instanceof DatagramChannel) {
            size = ChannelReceiver.MAX_UDP_SIZE;
        }
        if ( (getOptions() & OPTION_DIRECT_BUFFER) == OPTION_DIRECT_BUFFER) {
            buffer = ByteBuffer.allocateDirect(size);
        } else {
            buffer = ByteBuffer.allocate(size);
        }
    } else {
        buffer.clear();
    }
    if (key == null) {
        return; // just in case
    }
    if ( log.isTraceEnabled() )
        log.trace("Servicing key:"+key);

    try {
        ObjectReader reader = (ObjectReader)key.attachment();
        if ( reader == null ) {
            if ( log.isTraceEnabled() )
                log.trace("No object reader, cancelling:"+key);
            cancelKey(key);
        } else {
            if ( log.isTraceEnabled() )
                log.trace("Draining channel:"+key);

            drainChannel(key, reader);
        }
    } catch (Exception e) {
        //this is common, since the sockets on the other
        //end expire after a certain time.
        if ( e instanceof CancelledKeyException ) {
            //do nothing
        } else if ( e instanceof IOException ) {
            //dont spew out stack traces for IO exceptions unless debug is enabled.
            if (log.isDebugEnabled()) log.debug ("IOException in replication worker, unable to drain channel. Probable cause: Keep alive socket closed["+e.getMessage()+"].", e);
            else log.warn ("IOException in replication worker, unable to drain channel. Probable cause: Keep alive socket closed["+e.getMessage()+"].");
        } else if ( log.isErrorEnabled() ) {
            //this is a real error, log it.
            log.error("Exception caught in TcpReplicationThread.drainChannel.",e);
        }
        cancelKey(key);
    } finally {

    }
    key = null;
    // done, ready for more, return to pool
    getTaskPool().returnWorker (this);
}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:55,代码来源:NioReplicationTask.java


示例12: serviceSocket

import org.apache.catalina.tribes.io.ObjectReader; //导入依赖的package包/类
public synchronized void serviceSocket(Socket socket, ObjectReader reader) {
    this.socket = socket;
    this.reader = reader;
}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:5,代码来源:BioReplicationTask.java


示例13: run

import org.apache.catalina.tribes.io.ObjectReader; //导入依赖的package包/类
@Override
public synchronized void run() {
	if (buffer == null) {
		int size = getRxBufSize();
		if (key.channel() instanceof DatagramChannel) {
			size = ChannelReceiver.MAX_UDP_SIZE;
		}
		if ((getOptions() & OPTION_DIRECT_BUFFER) == OPTION_DIRECT_BUFFER) {
			buffer = ByteBuffer.allocateDirect(size);
		} else {
			buffer = ByteBuffer.allocate(size);
		}
	} else {
		buffer.clear();
	}
	if (key == null) {
		return; // just in case
	}
	if (log.isTraceEnabled())
		log.trace("Servicing key:" + key);

	try {
		ObjectReader reader = (ObjectReader) key.attachment();
		if (reader == null) {
			if (log.isTraceEnabled())
				log.trace("No object reader, cancelling:" + key);
			cancelKey(key);
		} else {
			if (log.isTraceEnabled())
				log.trace("Draining channel:" + key);

			drainChannel(key, reader);
		}
	} catch (Exception e) {
		// this is common, since the sockets on the other
		// end expire after a certain time.
		if (e instanceof CancelledKeyException) {
			// do nothing
		} else if (e instanceof IOException) {
			// dont spew out stack traces for IO exceptions unless debug is
			// enabled.
			if (log.isDebugEnabled())
				log.debug(
						"IOException in replication worker, unable to drain channel. Probable cause: Keep alive socket closed["
								+ e.getMessage() + "].",
						e);
			else
				log.warn(
						"IOException in replication worker, unable to drain channel. Probable cause: Keep alive socket closed["
								+ e.getMessage() + "].");
		} else if (log.isErrorEnabled()) {
			// this is a real error, log it.
			log.error("Exception caught in TcpReplicationThread.drainChannel.", e);
		}
		cancelKey(key);
	} finally {

	}
	key = null;
	// done, ready for more, return to pool
	getTaskPool().returnWorker(this);
}
 
开发者ID:how2j,项目名称:lazycat,代码行数:63,代码来源:NioReplicationTask.java


示例14: socketTimeouts

import org.apache.catalina.tribes.io.ObjectReader; //导入依赖的package包/类
protected void socketTimeouts() {
	long now = System.currentTimeMillis();
	if ((now - lastCheck) < getSelectorTimeout())
		return;
	// timeout
	Selector tmpsel = this.selector.get();
	Set<SelectionKey> keys = (isListening() && tmpsel != null) ? tmpsel.keys() : null;
	if (keys == null)
		return;
	for (Iterator<SelectionKey> iter = keys.iterator(); iter.hasNext();) {
		SelectionKey key = iter.next();
		try {
			// if (key.interestOps() == SelectionKey.OP_READ) {
			// //only timeout sockets that we are waiting for a read from
			// ObjectReader ka = (ObjectReader) key.attachment();
			// long delta = now - ka.getLastAccess();
			// if (delta > (long) getTimeout()) {
			// cancelledKey(key);
			// }
			// }
			// else
			if (key.interestOps() == 0) {
				// check for keys that didn't make it in.
				ObjectReader ka = (ObjectReader) key.attachment();
				if (ka != null) {
					long delta = now - ka.getLastAccess();
					if (delta > getTimeout() && (!ka.isAccessed())) {
						if (log.isWarnEnabled())
							log.warn("Channel key is registered, but has had no interest ops for the last "
									+ getTimeout() + " ms. (cancelled:" + ka.isCancelled() + "):" + key
									+ " last access:" + new java.sql.Timestamp(ka.getLastAccess())
									+ " Possible cause: all threads used, perform thread dump");
						ka.setLastAccess(now);
						// key.interestOps(SelectionKey.OP_READ);
					} // end if
				} else {
					cancelledKey(key);
				} // end if
			} // end if
		} catch (CancelledKeyException ckx) {
			cancelledKey(key);
		}
	}
	lastCheck = System.currentTimeMillis();
}
 
开发者ID:how2j,项目名称:lazycat,代码行数:46,代码来源:NioReceiver.java


示例15: listen

import org.apache.catalina.tribes.io.ObjectReader; //导入依赖的package包/类
public void listen() throws Exception {
	if (doListen()) {
		log.warn("ServerSocket already started");
		return;
	}
	setListen(true);

	while (doListen()) {
		Socket socket = null;
		if (getTaskPool().available() < 1) {
			if (log.isWarnEnabled())
				log.warn(
						"All BIO server replication threads are busy, unable to handle more requests until a thread is freed up.");
		}
		BioReplicationTask task = (BioReplicationTask) getTaskPool().getRxTask();
		if (task == null)
			continue; // should never happen
		try {
			socket = serverSocket.accept();
		} catch (Exception x) {
			if (doListen())
				throw x;
		}
		if (!doListen()) {
			task.setDoRun(false);
			task.serviceSocket(null, null);
			getExecutor().execute(task);
			break; // regular shutdown
		}
		if (socket == null)
			continue;
		socket.setReceiveBufferSize(getRxBufSize());
		socket.setSendBufferSize(getTxBufSize());
		socket.setTcpNoDelay(getTcpNoDelay());
		socket.setKeepAlive(getSoKeepAlive());
		socket.setOOBInline(getOoBInline());
		socket.setReuseAddress(getSoReuseAddress());
		socket.setSoLinger(getSoLingerOn(), getSoLingerTime());
		socket.setSoTimeout(getTimeout());
		ObjectReader reader = new ObjectReader(socket);
		task.serviceSocket(socket, reader);
		getExecutor().execute(task);
	} // while
}
 
开发者ID:how2j,项目名称:lazycat,代码行数:45,代码来源:BioReceiver.java



注:本文中的org.apache.catalina.tribes.io.ObjectReader类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java JUnitConfiguration类代码示例发布时间:2022-05-23
下一篇:
Java LineSeparator类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap