Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit570a300

Browse files
committed
Some changes to further polishiluwatar#74
1 parente5f1ff1 commit570a300

File tree

8 files changed

+107
-69
lines changed

8 files changed

+107
-69
lines changed

‎reactor/etc/reactor.png

1.41 KB
Loading

‎reactor/etc/reactor.ucls

Lines changed: 75 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -124,80 +124,108 @@
124124
<operationspublic="true"package="true"protected="true"private="false"static="true"/>
125125
</display>
126126
</class>
127-
<realizationid="14">
128-
<endtype="SOURCE"refId="5"/>
129-
<endtype="TARGET"refId="3"/>
130-
</realization>
131-
<associationid="15">
132-
<endtype="SOURCE"refId="2"navigable="false">
133-
<attributeid="16"name="dispatcher"/>
134-
<multiplicityid="17"minimum="0"maximum="1"/>
127+
<associationid="14">
128+
<endtype="SOURCE"refId="13"navigable="false">
129+
<attributeid="15"name="dispatcher"/>
130+
<multiplicityid="16"minimum="0"maximum="1"/>
135131
</end>
136132
<endtype="TARGET"refId="3"navigable="true"/>
137133
<displaylabels="true"multiplicity="true"/>
138134
</association>
139-
<realizationid="18">
140-
<bendpointx="309"y="348"/>
141-
<endtype="SOURCE"refId="4"/>
142-
<endtype="TARGET"refId="3"/>
143-
</realization>
144-
<associationid="19">
145-
<bendpointx="460"y="203"/>
146-
<endtype="SOURCE"refId="13"navigable="false">
147-
<attributeid="20"name="reactor"/>
148-
<multiplicityid="21"minimum="0"maximum="1"/>
135+
<associationid="17">
136+
<endtype="SOURCE"refId="2"navigable="false">
137+
<attributeid="18"name="selector">
138+
<positionheight="0"width="0"x="0"y="0"/>
139+
</attribute>
140+
<multiplicityid="19"minimum="0"maximum="1">
141+
<positionheight="0"width="0"x="0"y="0"/>
142+
</multiplicity>
149143
</end>
150-
<endtype="TARGET"refId="2"navigable="true"/>
144+
<endtype="TARGET"refId="1"navigable="true"/>
151145
<displaylabels="true"multiplicity="true"/>
152146
</association>
153-
<dependencyid="22">
147+
<dependencyid="20">
154148
<endtype="SOURCE"refId="8"/>
155149
<endtype="TARGET"refId="10"/>
156150
</dependency>
157-
<generalizationid="23">
151+
<generalizationid="21">
158152
<endtype="SOURCE"refId="7"/>
159153
<endtype="TARGET"refId="6"/>
160154
</generalization>
155+
<realizationid="22">
156+
<bendpointx="309"y="348"/>
157+
<endtype="SOURCE"refId="4"/>
158+
<endtype="TARGET"refId="3"/>
159+
</realization>
160+
<dependencyid="23">
161+
<endtype="SOURCE"refId="13"/>
162+
<endtype="TARGET"refId="12"/>
163+
</dependency>
161164
<associationid="24">
162165
<endtype="SOURCE"refId="6"navigable="false">
163-
<attributeid="25"name="handler"/>
164-
<multiplicityid="26"minimum="0"maximum="1"/>
166+
<attributeid="25"name="handler">
167+
<positionheight="0"width="0"x="0"y="0"/>
168+
</attribute>
169+
<multiplicityid="26"minimum="0"maximum="1">
170+
<positionheight="0"width="0"x="0"y="0"/>
171+
</multiplicity>
165172
</end>
166173
<endtype="TARGET"refId="11"navigable="true"/>
167174
<displaylabels="true"multiplicity="true"/>
168175
</association>
169-
<associationid="27">
170-
<endtype="SOURCE"refId="6"navigable="false">
171-
<attributeid="28"name="reactor"/>
172-
<multiplicityid="29"minimum="0"maximum="1"/>
173-
</end>
174-
<endtype="TARGET"refId="2"navigable="true"/>
175-
<displaylabels="true"multiplicity="true"/>
176-
</association>
177-
<dependencyid="30">
178-
<endtype="SOURCE"refId="13"/>
179-
<endtype="TARGET"refId="12"/>
176+
<dependencyid="27">
177+
<endtype="SOURCE"refId="7"/>
178+
<endtype="TARGET"refId="9"/>
180179
</dependency>
181-
<associationid="31">
180+
<generalizationid="28">
181+
<endtype="SOURCE"refId="8"/>
182+
<endtype="TARGET"refId="6"/>
183+
</generalization>
184+
<associationid="29">
182185
<endtype="SOURCE"refId="2"navigable="false">
183-
<attributeid="32"name="selector"/>
184-
<multiplicityid="33"minimum="0"maximum="1"/>
186+
<attributeid="30"name="dispatcher">
187+
<positionheight="0"width="0"x="0"y="0"/>
188+
</attribute>
189+
<multiplicityid="31"minimum="0"maximum="1">
190+
<positionheight="0"width="0"x="0"y="0"/>
191+
</multiplicity>
185192
</end>
186-
<endtype="TARGET"refId="1"navigable="true"/>
193+
<endtype="TARGET"refId="3"navigable="true"/>
187194
<displaylabels="true"multiplicity="true"/>
188195
</association>
189-
<realizationid="34">
196+
<realizationid="32">
190197
<endtype="SOURCE"refId="12"/>
191198
<endtype="TARGET"refId="11"/>
192199
</realization>
193-
<generalizationid="35">
194-
<endtype="SOURCE"refId="8"/>
195-
<endtype="TARGET"refId="6"/>
196-
</generalization>
197-
<dependencyid="36">
198-
<endtype="SOURCE"refId="7"/>
199-
<endtype="TARGET"refId="9"/>
200-
</dependency>
200+
<associationid="33">
201+
<bendpointx="460"y="203"/>
202+
<endtype="SOURCE"refId="13"navigable="false">
203+
<attributeid="34"name="reactor">
204+
<positionheight="0"width="0"x="0"y="0"/>
205+
</attribute>
206+
<multiplicityid="35"minimum="0"maximum="1">
207+
<positionheight="0"width="0"x="0"y="0"/>
208+
</multiplicity>
209+
</end>
210+
<endtype="TARGET"refId="2"navigable="true"/>
211+
<displaylabels="true"multiplicity="true"/>
212+
</association>
213+
<associationid="36">
214+
<endtype="SOURCE"refId="6"navigable="false">
215+
<attributeid="37"name="reactor">
216+
<positionheight="0"width="0"x="0"y="0"/>
217+
</attribute>
218+
<multiplicityid="38"minimum="0"maximum="1">
219+
<positionheight="0"width="0"x="0"y="0"/>
220+
</multiplicity>
221+
</end>
222+
<endtype="TARGET"refId="2"navigable="true"/>
223+
<displaylabels="true"multiplicity="true"/>
224+
</association>
225+
<realizationid="39">
226+
<endtype="SOURCE"refId="5"/>
227+
<endtype="TARGET"refId="3"/>
228+
</realization>
201229
<classifier-displayautosize="true"stereotype="true"package="true"initial-value="false"signature="true"
202230
sort-features="false"accessors="true"visibility="true">
203231
<attributespublic="true"package="true"protected="true"private="true"static="true"/>

‎reactor/src/main/java/com/iluwatar/reactor/app/App.java

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,23 +66,31 @@ public class App {
6666

6767
privateNioReactorreactor;
6868
privateList<AbstractNioChannel>channels =newArrayList<>();
69+
privateDispatcherdispatcher;
70+
71+
/**
72+
* Creates an instance of App which will use provided dispatcher for dispatching events on reactor.
73+
* @param dispatcher the dispatcher that will be used to dispatch events.
74+
*/
75+
publicApp(Dispatcherdispatcher) {
76+
this.dispatcher =dispatcher;
77+
}
6978

7079
/**
7180
* App entry.
7281
*
7382
* @throws IOException
7483
*/
7584
publicstaticvoidmain(String[]args)throwsIOException {
76-
newApp().start(newThreadPoolDispatcher(2));
85+
newApp(newThreadPoolDispatcher(2)).start();
7786
}
7887

7988
/**
8089
* Starts the NIO reactor.
81-
* @param threadPoolDispatcher
82-
*
90+
*
8391
* @throws IOException if any channel fails to bind.
8492
*/
85-
publicvoidstart(Dispatcherdispatcher)throwsIOException {
93+
publicvoidstart()throwsIOException {
8694
/*
8795
* The application can customize its event dispatching mechanism.
8896
*/
@@ -110,8 +118,9 @@ public void start(Dispatcher dispatcher) throws IOException {
110118
*/
111119
publicvoidstop()throwsInterruptedException,IOException {
112120
reactor.stop();
121+
dispatcher.stop();
113122
for (AbstractNioChannelchannel :channels) {
114-
channel.getChannel().close();
123+
channel.getJavaChannel().close();
115124
}
116125
}
117126

‎reactor/src/main/java/com/iluwatar/reactor/framework/AbstractNioChannel.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ void setReactor(NioReactor reactor) {
4848
/**
4949
* @return the wrapped NIO channel.
5050
*/
51-
publicSelectableChannelgetChannel() {
51+
publicSelectableChannelgetJavaChannel() {
5252
returnchannel;
5353
}
5454

‎reactor/src/main/java/com/iluwatar/reactor/framework/NioDatagramChannel.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@ public DatagramPacket read(SelectionKey key) throws IOException {
6464
* @return the underlying datagram channel.
6565
*/
6666
@Override
67-
publicDatagramChannelgetChannel() {
68-
return (DatagramChannel)super.getChannel();
67+
publicDatagramChannelgetJavaChannel() {
68+
return (DatagramChannel)super.getJavaChannel();
6969
}
7070

7171
/**
@@ -75,8 +75,8 @@ public DatagramChannel getChannel() {
7575
*/
7676
@Override
7777
publicvoidbind()throwsIOException {
78-
getChannel().socket().bind(newInetSocketAddress(InetAddress.getLocalHost(),port));
79-
getChannel().configureBlocking(false);
78+
getJavaChannel().socket().bind(newInetSocketAddress(InetAddress.getLocalHost(),port));
79+
getJavaChannel().configureBlocking(false);
8080
System.out.println("Bound UDP socket at port: " +port);
8181
}
8282

@@ -87,7 +87,7 @@ public void bind() throws IOException {
8787
@Override
8888
protectedvoiddoWrite(ObjectpendingWrite,SelectionKeykey)throwsIOException {
8989
DatagramPacketpendingPacket = (DatagramPacket)pendingWrite;
90-
getChannel().send(pendingPacket.getData(),pendingPacket.getReceiver());
90+
getJavaChannel().send(pendingPacket.getData(),pendingPacket.getReceiver());
9191
}
9292

9393
/**

‎reactor/src/main/java/com/iluwatar/reactor/framework/NioReactor.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,13 @@ public void start() throws IOException {
7474
* Stops the reactor and related resources such as dispatcher.
7575
*
7676
* @throws InterruptedException if interrupted while stopping the reactor.
77+
* @throws IOException if any I/O error occurs.
7778
*/
78-
publicvoidstop()throwsInterruptedException {
79+
publicvoidstop()throwsInterruptedException,IOException {
7980
reactorMain.shutdownNow();
8081
selector.wakeup();
8182
reactorMain.awaitTermination(4,TimeUnit.SECONDS);
82-
dispatcher.stop();
83+
selector.close();
8384
}
8485

8586
/**
@@ -94,7 +95,7 @@ public void stop() throws InterruptedException {
9495
* @throws IOException if any I/O error occurs.
9596
*/
9697
publicNioReactorregisterChannel(AbstractNioChannelchannel)throwsIOException {
97-
SelectionKeykey =channel.getChannel().register(selector,channel.getInterestedOps());
98+
SelectionKeykey =channel.getJavaChannel().register(selector,channel.getInterestedOps());
9899
key.attach(channel);
99100
channel.setReactor(this);
100101
returnthis;

‎reactor/src/main/java/com/iluwatar/reactor/framework/NioServerSocketChannel.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ public int getInterestedOps() {
4343
* @return the underlying {@link ServerSocketChannel}.
4444
*/
4545
@Override
46-
publicServerSocketChannelgetChannel() {
47-
return (ServerSocketChannel)super.getChannel();
46+
publicServerSocketChannelgetJavaChannel() {
47+
return (ServerSocketChannel)super.getJavaChannel();
4848
}
4949

5050
/**
@@ -71,8 +71,8 @@ public ByteBuffer read(SelectionKey key) throws IOException {
7171
*/
7272
@Override
7373
publicvoidbind()throwsIOException {
74-
((ServerSocketChannel)getChannel()).socket().bind(newInetSocketAddress(InetAddress.getLocalHost(),port));
75-
((ServerSocketChannel)getChannel()).configureBlocking(false);
74+
((ServerSocketChannel)getJavaChannel()).socket().bind(newInetSocketAddress(InetAddress.getLocalHost(),port));
75+
((ServerSocketChannel)getJavaChannel()).configureBlocking(false);
7676
System.out.println("Bound TCP socket at port: " +port);
7777
}
7878

‎reactor/src/test/java/com/iluwatar/reactor/app/AppTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ public class AppTest {
2222
*/
2323
@Test
2424
publicvoidtestAppUsingThreadPoolDispatcher()throwsIOException,InterruptedException {
25-
Appapp =newApp();
26-
app.start(newThreadPoolDispatcher(2));
25+
Appapp =newApp(newThreadPoolDispatcher(2));
26+
app.start();
2727

2828
AppClientclient =newAppClient();
2929
client.start();
@@ -48,8 +48,8 @@ public void testAppUsingThreadPoolDispatcher() throws IOException, InterruptedEx
4848
*/
4949
@Test
5050
publicvoidtestAppUsingSameThreadDispatcher()throwsIOException,InterruptedException {
51-
Appapp =newApp();
52-
app.start(newSameThreadDispatcher());
51+
Appapp =newApp(newSameThreadDispatcher());
52+
app.start();
5353

5454
AppClientclient =newAppClient();
5555
client.start();

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp