Toggle navigation
Toggle navigation
This project
Loading...
Sign in
홍길동
/
onos
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
pankaj
2014-10-10 15:40:43 -0700
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
9fc87594fd98512d8185f18cc8c7032c884dfd32
9fc87594
1 parent
38935e5f
cleaned-up to give better help and javadoc
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
98 additions
and
17 deletions
apps/foo/src/main/java/org/onlab/onos/foo/NettyEchoHandler.java
apps/foo/src/main/java/org/onlab/onos/foo/NettyNothingHandler.java
apps/foo/src/main/java/org/onlab/onos/foo/SimpleNettyClient.java
apps/foo/src/main/java/org/onlab/onos/foo/SimpleNettyClientCommand.java
apps/foo/src/main/java/org/onlab/onos/foo/SimpleNettyServer.java
apps/foo/src/main/java/org/onlab/onos/foo/NettyEchoHandler.java
View file @
9fc8759
...
...
@@ -4,8 +4,6 @@ import java.io.IOException;
import
org.onlab.netty.Message
;
import
org.onlab.netty.MessageHandler
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
/**
...
...
@@ -13,11 +11,8 @@ import org.slf4j.LoggerFactory;
*/
public
class
NettyEchoHandler
implements
MessageHandler
{
private
final
Logger
log
=
LoggerFactory
.
getLogger
(
getClass
());
@Override
public
void
handle
(
Message
message
)
throws
IOException
{
//log.info("Received message. Echoing it back to the sender.");
message
.
respond
(
message
.
payload
());
}
}
...
...
apps/foo/src/main/java/org/onlab/onos/foo/NettyNothingHandler.java
0 → 100644
View file @
9fc8759
package
org
.
onlab
.
onos
.
foo
;
import
org.onlab.netty.Message
;
import
org.onlab.netty.MessageHandler
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
/**
* A MessageHandler that simply logs the information.
*/
public
class
NettyNothingHandler
implements
MessageHandler
{
private
final
Logger
log
=
LoggerFactory
.
getLogger
(
getClass
());
@Override
public
void
handle
(
Message
message
)
{
// Do nothing
}
}
apps/foo/src/main/java/org/onlab/onos/foo/SimpleNettyClient.java
View file @
9fc8759
...
...
@@ -2,6 +2,7 @@ package org.onlab.onos.foo;
import
java.io.IOException
;
import
java.util.concurrent.ExecutionException
;
import
java.util.concurrent.TimeUnit
;
import
java.util.concurrent.TimeoutException
;
import
org.onlab.metrics.MetricsComponent
;
...
...
@@ -15,14 +16,29 @@ import org.slf4j.LoggerFactory;
import
com.codahale.metrics.Timer
;
/**
* The Simple netty client test.
*/
// FIXME: Should be move out to test or app
public
final
class
SimpleNettyClient
{
private
static
Logger
log
=
LoggerFactory
.
getLogger
(
SimpleNettyClient
.
class
);
static
NettyMessagingService
messaging
;
static
MetricsManager
metrics
;
private
SimpleNettyClient
()
{
}
/**
* The entry point of application.
*
* @param args the input arguments
* @throws IOException the iO exception
* @throws InterruptedException the interrupted exception
* @throws ExecutionException the execution exception
* @throws TimeoutException the timeout exception
*/
public
static
void
main
(
String
[]
args
)
throws
IOException
,
InterruptedException
,
ExecutionException
,
TimeoutException
{
...
...
@@ -34,13 +50,20 @@ private static Logger log = LoggerFactory.getLogger(SimpleNettyClient.class);
System
.
exit
(
0
);
}
/**
* Start standalone.
*
* @param args the args
* @throws Exception the exception
*/
public
static
void
startStandalone
(
String
[]
args
)
throws
Exception
{
String
host
=
args
.
length
>
0
?
args
[
0
]
:
"localhost"
;
int
port
=
args
.
length
>
1
?
Integer
.
parseInt
(
args
[
1
])
:
8081
;
int
warmup
=
args
.
length
>
2
?
Integer
.
parseInt
(
args
[
2
])
:
1000
;
int
iterations
=
args
.
length
>
3
?
Integer
.
parseInt
(
args
[
3
])
:
50
*
100000
;
NettyMessagingService
messaging
=
new
TestNettyMessagingService
(
9081
);
MetricsManager
metrics
=
new
MetricsManager
();
messaging
=
new
TestNettyMessagingService
(
9081
);
metrics
=
new
MetricsManager
();
Endpoint
endpoint
=
new
Endpoint
(
host
,
port
);
messaging
.
activate
();
metrics
.
activate
();
...
...
@@ -53,6 +76,7 @@ private static Logger log = LoggerFactory.getLogger(SimpleNettyClient.class);
Response
response
=
messaging
.
sendAndReceive
(
endpoint
,
"echo"
,
"Hello World"
.
getBytes
());
response
.
get
(
100000
,
TimeUnit
.
MILLISECONDS
);
}
log
.
info
(
"measuring async sender"
);
...
...
@@ -64,19 +88,47 @@ private static Logger log = LoggerFactory.getLogger(SimpleNettyClient.class);
context
.
stop
();
}
log
.
info
(
"measuring round-trip send & receive"
);
Timer
sendAndReceiveTimer
=
metrics
.
createTimer
(
component
,
feature
,
"SendAndReceive"
);
int
timeouts
=
0
;
for
(
int
i
=
0
;
i
<
iterations
;
i
++)
{
Response
response
;
Timer
.
Context
context
=
sendAndReceiveTimer
.
time
();
Response
response
=
messaging
.
sendAndReceive
(
endpoint
,
"echo"
,
"Hello World"
.
getBytes
());
try
{
response
=
messaging
.
sendAndReceive
(
endpoint
,
"echo"
,
"Hello World"
.
getBytes
());
response
.
get
(
10000
,
TimeUnit
.
MILLISECONDS
);
}
catch
(
TimeoutException
e
)
{
timeouts
++;
log
.
info
(
"timeout:"
+
timeouts
+
" at iteration:"
+
i
);
}
finally
{
context
.
stop
();
}
// System.out.println("Got back:" + new String(response.get(2, TimeUnit.SECONDS)));
context
.
stop
();
}
metrics
.
deactivate
();
}
public
static
void
stop
()
{
try
{
messaging
.
deactivate
();
metrics
.
deactivate
();
}
catch
(
Exception
e
)
{
log
.
info
(
"Unable to stop client %s"
,
e
);
}
}
/**
* The type Test netty messaging service.
*/
public
static
class
TestNettyMessagingService
extends
NettyMessagingService
{
/**
* Instantiates a new Test netty messaging service.
*
* @param port the port
* @throws Exception the exception
*/
public
TestNettyMessagingService
(
int
port
)
throws
Exception
{
super
(
port
);
}
...
...
apps/foo/src/main/java/org/onlab/onos/foo/SimpleNettyClientCommand.java
View file @
9fc8759
package
org
.
onlab
.
onos
.
foo
;
import
static
org
.
onlab
.
onos
.
foo
.
SimpleNettyClient
.
startStandalone
;
import
static
org
.
onlab
.
onos
.
foo
.
SimpleNettyClient
.
stop
;
import
org.apache.karaf.shell.commands.Argument
;
import
org.apache.karaf.shell.commands.Command
;
...
...
@@ -24,11 +25,11 @@ public class SimpleNettyClientCommand extends AbstractShellCommand {
@Argument
(
index
=
2
,
name
=
"warmupCount"
,
description
=
"Warm-up count"
,
required
=
false
,
multiValued
=
false
)
String
warmupCount
=
"1000"
;
String
warmupCount
=
"1000
0
"
;
@Argument
(
index
=
3
,
name
=
"messageCount"
,
description
=
"Message count"
,
required
=
false
,
multiValued
=
false
)
String
messageCount
=
"100000"
;
String
messageCount
=
"100000
0
"
;
@Override
protected
void
execute
()
{
...
...
@@ -37,5 +38,6 @@ public class SimpleNettyClientCommand extends AbstractShellCommand {
}
catch
(
Exception
e
)
{
error
(
"Unable to start client %s"
,
e
);
}
stop
();
}
}
...
...
apps/foo/src/main/java/org/onlab/onos/foo/SimpleNettyServer.java
View file @
9fc8759
...
...
@@ -12,17 +12,30 @@ import org.slf4j.LoggerFactory;
private
SimpleNettyServer
()
{}
public
static
void
main
(
String
...
args
)
throws
Exception
{
/**
* The entry point of application.
*
* @param args the input arguments
* @throws Exception the exception
*/
public
static
void
main
(
String
...
args
)
throws
Exception
{
startStandalone
(
args
);
System
.
exit
(
0
);
}
public
static
void
startStandalone
(
String
[]
args
)
throws
Exception
{
/**
* Start standalone server.
*
* @param args the args
* @throws Exception the exception
*/
public
static
void
startStandalone
(
String
[]
args
)
throws
Exception
{
int
port
=
args
.
length
>
0
?
Integer
.
parseInt
(
args
[
0
])
:
8081
;
NettyMessagingService
server
=
new
NettyMessagingService
(
port
);
server
.
activate
();
server
.
registerHandler
(
"simple"
,
new
Netty
Logg
ingHandler
());
server
.
registerHandler
(
"simple"
,
new
Netty
Noth
ingHandler
());
server
.
registerHandler
(
"echo"
,
new
NettyEchoHandler
());
log
.
info
(
"Netty Server server on port "
+
port
);
}
}
...
...
Please
register
or
login
to post a comment