public final class ProtocolFactory extends Object
This class is responsible for creating instances of Protocol subclasses and registering custom protocol implementations. To add a custom protocol, please have a look at the documentation and example of the registerProtocol method.
This class is fully threadsafe.
| Constructor and Description |
|---|
ProtocolFactory() |
| Modifier and Type | Method and Description |
|---|---|
static Protocol |
getProtocol(String name,
String options)
Creates an instance of a Protocol subclass.
|
static void |
registerProtocol(String name,
Class impl)
Registers a custom protocol implementation to the SmartInspect Java library.
|
public static Protocol getProtocol(String name, String options) throws SmartInspectException
This method tries to create an instance of a Protocol subclass using the name parameter. If you, for example, specify "file" as name parameter, this method returns an instance of the FileProtocol class. If the creation of such an instance has been successful, the supplied options will be applied to the protocol.
For a list of available protocols, please refer to the Protocol class. Additionally, to add your own custom protocol, please have a look at the registerProtocol method.
Please note that if the name argument is null, then the return value of this method is null as well.
name - The protocol name to search foroptions - The options to apply to the new Protocol instance. Can be nullSmartInspectException - if the protocol is unknown or options have invalid syntaxpublic static void registerProtocol(String name, Class impl)
Example:
import com.gurock.smartinspect.*;
class StdoutProtocol extends Protocol
{
// Implement the abstract methods and handle your protocol
// specific options ..
}
public class Program
{
public static void main(String[] args)
throws InvalidConnectionsException
{
ProtocolFactory.registerProtocol("stdout", StdoutProtocol.class);
SiAuto.si.setConnections("stdout()");
SiAuto.si.setEnabled(true);
}
}
name - The name of the custom protocol to register.impl - The class of your custom protocol. It needs to be derived from the Protocol classCopyright © 2023. All rights reserved.