Mercurial > hg > Applications > TreeVNC
view src/main/java/com/glavsoft/rfb/protocol/MessageQueue.java @ 57:17b702648079
version2.7.2 original version.
author | Taninari YU <you@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Sun, 15 Dec 2013 18:04:03 +0900 |
parents | 4689cc86d6cb |
children | 3ede63861103 |
line wrap: on
line source
// Copyright (C) 2010, 2011, 2012, 2013 GlavSoft LLC. // All rights reserved. // //------------------------------------------------------------------------- // This file is part of the TightVNC software. Please visit our Web site: // // http://www.tightvnc.com/ // // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation; either version 2 of the License, or // (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License along // with this program; if not, write to the Free Software Foundation, Inc., // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. //------------------------------------------------------------------------- // package com.glavsoft.rfb.protocol; import com.glavsoft.rfb.client.ClientToServerMessage; import java.util.concurrent.BlockingQueue; import java.util.concurrent.LinkedBlockingQueue; import java.util.concurrent.TimeUnit; /** * @author dime at tightvnc.com */ public class MessageQueue { private final BlockingQueue<ClientToServerMessage> queue; public MessageQueue() { queue = new LinkedBlockingQueue<ClientToServerMessage>(); } public void put(ClientToServerMessage message) { queue.offer(message); } /** * Retrieves and removes the head of this queue, waiting if necessary until an element becomes available. * Retrieves and removes the head of this queue, waiting up to the certain wait time if necessary for * an element to become available. * @return the head of this queue, or null if the specified waiting time elapses before an element is available * @throws InterruptedException - if interrupted while waiting */ public ClientToServerMessage get() throws InterruptedException { return queue.poll(1, TimeUnit.SECONDS); } }