Class JVMBridgeListener
Base class managing events from JVM. Implements IJVMBridgeBase. Extend this base class to manage events from the JVM
public class JVMBridgeListener : JVMBridgeBase<JVMBridgeListener>, IDynamicMetaObjectProvider, IJVMBridgeCore, IEquatable<IJVMBridgeBase>, IJVMBridgeBaseStatic, IJVMBridgeBase, IJVMBridgeDefinition, IDisposable
- Inheritance
-
JVMBridgeListener
- Implements
- Inherited Members
- Extension Methods
Examples
The following is the implementation of the Java ActionListener interface managed from the object JCActionListener (see Java help for implementation)
It use CLRActionEventData as typeparam of the generic CLRListenerEventArgs<TDataClass>
public sealed class CLRActionListener : JVMBridgeListener
{
public override string ClassName { get { return "org.mases.jcobridge.specialized.JCActionListener"; } } // the full name of class, in the JVM counterpart, of the Java class implementing the event
public CLRActionListener(EventHandler<CLRListenerEventArgs<CLRActionEventData>> handler) // the handler with the expected type
{
AddEventHandler("actionPerformed", handler); // allocate the event handler associated to the action the Java interface to be managed in C#
}
}
Constructors
JVMBridgeListener()
Initialize a new instance of JVMBridgeListener
public JVMBridgeListener()
JVMBridgeListener(IJVMBridgeBaseInitializer)
Initializer used internally
public JVMBridgeListener(IJVMBridgeBaseInitializer initializer)
Parameters
initializerIJVMBridgeBaseInitializerAn instance of IJVMBridgeBaseInitializer
Remarks
Shall be available in any class inherited from JVMBridgeBase
JVMBridgeListener(params object[])
Initialize a new instance of JVMBridgeListener
public JVMBridgeListener(params object[] args)
Parameters
argsobject[]The arguments of constructor
Properties
AutoInit
Set to false to externally initialize this JVMBridgeListener instance using InitializeListener(IJVMBridgeBase)
public virtual bool AutoInit { get; }
Property Value
BridgeClassName
Java class name to be instantiated
public override string BridgeClassName { get; }
Property Value
IsBridgeCloseable
true if the BridgeClassName implements Closeable
public override bool IsBridgeCloseable { get; }
Property Value
IsBridgeListener
true if the BridgeClassName follows the listener pattern of JCOBridge: the BridgeClassName extends a JCListener or implements IJCListener
public override sealed bool IsBridgeListener { get; }
Property Value
IsBridgeStatic
true if the BridgeClassName is a static class, i.e. does not have any public constructor
public override bool IsBridgeStatic { get; }
Property Value
ShallManageEventHandler
An handler invoked from the JVMBridgeListener on each received event to notify the user which can decide to abort the execution for the specific event returning false
public Func<string, bool> ShallManageEventHandler { get; set; }
Property Value
Remarks
By default every event continues the execution and reads the data from JVM; this implies an extra cost which can be limited using the handler associated to this property. Returning false the control is immediately returned to the JVM, however the user has received the notification. It can be useful in scenarios where the user is interested in few events and the other are simply discarded to optimize the execution speed.
ShallManageEventWithDataHandler
An handler invoked from the JVMBridgeListener on each received event, if ShallManageEvent(string) or ShallManageEventHandler returned true, to notify the user which can decide to abort the execution for the specific event returning false This is an overload of ShallManageEventHandler which adds the information associated to the event
public Func<string, object, bool> ShallManageEventWithDataHandler { get; set; }
Property Value
Remarks
Returning false the control is immediately returned to the JVM, however the user has received the notification with the raw prepared data. It can be useful in scenarios where the user is interested in data associated to few events before the registered handler is invoked and the other are simply discarded to optimize the execution speed.
Methods
AddEventHandler(string, EventHandler)
Adds an handler to manage events from JVM
protected int AddEventHandler(string action, EventHandler handler)
Parameters
actionstringThe action to be managed
handlerEventHandlerThe CLR handler associated to the JVM event
Returns
- int
The index asssociated to the event added
AddEventHandler<TDataClass>(string, EventHandler<CLRListenerEventArgs<TDataClass>>)
Adds an handler to manage events from JVM
protected int AddEventHandler<TDataClass>(string action, EventHandler<CLRListenerEventArgs<TDataClass>> handler) where TDataClass : CLREventData
Parameters
actionstringThe action to be managed
handlerEventHandler<CLRListenerEventArgs<TDataClass>>The CLR handler associated to the JVM event
Returns
- int
The index asssociated to the event added
Type Parameters
TDataClassThe class which manages event data in CLR format
Dispose(bool)
Implements the pattern described in https://learn.microsoft.com/en-en/dotnet/standard/garbage-collection/implementing-dispose
protected override void Dispose(bool disposing)
Parameters
disposingboolThe disposing parameter is a bool that indicates whether the method call comes from a Dispose() method (its value is true) or from a finalizer (its value is false)
ShallManageEvent(string)
Invoked from the JVMBridgeListener on each received event to notify the user which can decide to abort the execution for the specific event returning false
protected virtual bool ShallManageEvent(string eventName)
Parameters
eventNamestringThe name of the event is triggering
Returns
Remarks
By default every event continues the execution and reads the data from JVM; this implies an extra cost which can be limited using ShallManageEvent(string) or the ShallManageEventHandler handler. Returning false the control is immediately returned to the JVM, anyway the user has received the notification. It can be useful in scenarios where the user is interested in few events and the other are simply discarded to optimize the execution speed. By default, this function invokes ShallManageEventHandler if it is set or return true
ShallManageEvent(string, object)
Invoked from the JVMBridgeListener on each received event, if ShallManageEvent(string) returned true, to notify the user which can decide to abort the execution, for the specific event, returning false.
This is an overload of ShallManageEvent(string) which adds the information associated to the event in data
protected virtual bool ShallManageEvent(string eventName, object data)
Parameters
Returns
Remarks
Returning false the control is immediately returned to the JVM, however the user has received the notification with the raw prepared data. It can be useful in scenarios where the user is interested in data associated to few events before the registered handler is invoked and the other are simply discarded to optimize the execution speed. This function invokes ShallManageEventHandler or return true by default