Search in sources :

Example 1 with ChannelGroup

use of org.jboss.netty.channel.group.ChannelGroup in project bagheera by mozilla-metrics.

the class Bagheera method startServer.

/**
     * Start a Bagheera server with the provided settings.
     * Throws if the server could not be started.
     * The caller is responsible for closing the returned instance, and the
     * channel factory if desired.
     */
public static BagheeraServerState startServer(final int port, final boolean tcpNoDelay, final WildcardProperties props, final Producer producer, final NioServerSocketChannelFactory channelFactory, final String channelGroupName, final MetricsManager manager) throws Exception {
    prepareHealthChecks();
    // HTTP server setup.
    final ChannelGroup channelGroup = new DefaultChannelGroup(channelGroupName);
    final ServerBootstrap server = new ServerBootstrap(channelFactory);
    final HttpServerPipelineFactory pipeFactory = new HttpServerPipelineFactory(props, producer, channelGroup, manager);
    server.setPipelineFactory(pipeFactory);
    server.setOption("tcpNoDelay", tcpNoDelay);
    // Disable keep-alive so client connections don't hang around.
    server.setOption("keepAlive", false);
    final Channel channel = server.bind(new InetSocketAddress(port));
    return new BagheeraServerState(port, producer, channelFactory, channel, channelGroup);
}
Also used : DefaultChannelGroup(org.jboss.netty.channel.group.DefaultChannelGroup) InetSocketAddress(java.net.InetSocketAddress) Channel(org.jboss.netty.channel.Channel) DefaultChannelGroup(org.jboss.netty.channel.group.DefaultChannelGroup) ChannelGroup(org.jboss.netty.channel.group.ChannelGroup) ServerBootstrap(org.jboss.netty.bootstrap.ServerBootstrap)

Example 2 with ChannelGroup

use of org.jboss.netty.channel.group.ChannelGroup in project bagheera by mozilla-metrics.

the class DummyProducer method setup.

@Before
public void setup() {
    validator = Mockito.mock(Validator.class);
    producer = new DummyProducer();
    channelGroup = Mockito.mock(ChannelGroup.class);
    manager = Mockito.mock(MetricsManager.class);
    HttpMetric metric = Mockito.mock(HttpMetric.class);
    Mockito.when(manager.getGlobalHttpMetric()).thenReturn(metric);
    Mockito.when(manager.getHttpMetricForNamespace(Mockito.anyString())).thenReturn(metric);
    mockChannelBuffer = Mockito.mock(ChannelBuffer.class);
    Mockito.when(mockChannelBuffer.readable()).thenReturn(true);
    Mockito.when(mockChannelBuffer.readableBytes()).thenReturn(1);
    Mockito.when(mockChannelBuffer.toByteBuffer()).thenReturn(ByteBuffer.allocate(1));
    mockChannel = Mockito.mock(Channel.class);
    mockFuture = Mockito.mock(ChannelFuture.class);
    Mockito.when(mockChannel.getRemoteAddress()).thenReturn(new InetSocketAddress("localhost", 8080));
    Mockito.when(mockChannel.write(Mockito.any())).thenReturn(mockFuture);
    // We get a NoClassDefFoundError without this.
    if (!new File("./target/classes/com/mozilla/bagheera/BagheeraProto.class").exists()) {
        fail("You must run 'mvn compile' before the tests will run properly from Eclipse");
    }
}
Also used : ChannelFuture(org.jboss.netty.channel.ChannelFuture) MetricsManager(com.mozilla.bagheera.metrics.MetricsManager) InetSocketAddress(java.net.InetSocketAddress) Channel(org.jboss.netty.channel.Channel) File(java.io.File) Validator(com.mozilla.bagheera.validation.Validator) ChannelGroup(org.jboss.netty.channel.group.ChannelGroup) HttpMetric(com.mozilla.bagheera.metrics.HttpMetric) ChannelBuffer(org.jboss.netty.buffer.ChannelBuffer) Before(org.junit.Before)

Aggregations

InetSocketAddress (java.net.InetSocketAddress)2 Channel (org.jboss.netty.channel.Channel)2 ChannelGroup (org.jboss.netty.channel.group.ChannelGroup)2 HttpMetric (com.mozilla.bagheera.metrics.HttpMetric)1 MetricsManager (com.mozilla.bagheera.metrics.MetricsManager)1 Validator (com.mozilla.bagheera.validation.Validator)1 File (java.io.File)1 ServerBootstrap (org.jboss.netty.bootstrap.ServerBootstrap)1 ChannelBuffer (org.jboss.netty.buffer.ChannelBuffer)1 ChannelFuture (org.jboss.netty.channel.ChannelFuture)1 DefaultChannelGroup (org.jboss.netty.channel.group.DefaultChannelGroup)1 Before (org.junit.Before)1