Skip to content

SetupSharkApp

Thomas Schwotzer edited this page Oct 9, 2023 · 8 revisions

SharkPeer

All component are initialized. Now, we need to bring them together with our ASAP peer that actually sends and receives messages.

SharkPeer extends ASAPPeer to make let it run in our component based infrastructure.

  • provide component factories
  • create a peer
  • add components to the peers
  • start the system.

It can look a bit tricky when it comes to dependent components (which are quite common).

Let's start with an easy example:

static final CharSequence ALICE = "Alice";
static final CharSequence ROOTFOLDER = "yourComponent";
static final CharSequence ALICE_ROOTFOLDER = ROOTFOLDER + "/" + ALICE;
...
// create a file system based peer
SharkPeer sharkPeer = new SharkPeerFS(ALICE, ALICE_ROOTFOLDER);

// create factory object
SharkComponentFactory yourFactory = new YourComponentFactory();

// tell peer about your component
// second parameter: component interface
sharkPeer.addComponent(yourFactory , YourComponent.class);

// peers reference to a component instance if required
YourComponent yourComponent = (YourComponent)sharkPeer.getComponent(YourComponent.class);

// start peer == start system
sharkPeer.start();

Just in case you wonder... Shark peers create components using their coponents´ factory (sharkPeer.addComponent(yourFactory , YourComponent.class);. Components instances are not injected into peers (there is no such thing as sharkPeer.addComponent(componentInstance)).

In other words: A component is added by means of its factory not with its instances.

(Reason (can be ignored): We did it in another way in a previous version. It can lead to frustrating and hardly discoverable bugs when components are created twice (which is a bug). In that case, a peer dealt with one instance but a user interface with another one. Unfortunately it happened more than once and took very long time to figure the problem out. This solution looks a bit difficult but it is stable.)

Setup Dependent Components

Setting up dependent components is a bit - but really just a bit - more complex.

Here comes an example.

It could look like this:

// peer is created same way
SharkPeer sharkPeer = new SharkPeerFS(ALICE, ALICE_ROOTFOLDER);

// independent factory
SharkComponentFactory providerFactory = new ProviderComponentFactory();

// can add this component directly to our peer
sharkPeer.addComponent(providerFactory, ProviderComponent.class);

// dependent factory requires an instance(!) of our provider class, though
// we need to get component instance from our peer; ensures using same instance.
ProviderComponent providerComponent = (ProviderComponent)sharkPeer.getComponent(ProviderComponent.class);

// setup dependent factory
SharkComponentFactory dependingFactory = new DependingComponentFactory(providerComponent);

// now we can add component with a factory object
sharkPeer.addComponent(dependingFactory, DependingComponent.class);

// system setup is done - start the system
sharkPeer.start();

Next

One final thing...

SharkComponents are informed about application launch. That makes perfect sense. A peer is in place. Now, your component knows that it could potentially receive messages and it can definitely send messages.

You need to implement a single method in your component to make it aware of system launch.

Introduction

Shark Components

  1. Describe your component
  2. Component initialization
  3. Setup Shark App
  4. Component launch

ASAP Hub Management

  1. What's a hub
  2. hub information management
  3. connection management
Clone this wiki locally