PageRenderTime 37ms CodeModel.GetById 20ms app.highlight 15ms RepoModel.GetById 1ms app.codeStats 0ms

/.metadata/.plugins/org.eclipse.core.resources/.history/bf/005b5d9781a3001e1dff9ae635b3e1ee

https://bitbucket.org/fixpoint/connexion
#! | 50 lines | 44 code | 6 blank | 0 comment | 0 complexity | d5d75d5f7a35f097bdb3b3a8167a5494 MD5 | raw file
 1package info.reflectionsofmind.connexion.platform.control.util;
 2
 3import info.reflectionsofmind.connexion.platform.control.stc.IServerToClientMessage;
 4import info.reflectionsofmind.connexion.platform.control.stc.STCMessageCoder;
 5import info.reflectionsofmind.connexion.platform.control.stc.message.MsgParticipationAccepted;
 6import info.reflectionsofmind.connexion.transport.AbstractTransport;
 7import info.reflectionsofmind.connexion.transport.ITransport.INode;
 8import info.reflectionsofmind.connexion.util.convert.DecodingException;
 9
10import java.util.concurrent.BlockingQueue;
11import java.util.concurrent.SynchronousQueue;
12
13private final class WaitForParticipationAccepted extends AbstractTransport.Listener
14{
15	private final BlockingQueue<MsgParticipationAccepted> queue = new SynchronousQueue<MsgParticipationAccepted>();
16	
17	public MsgParticipationAccepted take()
18	{
19		try
20		{
21			return this.queue.take();
22		}
23		catch (final InterruptedException exception)
24		{
25			throw new RuntimeException(exception);
26		}
27	}
28	
29	@Override
30	public void onPacket(final INode sender, final String contents)
31	{
32		try
33		{
34			final IServerToClientMessage message = STCMessageCoder.INSTANCE.decode(contents);
35			
36			if (message instanceof MsgParticipationAccepted)
37			{
38				this.queue.put((MsgParticipationAccepted) message);
39			}
40		}
41		catch (final DecodingException exception)
42		{
43			throw new RuntimeException(exception);
44		}
45		catch (final InterruptedException exception)
46		{
47			throw new RuntimeException(exception);
48		}
49	}
50}