Skip to content

Commit cb43c4a

Browse files
committed
* update baseio
1 parent c2f3e98 commit cb43c4a

File tree

3 files changed

+111
-94
lines changed

3 files changed

+111
-94
lines changed
501 KB
Binary file not shown.

baseio/pom.xml

Lines changed: 55 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,63 @@
1-
<project xmlns="http://maven.apache.org/POM/4.0.0"
2-
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3-
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
43
http://maven.apache.org/xsd/maven-4.0.0.xsd">
5-
<modelVersion>4.0.0</modelVersion>
6-
<groupId>com.generallycloud</groupId>
7-
<artifactId>baseio-example-microservices</artifactId>
8-
<name>Baseio Example Microservices</name>
9-
<version>1.0.0-SNAPSHOT</version>
4+
<modelVersion>4.0.0</modelVersion>
5+
<groupId>com.generallycloud</groupId>
6+
<artifactId>baseio-example-microservices</artifactId>
7+
<name>Baseio Example Microservices</name>
8+
<version>1.0.0-SNAPSHOT</version>
109

11-
<properties>
12-
<!-- the main class -->
13-
<exec.mainClass>example.Server</exec.mainClass>
14-
</properties>
10+
<properties>
11+
<!-- the main class -->
12+
<exec.mainClass>example.Server</exec.mainClass>
13+
</properties>
1514

16-
<dependencies>
17-
<dependency>
18-
<groupId>com.generallycloud</groupId>
19-
<artifactId>baseio-all</artifactId>
20-
<version>3.1.8-Alpha3</version>
21-
</dependency>
22-
</dependencies>
15+
<dependencies>
16+
<dependency>
17+
<groupId>com.generallycloud</groupId>
18+
<artifactId>baseio-all</artifactId>
19+
<version>baseio-all-3.2.6-SNAPSHOT</version>
20+
<scope>system</scope>
21+
<systemPath>${basedir}/lib/baseio-all-3.2.6-SNAPSHOT.jar</systemPath>
22+
</dependency>
23+
</dependencies>
2324

24-
<build>
25-
<plugins>
26-
<plugin>
27-
<artifactId>maven-compiler-plugin</artifactId>
28-
<version>3.6.1</version>
29-
<configuration>
30-
<source>1.8</source>
31-
<target>1.8</target>
32-
</configuration>
33-
</plugin>
25+
<build>
26+
<plugins>
3427
<plugin>
35-
<groupId>org.apache.maven.plugins</groupId>
36-
<artifactId>maven-shade-plugin</artifactId>
37-
<version>2.3</version>
38-
<executions>
39-
<execution>
40-
<phase>package</phase>
41-
<goals>
42-
<goal>shade</goal>
43-
</goals>
44-
<configuration>
28+
<artifactId>maven-compiler-plugin</artifactId>
29+
<version>3.6.1</version>
30+
<configuration>
31+
<source>1.8</source>
32+
<target>1.8</target>
33+
</configuration>
34+
</plugin>
35+
<plugin>
36+
<groupId>org.apache.maven.plugins</groupId>
37+
<artifactId>maven-shade-plugin</artifactId>
38+
<version>2.3</version>
39+
<executions>
40+
<execution>
41+
<phase>package</phase>
42+
<goals>
43+
<goal>shade</goal>
44+
</goals>
45+
<configuration>
4546
<transformers>
46-
<transformer
47-
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
48-
<manifestEntries>
49-
<Main-Class>${exec.mainClass}</Main-Class>
50-
</manifestEntries>
51-
</transformer>
52-
</transformers>
53-
<outputFile>${project.build.directory}/${project.artifactId}-fat.jar
54-
</outputFile>
55-
</configuration>
56-
</execution>
57-
</executions>
58-
</plugin>
59-
</plugins>
60-
</build>
47+
<transformer
48+
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
49+
<manifestEntries>
50+
<Main-Class>${exec.mainClass}</Main-Class>
51+
</manifestEntries>
52+
</transformer>
53+
</transformers>
54+
<outputFile>${project.build.directory}/${project.artifactId}-fat.jar
55+
</outputFile>
56+
</configuration>
57+
</execution>
58+
</executions>
59+
</plugin>
60+
</plugins>
61+
</build>
6162

6263
</project>
Lines changed: 56 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,59 @@
11
package example;
22

3-
import com.generallycloud.nio.acceptor.SocketChannelAcceptor;
4-
import com.generallycloud.nio.codec.http11.ServerHTTPProtocolFactory;
5-
import com.generallycloud.nio.component.IoEventHandleAdaptor;
6-
import com.generallycloud.nio.component.NioSocketChannelContext;
7-
import com.generallycloud.nio.component.SocketChannelContext;
8-
import com.generallycloud.nio.component.SocketSession;
9-
import com.generallycloud.nio.configuration.ServerConfiguration;
10-
import com.generallycloud.nio.protocol.ReadFuture;
11-
12-
public class Server {
13-
14-
public static void main(String[] args) throws Exception {
15-
16-
IoEventHandleAdaptor eventHandleAdaptor = new IoEventHandleAdaptor() {
17-
@Override
18-
public void accept(SocketSession session, ReadFuture future) throws Exception {
19-
future.write("Hello World!");
20-
session.flush(future);
21-
}
22-
};
23-
24-
ServerConfiguration c = new ServerConfiguration(8080);
25-
26-
c.setSERVER_MEMORY_POOL_UNIT(256);
27-
c.setSERVER_ENABLE_MEMORY_POOL_DIRECT(true);
28-
//c.setSERVER_CORE_SIZE(2);
29-
c.setSERVER_ENABLE_MEMORY_POOL(true);
30-
c.setSERVER_MEMORY_POOL_CAPACITY_RATE(4);
31-
32-
SocketChannelContext context = new NioSocketChannelContext(c);
33-
34-
SocketChannelAcceptor acceptor = new SocketChannelAcceptor(context);
35-
36-
context.setIoEventHandleAdaptor(eventHandleAdaptor);
37-
context.setProtocolFactory(new ServerHTTPProtocolFactory());
38-
39-
acceptor.bind();
40-
41-
}
42-
3+
import java.net.StandardSocketOptions;
4+
import java.util.ArrayList;
5+
import java.util.List;
6+
7+
import com.generallycloud.baseio.buffer.ByteBuf;
8+
import com.generallycloud.baseio.codec.http11.ServerHttpCodec;
9+
import com.generallycloud.baseio.component.ChannelAcceptor;
10+
import com.generallycloud.baseio.component.ChannelContext;
11+
import com.generallycloud.baseio.component.ChannelEventListenerAdapter;
12+
import com.generallycloud.baseio.component.IoEventHandle;
13+
import com.generallycloud.baseio.component.LoggerChannelOpenListener;
14+
import com.generallycloud.baseio.component.NioEventLoopGroup;
15+
import com.generallycloud.baseio.component.NioSocketChannel;
16+
import com.generallycloud.baseio.protocol.Future;
17+
18+
public class Server {
19+
20+
public static void main(String[] args) throws Exception {
21+
22+
NioEventLoopGroup group = new NioEventLoopGroup();
23+
group.setMemoryPoolCapacity(1024 * 64);
24+
group.setMemoryPoolUnit(512);
25+
ChannelContext context = new ChannelContext(8087);
26+
ChannelAcceptor acceptor = new ChannelAcceptor(context, group);
27+
context.setProtocolCodec(new ServerHttpCodec(1024 * 4));
28+
context.setMaxWriteBacklog(Integer.MAX_VALUE);
29+
context.addChannelEventListener(new LoggerChannelOpenListener());
30+
context.addChannelEventListener(new ChannelEventListenerAdapter() {
31+
32+
@Override
33+
public void channelOpened(NioSocketChannel channel) throws Exception {
34+
channel.setOption(StandardSocketOptions.TCP_NODELAY, true);
35+
channel.setIoEventHandle(new IoEventHandle() {
36+
boolean addTask = true;
37+
List<ByteBuf> fs = new ArrayList<>(256);
38+
39+
@Override
40+
public void accept(NioSocketChannel channel, Future future) throws Exception {
41+
future.write("Hello World", channel);
42+
fs.add(channel.encode(future));
43+
if (addTask) {
44+
addTask = false;
45+
channel.getEventLoop().dispatchAfterLoop(() -> {
46+
channel.flush(fs);
47+
addTask = true;
48+
fs.clear();
49+
});
50+
}
51+
}
52+
});
53+
}
54+
});
55+
56+
acceptor.bind();
57+
}
58+
4359
}

0 commit comments

Comments
 (0)