Search in sources :

Example 1 with Channel

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;
}
Also used : EntityManager(javax.persistence.EntityManager) Query(javax.persistence.Query) Channel(io.joynr.messaging.info.Channel) ChannelEntity(io.joynr.messaging.bounceproxy.controller.directory.jdbc.entities.ChannelEntity) LinkedList(java.util.LinkedList)

Example 2 with Channel

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());
}
Also used : Channel(io.joynr.messaging.info.Channel) ControlledBounceProxyInformation(io.joynr.messaging.info.ControlledBounceProxyInformation) Test(org.junit.Test)

Example 3 with Channel

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);
    }
}
Also used : Channel(io.joynr.messaging.info.Channel) ControlledBounceProxyInformation(io.joynr.messaging.info.ControlledBounceProxyInformation) JoynrRuntimeException(io.joynr.exceptions.JoynrRuntimeException) URI(java.net.URI) JoynrRuntimeException(io.joynr.exceptions.JoynrRuntimeException) JoynrCommunicationException(io.joynr.exceptions.JoynrCommunicationException)

Example 4 with Channel

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);
}
Also used : Channel(io.joynr.messaging.info.Channel) URI(java.net.URI)

Example 5 with Channel

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);
    }
}
Also used : JoynrHttpException(io.joynr.communications.exceptions.JoynrHttpException) WebApplicationException(javax.ws.rs.WebApplicationException) Channel(io.joynr.messaging.info.Channel) JoynrHttpException(io.joynr.communications.exceptions.JoynrHttpException) WebApplicationException(javax.ws.rs.WebApplicationException) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces)

Aggregations

Channel (io.joynr.messaging.info.Channel)11 ControlledBounceProxyInformation (io.joynr.messaging.info.ControlledBounceProxyInformation)5 Test (org.junit.Test)5 URI (java.net.URI)2 LinkedList (java.util.LinkedList)2 EntityManager (javax.persistence.EntityManager)2 Query (javax.persistence.Query)2 JoynrHttpException (io.joynr.communications.exceptions.JoynrHttpException)1 JoynrCommunicationException (io.joynr.exceptions.JoynrCommunicationException)1 JoynrRuntimeException (io.joynr.exceptions.JoynrRuntimeException)1 BounceProxyRecord (io.joynr.messaging.bounceproxy.controller.directory.BounceProxyRecord)1 ChannelEntity (io.joynr.messaging.bounceproxy.controller.directory.jdbc.entities.ChannelEntity)1 BounceProxyInformation (io.joynr.messaging.info.BounceProxyInformation)1 ChannelInformation (io.joynr.messaging.info.ChannelInformation)1 EntityTransaction (javax.persistence.EntityTransaction)1 POST (javax.ws.rs.POST)1 Produces (javax.ws.rs.Produces)1 WebApplicationException (javax.ws.rs.WebApplicationException)1 Ignore (org.junit.Ignore)1