PageRenderTime 41ms CodeModel.GetById 29ms app.highlight 11ms RepoModel.GetById 0ms app.codeStats 0ms

/.metadata/.plugins/org.eclipse.core.resources/.history/21/8055b4bb81a3001e1dff9ae635b3e1ee

https://bitbucket.org/fixpoint/connexion
#! | 50 lines | 44 code | 6 blank | 0 comment | 0 complexity | d86feaa195bf52832a5b1e1c95417640 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.Waiter;
 9import info.reflectionsofmind.connexion.util.convert.DecodingException;
10
11import java.util.concurrent.Future;
12
13public class ParticipationAcceptedWaiter extends AbstractTransport.Listener
14{
15	private final Waiter<MsgParticipationAccepted> queue = new Waiter<MsgParticipationAccepted>();
16	
17	public Future<MsgParticipationAccepted> get()
18	{
19		try
20		{
21			return this.queue.get();
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}