Link between JavaDelegate class and a Java Server

Hi everyone,

I’m trying to manage a light behaviour in correlation with a BPMN process diagram. I’ve implemented a Java Server which connects itself with a Telnet client (way to send commands to my lights), and I’d like to read signals from my process to know, for example, the name of the light I should turn on. :bulb::bulb::bulb:

I’ve written a JavaDelegate in order to listen to events names :


public class ProcessListener implements JavaDelegate {
	
	public String signalName;

	@Override
	public void execute(DelegateExecution execution) throws Exception {
		try {
			signalName = execution.getEventName().toString();
			}
		 catch (Exception e) {
			e.printStackTrace();
		}
	}
} 

My issue is to call this class on my Java Server class. I don’t know what to put as an argument calling “this.listen.execute” even if I know it shoulb be a DelegateExecution type… I guess I need some implementation examples. Here’s my Server :


package opec.opec_server;

import java.io.InputStream;
import java.io.PrintStream;
import opec.opec_server.ProcessListener;

import org.apache.commons.net.telnet.TelnetClient;

public class Server implements Runnable {

int telnetPort = 23;
String lutronIP = “192.168.0.101”;
String userName = “USER”;
String password = “Lutron”;
String mem = “”;
TelnetClient tc;
InputStream in;
PrintStream out;
ProcessListener listen;

public Server() {
//init ProcessListener
this.listen = new ProcessListener();

  //connection to the Telnet client
  this.tc = new TelnetClient();
  try {
  	this.tc.connect(this.lutronIP);
  	System.out.println("Connexion Successfull.");
  } catch (Exception e) {
  	e.printStackTrace();
  }

}
// Some …
//Functions…
//Later…
public void run() {

  //this.listen.execute(); How do I call that ?? 
  
  if(this.listen.signalName != this.mem) {
  	
  	switch(this.listen.signalName) {
  	case "TurnOnIMB":
  		this.out.println("#OUTPUT,11,1,30");
  		this.out.flush();
  	case "TurnOnZI":
  		this.out.println("#OUTPUT,10,1,30");
  		this.out.flush();
  	case "TurnOffAll":
  		this.out.println("#OUTPUT,10,0,0");
  		this.out.flush();
  		this.out.println("#OUTPUT,11,0,0");
  		this.out.flush();
  	default:
  		;
  	}
  mem = this.listen.signalName;
  }

}

public static void main(String args) {
int n = 0;
Server mySrv = new Server();
mySrv.authentification();
while(n != 1000) {
mySrv.run();
n++;
}
mySrv.disconnect();
}
}

Thank you in advance for your time and consideration,

Emma. :slightly_smiling_face:

Hrm… I don’t see where is the process engine in your setup. Could you describe it in more details?

The diagram is called light-process.bpmn and is stored in src/main/resources on my eclipe workspace.
I’ve defined the listener of the process on the ProcessListener class.

Did I answer your question ?