ComponentDefinition

public abstract class ComponentDefinition

The ComponentDefinition class.

Author:Cosmin Arad <cosmin@sics.se>, Jim Dowling <jdowling@sics.se>, Lars Kroll <lkroll@kth.se>

Fields

MDC_KEY_CID

public static final String MDC_KEY_CID

Pre-configured MDC key for the unique component id.

See the logback manuel for how to use this with logback.

MDC_KEY_CSTATE

public static final String MDC_KEY_CSTATE

Pre-configured MDC key for the current component lifecycle state.

See the logback manuel for how to use this with logback.

control

protected Negative<ControlPort> control

logger

protected final Logger logger

Kompics provided slf4j logger with managed diagnostic context.

See the logback manuel for how to use this with logback.

loopback

protected Negative<LoopbackPort> loopback

onSelf

protected Positive<LoopbackPort> onSelf

proxy

public final ComponentProxy proxy

Constructors

ComponentDefinition

protected ComponentDefinition()

Instantiates a new component definition.

ComponentDefinition

protected ComponentDefinition(Class<? extends ComponentCore> coreClass)

Methods

answer

protected final <P extends PortType> void answer(Direct.Request<?> event)

answer

protected final <P extends PortType> void answer(Direct.Request<?> req, Direct.Response resp)

config

public final Config config()

connect

protected final <P extends PortType> Channel<P> connect(Positive<P> positive, Negative<P> negative)
Parameters:
  • <P>
  • negative
  • positive

connect

protected final <P extends PortType> Channel<P> connect(Negative<P> negative, Positive<P> positive)
Parameters:
  • <P>
  • negative
  • positive

connect

protected <P extends PortType> Channel<P> connect(Positive<P> positive, Negative<P> negative, ChannelSelector<?, ?> selector)
Parameters:
  • <P>
  • negative
  • positive

connect

protected <P extends PortType> Channel<P> connect(Negative<P> negative, Positive<P> positive, ChannelSelector<?, ?> selector)
Parameters:
  • <P>
  • negative
  • positive

connect

protected <P extends PortType> Channel<P> connect(Negative<P> negative, Positive<P> positive, ChannelSelector<?, ?> selector, ChannelFactory factory)

connect

protected <P extends PortType> Channel<P> connect(Positive<P> positive, Negative<P> negative, ChannelSelector<?, ?> selector, ChannelFactory factory)

connect

protected <P extends PortType> Channel<P> connect(Negative<P> negative, Positive<P> positive, ChannelFactory factory)

connect

protected <P extends PortType> Channel<P> connect(Positive<P> positive, Negative<P> negative, ChannelFactory factory)

create

protected final <T extends ComponentDefinition> Component create(Class<T> definition, Init<T> initEvent)

Creates the.

Parameters:
  • definition – the definition
  • initEvent – init event to be passed to constructor
Returns:

the component

create

protected final <T extends ComponentDefinition> Component create(Class<T> definition, Init.None initEvent)

Creates the.

Parameters:
  • definition – the definition
  • initEvent – none
Returns:

the component

create

protected final <T extends ComponentDefinition> Component create(Class<T> definition, Init<T> initEvent, ConfigUpdate update)

Creates the.

Parameters:
  • definition – the definition
  • initEvent – init event to be passed to constructor
Returns:

the component

create

protected final <T extends ComponentDefinition> Component create(Class<T> definition, Init.None initEvent, ConfigUpdate update)

Creates the.

Parameters:
  • definition – the definition
  • initEvent – none
Returns:

the component

destroy

protected final void destroy(Component component)

disconnect

protected final <P extends PortType> void disconnect(Negative<P> negative, Positive<P> positive)
Parameters:
  • <P>
  • negative
  • positive

disconnect

protected final <P extends PortType> void disconnect(Positive<P> positive, Negative<P> negative)
Parameters:
  • <P>
  • negative
  • positive

disconnect

protected final <P extends PortType> void disconnect(Channel<P> c)

getComponentCore

public final ComponentCore getComponentCore()

getControlPort

public final Negative<ControlPort> getControlPort()

handleFault

public ResolveAction handleFault(Fault fault)

Override for custom error handling.

Default action is ESCALATE.

ESCALATE -> Forward fault to parent. IGNORE -> Drop fault. Resume component as if nothing happened. RESOLVED -> Fault has been handled by user. Don’t do anything else.

Parameters:
  • fault

handleUpdate

public UpdateAction handleUpdate(ConfigUpdate update)

Override for custom update handling.

Default action is to propagate the original everywhere and apply to self.

Parameters:
  • update

id

public final UUID id()

loggingCtxGet

protected String loggingCtxGet(String key)

Get the value associated with key in the current logging diagnostic context.

Parameters:
  • key
Returns:

the value associated with key

loggingCtxPut

protected void loggingCtxPut(String key, String value)

Associate key with value in the logging diagnostic context.

See the logback manuel for how to use this with logback.

Parameters:
  • key
  • value

loggingCtxPutAlways

protected void loggingCtxPutAlways(String key, String value)

Associate key permanently with value in the logging diagnostic context.

Keys set in this way are not removed by loggingCtxReset() or loggingCtxRemove().

See the logback manuel for how to use this with logback.

Parameters:
  • key
  • value

loggingCtxRemove

protected void loggingCtxRemove(String key)

Disassociate any value with the key in the logging diagnostic context.

Parameters:
  • key

loggingCtxReset

protected void loggingCtxReset()

Reset the current logging diagnostic context.

Removes all items added to context by the user that weren’t set with loggingCtxPutAlways(String,String)

negative

protected final <P extends PortType> Negative<P> negative(Class<P> portType)

Negative.

Parameters:
  • portType – the port type
Returns:

the negative < p>

positive

protected final <P extends PortType> Positive<P> positive(Class<P> portType)

Positive.

Parameters:
  • portType – the port type
Returns:

the positive < p>

postUpdate

public void postUpdate()

Override to perform actions after a ConfigUpdate was applied and forwarded.

provides

protected final <P extends PortType> Negative<P> provides(Class<P> portType)

requires

protected final <P extends PortType> Positive<P> requires(Class<P> portType)

specifies that this component requires a port of type portType.

Parameters:
  • <P>
  • portType

separateConfigId

public boolean separateConfigId()

Override to allow components of this type to start their own independent se.sics.kompics.config.Config id lines.

This is helpful in simulation, when simulating multiple independent nodes. Make sure that no ConfigUpdates are passed to siblings or parents of such nodes! (Override handleUpdate(se.sics.kompics.config.ConfigUpdate))

Returns:Whether to create a new config id line for this component (default: true)

setMDC

protected void setMDC()

Should not be necessary to call usually, as ComponentCore will do it.

Protected mainly for use by Kompics Scala.

Can also be used to set component MDC when executing related off-kompics work (check for concurrency issues, though!).

subscribe

protected final <E extends KompicsEvent, P extends PortType> void subscribe(Handler<E> handler, Port<P> port)

Subscribe.

Parameters:
  • handler – the handler
  • port – the port
Throws:

subscribe

protected final void subscribe(MatchedHandler<?, ?, ?> handler, Port<?> port)

suicide

public final void suicide()

tearDown

public void tearDown()

Use for custom cleanup. Will be called after all child components have stopped, but before sending a Stopped message to the parent.

trigger

protected final <P extends PortType> void trigger(KompicsEvent event, Port<P> port)

Trigger.

Parameters:
  • event – the event
  • port – the port

unsubscribe

protected final void unsubscribe(MatchedHandler<?, ?, ?> handler, Port<?> port)

unsubscribe

protected final <E extends KompicsEvent, P extends PortType> void unsubscribe(Handler<E> handler, Port<P> port)

Unsubscribe.

Parameters:
  • handler – the handler
  • port – the port
Throws:

updateConfig

public final void updateConfig(ConfigUpdate update)