Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Simonstrator
PeerfactSim.KOM
Commits
85cf5aa8
Commit
85cf5aa8
authored
Sep 28, 2015
by
Björn Richerzhagen
Browse files
MetricOutputSiS: Simulation Metrics can now be used as SiS Metrics (via
their names)
parent
2d4bb12a
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/de/tud/kom/p2psim/impl/analyzer/metric/output/MetricOutputSiS.java
0 → 100644
View file @
85cf5aa8
/*
* Copyright (c) 2005-2010 KOM – Multimedia Communications Lab
*
* This file is part of PeerfactSim.KOM.
*
* PeerfactSim.KOM is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* PeerfactSim.KOM is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with PeerfactSim.KOM. If not, see <http://www.gnu.org/licenses/>.
*
*/
package
de.tud.kom.p2psim.impl.analyzer.metric.output
;
import
java.util.LinkedList
;
import
java.util.List
;
import
de.tudarmstadt.maki.simonstrator.api.Host
;
import
de.tudarmstadt.maki.simonstrator.api.Oracle
;
import
de.tudarmstadt.maki.simonstrator.api.common.metric.Metric
;
import
de.tudarmstadt.maki.simonstrator.api.common.metric.Metric.MetricValue
;
import
de.tudarmstadt.maki.simonstrator.api.component.ComponentNotAvailableException
;
import
de.tudarmstadt.maki.simonstrator.api.component.sis.SiSComponent
;
import
de.tudarmstadt.maki.simonstrator.api.component.sis.SiSDataCallback
;
import
de.tudarmstadt.maki.simonstrator.api.component.sis.SiSInfoProperties
;
import
de.tudarmstadt.maki.simonstrator.api.component.sis.SiSInfoProperties.SiSScope
;
import
de.tudarmstadt.maki.simonstrator.api.component.sis.SiSInformationProvider.SiSProviderHandle
;
import
de.tudarmstadt.maki.simonstrator.api.component.sis.exception.InformationNotAvailableException
;
import
de.tudarmstadt.maki.simonstrator.api.component.sis.type.SiSType
;
import
de.tudarmstadt.maki.simonstrator.api.component.sis.type.SiSTypes
;
import
de.tudarmstadt.maki.simonstrator.api.component.sis.type.aggregation.AbstractAggregation
;
/**
* Metric output acting as a bridge to the SiS
*
* @author Bjoern Richerzhagen
* @version 1.0, Sep 28, 2015
*/
public
class
MetricOutputSiS
extends
AbstractOutput
{
List
<
MetricSiSHost
>
hosts
=
new
LinkedList
<
MetricOutputSiS
.
MetricSiSHost
>();
@Override
public
void
onStop
()
{
// ignore for now
}
@Override
public
void
onInitialize
(
List
<
Metric
>
metrics
)
{
for
(
Host
host
:
Oracle
.
getAllHosts
())
{
try
{
SiSComponent
sis
=
host
.
getComponent
(
SiSComponent
.
class
);
hosts
.
add
(
new
MetricSiSHost
(
host
,
sis
));
}
catch
(
ComponentNotAvailableException
e
)
{
continue
;
}
}
// Register a metric at the SiS
for
(
Metric
metric
:
metrics
)
{
// Only allow per-host metrics
if
(
metric
.
isOverallMetric
())
{
continue
;
}
for
(
MetricSiSHost
host
:
hosts
)
{
// FIXME metric type cannot be resolved programmatically
SiSType
<
Double
>
sisType
=
SiSTypes
.
getType
(
metric
.
getName
(),
Double
.
class
);
if
(
sisType
==
null
)
{
// register type
SiSTypes
.
registerType
(
metric
.
getName
(),
Double
.
class
,
new
AbstractAggregation
.
AggregationDouble
());
sisType
=
SiSTypes
.
getType
(
metric
.
getName
(),
Double
.
class
);
assert
sisType
!=
null
;
}
host
.
sis
.
provide
().
localNodeState
(
sisType
,
new
MetricSiSDataCallback
(
metric
.
getPerHostMetric
(
host
.
host
)));
}
}
}
private
class
MetricSiSDataCallback
implements
SiSDataCallback
<
Double
>
{
private
final
MetricValue
<
Double
>
mv
;
private
final
SiSInfoProperties
info
=
new
SiSInfoProperties
()
.
setScope
(
SiSScope
.
NODE_LOCAL
);
public
MetricSiSDataCallback
(
MetricValue
<?>
mv
)
{
this
.
mv
=
(
MetricValue
<
Double
>)
mv
;
}
@Override
public
Double
getValue
(
SiSProviderHandle
providerHandle
)
throws
InformationNotAvailableException
{
Double
value
=
mv
.
getValue
();
if
(
mv
.
isValid
())
{
return
value
;
}
return
Double
.
NaN
;
}
@Override
public
SiSInfoProperties
getInfoProperties
()
{
return
info
;
}
}
/**
* Tuple: Host <-> SiS
*
* @author Bjoern Richerzhagen
* @version 1.0, Sep 28, 2015
*/
private
class
MetricSiSHost
{
public
final
Host
host
;
public
final
SiSComponent
sis
;
public
MetricSiSHost
(
Host
host
,
SiSComponent
sis
)
{
this
.
host
=
host
;
this
.
sis
=
sis
;
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment