Class ProtocolFactory
- java.lang.Object
-
- com.gurock.smartinspect.protocols.ProtocolFactory
-
public final class ProtocolFactory extends Object
Creates Protocol instances and registers custom protocols.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 Summary
Constructors Constructor Description ProtocolFactory()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static ProtocolgetProtocol(String name, String options)Creates an instance of a Protocol subclass.static voidregisterProtocol(String name, Class impl)Registers a custom protocol implementation to the SmartInspect Java library.
-
-
-
Method Detail
-
getProtocol
public static Protocol getProtocol(String name, String options) throws SmartInspectException
Creates an instance of a Protocol subclass.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.
- Parameters:
name- The protocol name to search foroptions- The options to apply to the new Protocol instance. Can be null- Returns:
- A new instance of a Protocol subclass
- Throws:
SmartInspectException- if the protocol is unknown or options have invalid syntax
-
registerProtocol
public static void registerProtocol(String name, Class impl)
Registers a custom protocol implementation to the SmartInspect Java library.
This method enables you to register your own custom protocols. This can be used to extend the built-in capabilities of the SmartInspect Java library. To add your own protocol, derive your custom protocol class from Protocol, choose a name and pass this name and the type to this method. After registering your protocol, you are able to use it in the connections string just like any other (standard) protocol.
If one of the supplied arguments is null or the supplied type is not derived from the Protocol class then no custom protocol is added.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); } }- Parameters:
name- The name of the custom protocol to register.impl- The class of your custom protocol. It needs to be derived from the Protocol class
-
-