Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Store connection on channel to avoid hash lookup every time
- Loading branch information
Showing
10 changed files
with
230 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
src/main/java/io/vertx/core/http/impl/VertxNioServerChannelFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,30 @@ | |||
/* | |||
* Copyright 2014 Red Hat, Inc. | |||
* | |||
* All rights reserved. This program and the accompanying materials | |||
* are made available under the terms of the Eclipse Public License v1.0 | |||
* and Apache License v2.0 which accompanies this distribution. | |||
* | |||
* The Eclipse Public License is available at | |||
* http://www.eclipse.org/legal/epl-v10.html | |||
* | |||
* The Apache License v2.0 is available at | |||
* http://www.opensource.org/licenses/apache2.0.php | |||
* | |||
* You may elect to redistribute this code under either of these licenses. | |||
*/ | |||
|
|||
package io.vertx.core.http.impl; | |||
|
|||
import io.netty.bootstrap.ChannelFactory; | |||
|
|||
/** | |||
* @author <a href="http://tfox.org">Tim Fox</a> | |||
*/ | |||
public class VertxNioServerChannelFactory implements ChannelFactory<VertxNioServerSocketChannel> { | |||
|
|||
@Override | |||
public VertxNioServerSocketChannel newChannel() { | |||
return new VertxNioServerSocketChannel(); | |||
} | |||
} |
54 changes: 54 additions & 0 deletions
54
src/main/java/io/vertx/core/http/impl/VertxNioServerSocketChannel.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,54 @@ | |||
/* | |||
* Copyright 2014 Red Hat, Inc. | |||
* | |||
* All rights reserved. This program and the accompanying materials | |||
* are made available under the terms of the Eclipse Public License v1.0 | |||
* and Apache License v2.0 which accompanies this distribution. | |||
* | |||
* The Eclipse Public License is available at | |||
* http://www.eclipse.org/legal/epl-v10.html | |||
* | |||
* The Apache License v2.0 is available at | |||
* http://www.opensource.org/licenses/apache2.0.php | |||
* | |||
* You may elect to redistribute this code under either of these licenses. | |||
*/ | |||
|
|||
package io.vertx.core.http.impl; | |||
|
|||
import io.netty.channel.socket.nio.NioServerSocketChannel; | |||
import io.vertx.core.logging.Logger; | |||
import io.vertx.core.logging.LoggerFactory; | |||
|
|||
import java.nio.channels.SocketChannel; | |||
import java.util.List; | |||
|
|||
/** | |||
* @author <a href="http://tfox.org">Tim Fox</a> | |||
*/ | |||
public class VertxNioServerSocketChannel extends NioServerSocketChannel { | |||
|
|||
private static final Logger log = LoggerFactory.getLogger(VertxNioServerSocketChannel.class); | |||
|
|||
@Override | |||
protected int doReadMessages(List<Object> buf) throws Exception { | |||
SocketChannel ch = javaChannel().accept(); | |||
|
|||
try { | |||
if (ch != null) { | |||
buf.add(new VertxNioSocketChannel(this, ch)); | |||
return 1; | |||
} | |||
} catch (Throwable t) { | |||
log.warn("Failed to create a new channel from an accepted socket.", t); | |||
|
|||
try { | |||
ch.close(); | |||
} catch (Throwable t2) { | |||
log.warn("Failed to close a socket.", t2); | |||
} | |||
} | |||
|
|||
return 0; | |||
} | |||
} |
42 changes: 42 additions & 0 deletions
42
src/main/java/io/vertx/core/http/impl/VertxNioSocketChannel.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,42 @@ | |||
/* | |||
* Copyright 2014 Red Hat, Inc. | |||
* | |||
* All rights reserved. This program and the accompanying materials | |||
* are made available under the terms of the Eclipse Public License v1.0 | |||
* and Apache License v2.0 which accompanies this distribution. | |||
* | |||
* The Eclipse Public License is available at | |||
* http://www.eclipse.org/legal/epl-v10.html | |||
* | |||
* The Apache License v2.0 is available at | |||
* http://www.opensource.org/licenses/apache2.0.php | |||
* | |||
* You may elect to redistribute this code under either of these licenses. | |||
*/ | |||
|
|||
package io.vertx.core.http.impl; | |||
|
|||
import io.netty.channel.Channel; | |||
import io.netty.channel.socket.nio.NioSocketChannel; | |||
|
|||
import java.nio.channels.SocketChannel; | |||
|
|||
/** | |||
* We provide this class so we can store a reference to the connection on it. | |||
* | |||
* This means we don't have to do a lookup in the connectionMap for every message received which improves | |||
* performance. | |||
* | |||
* @author <a href="http://tfox.org">Tim Fox</a> | |||
*/ | |||
public class VertxNioSocketChannel<C> extends NioSocketChannel { | |||
|
|||
public C conn; | |||
|
|||
public VertxNioSocketChannel(Channel parent, SocketChannel socket) { | |||
super(parent, socket); | |||
} | |||
|
|||
public VertxNioSocketChannel() { | |||
} | |||
} |
30 changes: 30 additions & 0 deletions
30
src/main/java/io/vertx/core/http/impl/VertxNioSocketChannelFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,30 @@ | |||
/* | |||
* Copyright 2014 Red Hat, Inc. | |||
* | |||
* All rights reserved. This program and the accompanying materials | |||
* are made available under the terms of the Eclipse Public License v1.0 | |||
* and Apache License v2.0 which accompanies this distribution. | |||
* | |||
* The Eclipse Public License is available at | |||
* http://www.eclipse.org/legal/epl-v10.html | |||
* | |||
* The Apache License v2.0 is available at | |||
* http://www.opensource.org/licenses/apache2.0.php | |||
* | |||
* You may elect to redistribute this code under either of these licenses. | |||
*/ | |||
|
|||
package io.vertx.core.http.impl; | |||
|
|||
import io.netty.bootstrap.ChannelFactory; | |||
|
|||
/** | |||
* @author <a href="http://tfox.org">Tim Fox</a> | |||
*/ | |||
public class VertxNioSocketChannelFactory implements ChannelFactory<VertxNioSocketChannel> { | |||
|
|||
@Override | |||
public VertxNioSocketChannel newChannel() { | |||
return new VertxNioSocketChannel<>(); | |||
} | |||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.