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-07 17:18:37 -0700
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
366ce8b168b4b8eb7706d6a4a3b55751cc91c2e0
366ce8b1
1 parent
600bb24b
Create handles and default to console reported for metrics
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
65 additions
and
18 deletions
apps/foo/src/main/java/org/onlab/onos/foo/NettyEchoHandler.java
apps/foo/src/main/java/org/onlab/onos/foo/NettyLoggingHandler.java
apps/foo/src/main/java/org/onlab/onos/foo/SimpleNettyClient.java
apps/foo/src/main/java/org/onlab/onos/foo/SimpleNettyServer.java
features/features.xml
utils/misc/src/main/java/org/onlab/metrics/MetricsManager.java
apps/foo/src/main/java/org/onlab/onos/foo/NettyEchoHandler.java
0 → 100644
View file @
366ce8b
package
org
.
onlab
.
onos
.
foo
;
import
java.io.IOException
;
import
org.onlab.netty.Message
;
import
org.onlab.netty.MessageHandler
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
/**
* Message handler that echos the message back to the sender.
*/
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/NettyLoggingHandler.java
0 → 100644
View file @
366ce8b
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
NettyLoggingHandler
implements
MessageHandler
{
private
final
Logger
log
=
LoggerFactory
.
getLogger
(
getClass
());
@Override
public
void
handle
(
Message
message
)
{
log
.
info
(
"Received message. Payload has {} bytes"
,
message
.
payload
().
length
);
}
}
apps/foo/src/main/java/org/onlab/onos/foo/SimpleNettyClient.java
View file @
366ce8b
...
...
@@ -2,7 +2,6 @@ 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
;
...
...
@@ -35,28 +34,37 @@ public final class SimpleNettyClient {
MetricsManager
metrics
=
new
MetricsManager
();
messaging
.
activate
();
metrics
.
activate
();
MetricsFeature
feature
=
new
MetricsFeature
(
"
timers
"
);
MetricsFeature
feature
=
new
MetricsFeature
(
"
latency
"
);
MetricsComponent
component
=
metrics
.
registerComponent
(
"NettyMessaging"
);
Timer
sendAsyncTimer
=
metrics
.
createTimer
(
component
,
feature
,
"AsyncSender"
);
final
int
warmup
=
100
;
for
(
int
i
=
0
;
i
<
warmup
;
i
++)
{
messaging
.
sendAsync
(
new
Endpoint
(
"localhost"
,
8081
),
"simple"
,
"Hello World"
.
getBytes
());
Response
response
=
messaging
.
sendAndReceive
(
new
Endpoint
(
"localhost"
,
8081
),
"echo"
,
"Hello World"
.
getBytes
());
}
final
int
iterations
=
10000
;
for
(
int
i
=
0
;
i
<
iterations
;
i
++)
{
Timer
.
Context
context
=
sendAsyncTimer
.
time
();
messaging
.
sendAsync
(
new
Endpoint
(
"localhost"
,
808
0
),
"simple"
,
"Hello World"
.
getBytes
());
messaging
.
sendAsync
(
new
Endpoint
(
"localhost"
,
808
1
),
"simple"
,
"Hello World"
.
getBytes
());
context
.
stop
();
}
metrics
.
registerMetric
(
component
,
feature
,
"AsyncTimer"
,
sendAsyncTimer
);
Timer
sendAndReceiveTimer
=
metrics
.
createTimer
(
component
,
feature
,
"SendAndReceive"
);
final
int
iterations
=
1000000
;
for
(
int
i
=
0
;
i
<
iterations
;
i
++)
{
Timer
.
Context
context
=
sendAndReceiveTimer
.
time
();
Response
response
=
messaging
.
sendAndReceive
(
new
Endpoint
(
"localhost"
,
808
0
),
"echo"
,
.
sendAndReceive
(
new
Endpoint
(
"localhost"
,
808
1
),
"echo"
,
"Hello World"
.
getBytes
());
System
.
out
.
println
(
"Got back:"
+
new
String
(
response
.
get
(
2
,
TimeUnit
.
SECONDS
)));
//
System.out.println("Got back:" + new String(response.get(2, TimeUnit.SECONDS)));
context
.
stop
();
}
metrics
.
registerMetric
(
component
,
feature
,
"
AsyncTimer
"
,
sendAndReceiveTimer
);
metrics
.
registerMetric
(
component
,
feature
,
"
PingPong
"
,
sendAndReceiveTimer
);
}
public
static
class
TestNettyMessagingService
extends
NettyMessagingService
{
...
...
apps/foo/src/main/java/org/onlab/onos/foo/SimpleNettyServer.java
View file @
366ce8b
package
org
.
onlab
.
onos
.
foo
;
import
org.onlab.netty.EchoHandler
;
import
org.onlab.netty.NettyMessagingService
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
...
...
@@ -19,10 +18,10 @@ import org.slf4j.LoggerFactory;
}
public
static
void
startStandalone
(
String
[]
args
)
throws
Exception
{
NettyMessagingService
server
=
new
NettyMessagingService
(
808
0
);
NettyMessagingService
server
=
new
NettyMessagingService
(
808
1
);
server
.
activate
();
server
.
registerHandler
(
"simple"
,
new
org
.
onlab
.
netty
.
LoggingHandler
());
server
.
registerHandler
(
"echo"
,
new
EchoHandler
());
server
.
registerHandler
(
"simple"
,
new
Netty
LoggingHandler
());
server
.
registerHandler
(
"echo"
,
new
Netty
EchoHandler
());
}
}
...
...
features/features.xml
View file @
366ce8b
...
...
@@ -153,6 +153,7 @@
description=
"ONOS sample playground application"
>
<feature>
onos-api
</feature>
<bundle>
mvn:org.onlab.onos/onos-app-foo/1.0.0-SNAPSHOT
</bundle>
<bundle>
mvn:org.onlab.onos/onlab-netty/1.0.0-SNAPSHOT
</bundle>
</feature>
<feature
name=
"onos-app-config"
version=
"1.0.0"
...
...
utils/misc/src/main/java/org/onlab/metrics/MetricsManager.java
View file @
366ce8b
package
org
.
onlab
.
metrics
;
import
java.io.File
;
import
java.util.Locale
;
import
java.util.Map
;
import
java.util.concurrent.ConcurrentHashMap
;
import
java.util.concurrent.ConcurrentMap
;
...
...
@@ -11,8 +9,8 @@ import org.apache.felix.scr.annotations.Activate;
import
org.apache.felix.scr.annotations.Component
;
import
org.apache.felix.scr.annotations.Deactivate
;
import
com.codahale.metrics.ConsoleReporter
;
import
com.codahale.metrics.Counter
;
import
com.codahale.metrics.CsvReporter
;
import
com.codahale.metrics.Gauge
;
import
com.codahale.metrics.Histogram
;
import
com.codahale.metrics.Meter
;
...
...
@@ -69,15 +67,14 @@ public final class MetricsManager implements MetricsService {
/**
* Default Reporter for this metrics manager.
*/
private
final
C
sv
Reporter
reporter
;
private
final
C
onsole
Reporter
reporter
;
public
MetricsManager
()
{
this
.
metricsRegistry
=
new
MetricRegistry
();
this
.
reporter
=
CsvReporter
.
forRegistry
(
metricsRegistry
)
.
formatFor
(
Locale
.
US
)
this
.
reporter
=
ConsoleReporter
.
forRegistry
(
metricsRegistry
)
.
convertRatesTo
(
TimeUnit
.
SECONDS
)
.
convertDurationsTo
(
TimeUnit
.
MICROSECONDS
)
.
build
(
new
File
(
"/var/onos/log/metrics/"
)
);
.
build
();
}
@Activate
...
...
Please
register
or
login
to post a comment