Skip to content
This repository has been archived by the owner on Oct 1, 2020. It is now read-only.

Commit

Permalink
let ixi module connect to ict instead of the other way around
Browse files Browse the repository at this point in the history
  • Loading branch information
trifel committed Dec 29, 2018
1 parent cf90e9d commit c5a13ea
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 36 deletions.
28 changes: 12 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,10 @@ gradle fatJar

### Adjust the Ict config file

In your **ict.cfg** file, add `Report.ixi` to `ixis` and make sure that `ixi_enabled` is set to `true`:
In your **ict.cfg** file, make sure that `ixi_enabled` is set to `true`:

```
ixis=Report.ixi
ixi_enabled = true
ixi_enabled=true
```

### Create and adjust the Report.ixi config file
Expand All @@ -37,6 +36,11 @@ Create or open the **report.ixi.cfg** file and complete the settings.
// an IP address chosen by the kernel. Mostly you don`t need to change the host IP.
host=0.0.0.0
// The name of your Ict Client which is configured in the ict.cfg file. This name
// is only used for the RMI connection between Report.ixi and the Ict Client.
// The default value is set to "ict".
ictName=ict
// The additional port of the Report.ixi application of your instance.
// This additional port is not the Ict port.
reportPort=1338
Expand Down Expand Up @@ -72,7 +76,11 @@ uuid=61c134d5-915e-457b-999e-e91fd2aa8fe3

## Run Report.ixi

### Step 1: Stop your Ict Client
### Step 1: Start your Ict Client

```shell
java -jar ict-{VERSION}.jar
```

### Step 2: Start Report.ixi

Expand All @@ -83,15 +91,3 @@ If your **report.ixi.cfg** file is not in the same directory, you can set the pa
```shell
java -jar report.ixi-{VERSION}.jar ../report.ixi.cfg
```

### Step 3: Start your Ict Client

```shell
java -jar ict-{VERSION}.jar
```

The Report.ixi application should print this line if the Ict is connected successfully:

```
Ict '{name}' connected
```
35 changes: 16 additions & 19 deletions src/main/java/com/ictreport/ixi/ReportIxi.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,18 @@ public static void main(String[] args) {
final Properties properties = new Properties(propertiesFilePath);
properties.store(propertiesFilePath);

new ReportIxi(properties);
try {
new ReportIxi(properties);
} catch (RuntimeException e) {
LOGGER.info(String.format("Can't connect to Ict '%s'. Make sure that the Ict Client is running. Check 'ictName' in report.ixi.cfg and 'ixi_enabled=true' in ict.cfg.",
properties.getIctName()));
System.exit(0);
}
}

public ReportIxi(Properties properties) {

super(properties.getModuleName());
super(properties.getModuleName(), properties.getIctName());

this.properties = properties;

Expand All @@ -47,11 +53,13 @@ public ReportIxi(Properties properties) {
neighbors.add(new Neighbor(neighborASocketAddress.getAddress(), properties.getNeighborAPort()));
neighbors.add(new Neighbor(neighborBSocketAddress.getAddress(), properties.getNeighborBPort()));
neighbors.add(new Neighbor(neighborCSocketAddress.getAddress(), properties.getNeighborCPort()));

LOGGER.info(String.format("%s started, waiting for Ict to connect ...",
properties.getModuleName()));
LOGGER.info(String.format("Just add '%s' to 'ixis' in your ict.cfg file and restart your Ict.\n",
properties.getModuleName()));

GossipFilter filter = new GossipFilter();
filter.watchTag("REPORT9IXI99999999999999999");
setGossipFilter(filter);

api = new Api(this);
api.init();

Runtime.getRuntime().addShutdownHook(new Thread() {
public void run() {
Expand All @@ -60,6 +68,7 @@ public void run() {
if (api != null) api.shutDown();
}
});

}

public Properties getProperties() {
Expand All @@ -70,18 +79,6 @@ public List<Neighbor> getNeighbors() {
return this.neighbors;
}

@Override
public void onIctConnect(String name) {
LOGGER.info("Ict '" + name + "' connected");

GossipFilter filter = new GossipFilter();
filter.watchTag("REPORT9IXI99999999999999999");
setGossipFilter(filter);

api = new Api(this);
api.init();
}

@Override
public void onTransactionReceived(GossipReceiveEvent event) {
LOGGER.info(String.format("message received '%s'",
Expand Down
22 changes: 21 additions & 1 deletion src/main/java/com/ictreport/ixi/utils/Properties.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public class Properties extends java.util.Properties {

// Property names
private final static String MODULE_NAME = "moduleName";
private final static String ICT_NAME = "ictName";
private final static String NAME = "name";
private final static String UUID = "uuid";
private final static String HOST = "host";
Expand All @@ -30,6 +31,7 @@ public class Properties extends java.util.Properties {

// Property defaults
private final static String DEFAULT_MODULE_NAME = "Report.ixi";
private final static String DEFAULT_ICT_NAME = "ict";
private final static String DEFAULT_NAME = "";
private final static String DEFAULT_UUID = java.util.UUID.randomUUID().toString();
private final static String DEFAULT_HOST = "0.0.0.0";
Expand Down Expand Up @@ -72,6 +74,22 @@ public void setModuleName(final String moduleName) {
put(MODULE_NAME, moduleName);
}

/**
* @return the ict name
*/
public String getIctName() {

return getProperty(ICT_NAME, DEFAULT_ICT_NAME).trim();
}

/**
* @param ictName the ict name to set
*/
public void setIctName(final String ictName) {

put(ICT_NAME, ictName);
}

/**
* @return the reportPort
*/
Expand Down Expand Up @@ -256,7 +274,9 @@ public void store(String propertiesFilePath) {
}

private void setRequiredProps() {

if (get(ICT_NAME) == null) {
put(ICT_NAME, DEFAULT_ICT_NAME);
}
if (get(UUID) == null) {
put(UUID, DEFAULT_UUID);
}
Expand Down

0 comments on commit c5a13ea

Please sign in to comment.