use of io.joynr.messaging.info.Channel in project joynr by bmwcarit.
the class ChannelDatabase method getChannels.
@Override
public List<Channel> getChannels() {
logger.trace("getChannels()");
List<Channel> channels = new LinkedList<Channel>();
EntityManager em = emf.createEntityManager();
String sqlQueryString = String.format("SELECT x FROM %s x", ChannelEntity.class.getSimpleName());
Query query = em.createQuery(sqlQueryString);
@SuppressWarnings("unchecked") List<ChannelEntity> resultList = query.getResultList();
for (ChannelEntity result : resultList) {
channels.add(result.convertToChannel());
}
logger.debug("retrieved {} channels", channels.size());
return channels;
}
use of io.joynr.messaging.info.Channel in project joynr by bmwcarit.
the class DatabasesTest method testAddChannels.
@Test
public void testAddChannels() {
Assert.assertEquals(0, channelDb.getChannels().size());
ControlledBounceProxyInformation bpInfo1 = new ControlledBounceProxyInformation("bp1.0", URI.create("http://www.joynr1.de/bp1/"));
Mockito.when(mockTimestampProvider.getCurrentTime()).thenReturn(1000l);
bounceProxyDb.addBounceProxy(bpInfo1);
channelDb.addChannel(new Channel(bpInfo1, "channel1", URI.create("http://www.joyn1.de/bp1/channels/channel1")));
List<Channel> channels = channelDb.getChannels();
Assert.assertEquals(1, channels.size());
Channel channel = channels.get(0);
Assert.assertEquals("channel1", channel.getChannelId());
Assert.assertEquals("bp1.0", channel.getBounceProxy().getId());
Assert.assertEquals("http://www.joyn1.de/bp1/channels/channel1", channel.getLocation().toString());
Assert.assertEquals(channel.getChannelId(), channelDb.getChannel("channel1").getChannelId());
channelDb.addChannel(new Channel(bpInfo1, "channel1b", URI.create("http://www.joyn1.de/bp1/channels/channel1b")));
channels = channelDb.getChannels();
Assert.assertEquals(2, channels.size());
Channel channel1b = channelDb.getChannel("channel1b");
Assert.assertNotNull(channel1b);
Assert.assertEquals("channel1b", channel1b.getChannelId());
Assert.assertEquals("bp1.0", channel1b.getBounceProxy().getId());
Assert.assertEquals("http://www.joyn1.de/bp1/channels/channel1b", channel1b.getLocation().toString());
ControlledBounceProxyInformation bpInfo2 = new ControlledBounceProxyInformation("bp2.0", URI.create("http://www.joynr2.de/bp2/"));
Mockito.when(mockTimestampProvider.getCurrentTime()).thenReturn(2000l);
bounceProxyDb.addBounceProxy(bpInfo2);
channelDb.addChannel(new Channel(bpInfo2, "channel2", URI.create("http://www.joyn1.de/bp1/channels/channel2")));
Assert.assertEquals(3, channelDb.getChannels().size());
}
use of io.joynr.messaging.info.Channel in project joynr by bmwcarit.
the class ChannelServiceImpl method createChannel.
/*
* (non-Javadoc)
*
* @see
* io.joynr.messaging.service.ChannelServiceDelegate#createChannel(java.
* lang.String, java.lang.String)
*/
@Override
public Channel createChannel(String ccid, String trackingId) {
try {
// The controller has to assign the channel to a bounce proxy
// instance.
ControlledBounceProxyInformation bpInfo = strategy.calculateBounceProxy(ccid);
URI channelLocation = bpFacade.createChannel(bpInfo, ccid, trackingId);
Channel channel = new Channel(bpInfo, ccid, channelLocation);
channelDirectory.addChannel(channel);
bounceProxyDirectory.updateChannelAssignment(ccid, bpInfo);
return channel;
} catch (Exception e) {
log.error("Could not create channel on bounce proxy: channel {}, error: {}", ccid, e.getMessage());
throw new JoynrRuntimeException("Error creating channel on bounce proxy", e);
}
}
use of io.joynr.messaging.info.Channel in project joynr by bmwcarit.
the class DefaultBounceProxyChannelServiceImpl method createChannel.
@Override
public Channel createChannel(String ccid, String trackingId) {
String channelPath = longPollingDelegate.createChannel(ccid, trackingId);
URI channelLocation = UriBuilder.fromUri(bpInfo.getLocation()).path(channelPath).build();
return new Channel(bpInfo, ccid, channelLocation);
}
use of io.joynr.messaging.info.Channel in project joynr by bmwcarit.
the class ChannelServiceRestAdapter method createChannel.
/**
* HTTP POST to create a channel, returns location to new resource which can
* then be long polled. Since the channel id may later change to be a UUID,
* not using a PUT but rather POST with used id being returned
* @param ccid cluster controller id
* @param atmosphereTrackingId tracking id for atmosphere
* @return location to new resource
*/
@POST
@Produces({ MediaType.TEXT_PLAIN })
public Response createChannel(@QueryParam("ccid") String ccid, @HeaderParam(ChannelServiceConstants.X_ATMOSPHERE_TRACKING_ID) String atmosphereTrackingId) {
try {
log.info("CREATE channel for channel ID: {}", ccid);
if (ccid == null || ccid.isEmpty())
throw new JoynrHttpException(Status.BAD_REQUEST, JOYNRMESSAGINGERROR_CHANNELNOTSET);
Channel channel = channelService.getChannel(ccid);
if (channel != null) {
String encodedChannelLocation = response.encodeURL(channel.getLocation().toString());
return Response.ok().entity(encodedChannelLocation).header("Location", encodedChannelLocation).header("bp", channel.getBounceProxy().getId()).build();
}
// look for an existing bounce proxy handling the channel
channel = channelService.createChannel(ccid, atmosphereTrackingId);
String encodedChannelLocation = response.encodeURL(channel.getLocation().toString());
log.debug("encoded channel URL " + channel.getLocation() + " to " + encodedChannelLocation);
return Response.created(URI.create(encodedChannelLocation)).entity(encodedChannelLocation).header("bp", channel.getBounceProxy().getId()).build();
} catch (WebApplicationException ex) {
throw ex;
} catch (Exception e) {
throw new WebApplicationException(e);
}
}
Aggregations