Example usage for io.netty.channel.embedded EmbeddedChannel attr

List of usage examples for io.netty.channel.embedded EmbeddedChannel attr

Introduction

In this page you can find the example usage for io.netty.channel.embedded EmbeddedChannel attr.

Prototype

@SuppressWarnings("unchecked")
    @Override
    public <T> Attribute<T> attr(AttributeKey<T> key) 

Source Link

Usage

From source file:cpw.mods.fml.common.network.internal.FMLNetworkHandler.java

License:Open Source License

public static void openGui(EntityPlayer entityPlayer, Object mod, int modGuiId, World world, int x, int y,
        int z) {//  ww  w.  j  a va 2  s . co m
    ModContainer mc = FMLCommonHandler.instance().findContainerFor(mod);
    if (entityPlayer instanceof EntityPlayerMP) {
        EntityPlayerMP entityPlayerMP = (EntityPlayerMP) entityPlayer;
        Container remoteGuiContainer = NetworkRegistry.INSTANCE.getRemoteGuiContainer(mc, entityPlayerMP,
                modGuiId, world, x, y, z);
        if (remoteGuiContainer != null) {
            entityPlayerMP.getNextWindowId();
            entityPlayerMP.closeContainer();
            int windowId = entityPlayerMP.currentWindowId;
            FMLMessage.OpenGui openGui = new FMLMessage.OpenGui(windowId, mc.getModId(), modGuiId, x, y, z);
            EmbeddedChannel embeddedChannel = channelPair.get(Side.SERVER);
            embeddedChannel.attr(FMLOutboundHandler.FML_MESSAGETARGET).set(OutboundTarget.PLAYER);
            embeddedChannel.attr(FMLOutboundHandler.FML_MESSAGETARGETARGS).set(entityPlayerMP);
            embeddedChannel.writeOutbound(openGui);
            entityPlayerMP.openContainer = remoteGuiContainer;
            entityPlayerMP.openContainer.windowId = windowId;
            entityPlayerMP.openContainer.addCraftingToCrafters(entityPlayerMP);
        }
    } else if (FMLCommonHandler.instance().getSide().equals(Side.CLIENT)) {
        Object guiContainer = NetworkRegistry.INSTANCE.getLocalGuiContainer(mc, entityPlayer, modGuiId, world,
                x, y, z);
        FMLCommonHandler.instance().showGuiScreen(guiContainer);
    } else {
        FMLLog.fine(
                "Invalid attempt to open a local GUI on a dedicated server. This is likely a bug. GUIID: %s,%d",
                mc.getModId(), modGuiId);
    }

}

From source file:cpw.mods.fml.common.network.internal.FMLNetworkHandler.java

License:Open Source License

public static void makeEntitySpawnAdjustment(Entity entity, EntityPlayerMP player, int serverX, int serverY,
        int serverZ) {
    EmbeddedChannel embeddedChannel = channelPair.get(Side.SERVER);
    embeddedChannel.attr(FMLOutboundHandler.FML_MESSAGETARGET).set(OutboundTarget.PLAYER);
    embeddedChannel.attr(FMLOutboundHandler.FML_MESSAGETARGETARGS).set(player);
    embeddedChannel.writeOutbound(new FMLMessage.EntityAdjustMessage(entity, serverX, serverY, serverZ));
}

From source file:cpw.mods.fml.common.network.internal.FMLNetworkHandler.java

License:Open Source License

public static void registerChannel(FMLContainer container, Side side) {
    channelPair = NetworkRegistry.INSTANCE.newChannel(container, "FML", new FMLRuntimeCodec(),
            new HandshakeCompletionHandler());
    EmbeddedChannel embeddedChannel = channelPair.get(Side.SERVER);
    embeddedChannel.attr(FMLOutboundHandler.FML_MESSAGETARGET).set(OutboundTarget.NOWHERE);

    if (side == Side.CLIENT) {
        addClientHandlers();/*  www .j  a v  a  2 s . c  o m*/
    }
}

From source file:org.wso2.carbon.transport.http.netty.redirect.HTTPClientRedirectTestCase.java

License:Open Source License

/**
 * Check whether, redirect request is written to the backend when a redirect response is received.
 *
 * @throws URISyntaxException/* w w w.  j a v  a  2s .  c o  m*/
 * @throws IOException
 */
@Test
public void unitTestForRedirectHandler() throws URISyntaxException, IOException {
    EmbeddedChannel embeddedChannel = new EmbeddedChannel();
    embeddedChannel.pipeline().addLast(new HttpResponseDecoder());
    embeddedChannel.pipeline().addLast(new HttpRequestEncoder());
    embeddedChannel.pipeline().addLast(new RedirectHandler(null, false, 5, false));
    HttpResponse response = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1,
            HttpResponseStatus.TEMPORARY_REDIRECT, Unpooled.EMPTY_BUFFER);
    response.headers().set(HttpHeaders.Names.LOCATION, FINAL_DESTINATION);
    embeddedChannel.attr(Constants.ORIGINAL_REQUEST)
            .set(createHttpRequest(Constants.HTTP_GET_METHOD, FINAL_DESTINATION));
    embeddedChannel.writeInbound(response);
    embeddedChannel.writeInbound(LastHttpContent.EMPTY_LAST_CONTENT);
    assertNotNull(embeddedChannel.readOutbound());
}

From source file:org.wso2.carbon.transport.http.netty.redirect.HTTPClientRedirectTestCase.java

License:Open Source License

/**
 * When the maximum redirect count reached, channel should not do any more redirects.
 *
 * @throws URISyntaxException/*from w  w w. j  a v  a  2  s.  c  om*/
 * @throws IOException
 */
@Test
public void unitTestForRedirectLoop() throws URISyntaxException, IOException {
    EmbeddedChannel embeddedChannel = new EmbeddedChannel();
    embeddedChannel.pipeline().addLast(new HttpResponseDecoder());
    embeddedChannel.pipeline().addLast(new HttpRequestEncoder());
    embeddedChannel.pipeline().addLast(Constants.IDLE_STATE_HANDLER,
            new IdleStateHandler(50000, 50000, 0, TimeUnit.MILLISECONDS));
    embeddedChannel.pipeline().addLast(new RedirectHandler(null, false, 5, false, null, false));
    HttpResponse response = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1,
            HttpResponseStatus.TEMPORARY_REDIRECT, Unpooled.EMPTY_BUFFER);
    response.headers().set(HttpHeaders.Names.LOCATION, FINAL_DESTINATION);
    embeddedChannel.attr(Constants.ORIGINAL_REQUEST)
            .set(createHttpRequest(Constants.HTTP_GET_METHOD, FINAL_DESTINATION));
    embeddedChannel.attr(Constants.RESPONSE_FUTURE_OF_ORIGINAL_CHANNEL).set(new HttpResponseFutureImpl());
    TargetChannel targetChannel = new TargetChannel(null, null);
    targetChannel.setChannel(embeddedChannel);
    embeddedChannel.attr(Constants.TARGET_CHANNEL_REFERENCE).set(targetChannel);
    embeddedChannel.attr(Constants.REDIRECT_COUNT).set(5);
    embeddedChannel.writeInbound(response);
    embeddedChannel.writeInbound(LastHttpContent.EMPTY_LAST_CONTENT);
    assertNull(embeddedChannel.readOutbound());
}