Background:
I have a list of classes (comm objects), which may or may not increase. They all implement the same method in an interface Comms:
public int send(Socket socket, byte[] message);
I get a list of these comm classes by specifying the package name in the method's packageName parameter (excluding the package name itself internally in the function and doing some filtering to get just the names package comm):
public static Class[] getClasses(String packageName); (modified it a bit from the link below)
http://www.dzone.com/snippets/get-all-classes-within-package
Then I have several plugins which are configurable to use one of the comm objects as base communication.
Comm objects:
serial
client
server
etc.
Plugins:
plugin1
plugin2
etc.
The manager class will receive a request for sending a control packet from a plugin, and the manager will just queue the requests and call the send function for each request on a
Question:
How do I access the method send(Socket socket, byte[] message); within manager or the plugin itself?
This involves creating a generic class object which may call send, which is cast from one of the comm classes, depending on the plugin configuration, from the string name of the comm object.
The configuration of which comm class is used for each plugin is stored within a database. Converting from string to a Class object works well. I just need to find a way to call the send function which resides in the interface Comm which is implemented by all the comm classes. This has to be generic. More comm classes may be added.