comparison src/main/java/com/glavsoft/rfb/protocol/MessageQueue.java @ 0:daa24f8a557b

TightVNC original
author YU
date Thu, 11 Sep 2014 07:30:03 +0900
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:daa24f8a557b
1 // Copyright (C) 2010, 2011, 2012, 2013 GlavSoft LLC.
2 // All rights reserved.
3 //
4 //-------------------------------------------------------------------------
5 // This file is part of the TightVNC software. Please visit our Web site:
6 //
7 // http://www.tightvnc.com/
8 //
9 // This program is free software; you can redistribute it and/or modify
10 // it under the terms of the GNU General Public License as published by
11 // the Free Software Foundation; either version 2 of the License, or
12 // (at your option) any later version.
13 //
14 // This program is distributed in the hope that it will be useful,
15 // but WITHOUT ANY WARRANTY; without even the implied warranty of
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 // GNU General Public License for more details.
18 //
19 // You should have received a copy of the GNU General Public License along
20 // with this program; if not, write to the Free Software Foundation, Inc.,
21 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 //-------------------------------------------------------------------------
23 //
24
25 package com.glavsoft.rfb.protocol;
26
27 import com.glavsoft.rfb.client.ClientToServerMessage;
28
29 import java.util.concurrent.BlockingQueue;
30 import java.util.concurrent.LinkedBlockingQueue;
31 import java.util.concurrent.TimeUnit;
32
33 /**
34 * @author dime at tightvnc.com
35 */
36 public class MessageQueue {
37 private final BlockingQueue<ClientToServerMessage> queue;
38
39 public MessageQueue() {
40 queue = new LinkedBlockingQueue<ClientToServerMessage>();
41 }
42
43 public void put(ClientToServerMessage message) {
44 queue.offer(message);
45 }
46
47 /**
48 * Retrieves and removes the head of this queue, waiting if necessary until an element becomes available.
49 * Retrieves and removes the head of this queue, waiting up to the certain wait time if necessary for
50 * an element to become available.
51 * @return the head of this queue, or null if the specified waiting time elapses before an element is available
52 * @throws InterruptedException - if interrupted while waiting
53 */
54 public ClientToServerMessage get() throws InterruptedException {
55 return queue.poll(1, TimeUnit.SECONDS);
56 }
57
58 }