Class MxGatewaySession
- All Implemented Interfaces:
AutoCloseable
Wraps an MxaccessGateway.OpenSessionReply together with the MxGatewayClient
that opened it and exposes the MXAccess command surface (Register, AddItem,
Advise, bulk subscribe variants, Write, event streaming, and close). Each
command request carries a freshly generated client correlation id.
-
Method Summary
Modifier and TypeMethodDescriptionintInvokes MXAccessAddItemand returns the new item handle.intInvokes MXAccessAddItem2and returns the new item handle.addItem2Raw(int serverHandle, String itemDefinition, String itemContext) Invokes MXAccessAddItem2and returns the raw reply.addItemBulk(int serverHandle, List<String> tagAddresses) Invokes the bulkAddItemvariant.addItemRaw(int serverHandle, String itemDefinition) Invokes MXAccessAddItemand returns the raw reply.voidadvise(int serverHandle, int itemHandle) Invokes MXAccessAdviseso the item starts emitting data-change events.adviseItemBulk(int serverHandle, List<Integer> itemHandles) Invokes the bulkAdvisevariant.adviseRaw(int serverHandle, int itemHandle) Invokes MXAccessAdviseand returns the raw reply.voidclose()closeRaw()Sends aCloseSessionRPC and caches the reply so subsequent calls are idempotent.static MxGatewaySessionforSessionId(MxGatewayClient client, String sessionId) Builds a session handle for an existing gateway session id without issuing anOpenSessioncall.invokeCommand(MxaccessGateway.MxCommand command) Sends a pre-builtMxaccessGateway.MxCommandfor this session and returns the raw reply, attaching a freshly generated client correlation id.Returns the originalMxaccessGateway.OpenSessionReplythat this session was opened with.BulkRead— snapshot the current value of each requested tag.intInvokes MXAccessRegisterand returns the server handle.registerRaw(String clientName) Invokes MXAccessRegisterand returns the raw reply.voidremoveItem(int serverHandle, int itemHandle) Invokes MXAccessRemoveItem.removeItemBulk(int serverHandle, List<Integer> itemHandles) Invokes the bulkRemoveItemvariant.removeItemRaw(int serverHandle, int itemHandle) Invokes MXAccessRemoveItemand returns the raw reply.Returns the gateway-assigned session id.Subscribes to gateway events for this session starting from the beginning of the worker event log.streamEventsAfter(long afterWorkerSequence) Subscribes to gateway events for this session starting after the supplied worker sequence number.subscribeBulk(int serverHandle, List<String> tagAddresses) Invokes the gatewaySubscribeBulkconvenience that combines AddItem and Advise for the supplied tag addresses.voidunAdvise(int serverHandle, int itemHandle) Invokes MXAccessUnAdviseso the item stops emitting data-change events.unAdviseItemBulk(int serverHandle, List<Integer> itemHandles) Invokes the bulkUnAdvisevariant.unAdviseRaw(int serverHandle, int itemHandle) Invokes MXAccessUnAdviseand returns the raw reply.voidunregister(int serverHandle) Invokes MXAccessUnregister.unsubscribeBulk(int serverHandle, List<Integer> itemHandles) Invokes the gatewayUnsubscribeBulkconvenience that combines UnAdvise and RemoveItem for the supplied item handles.voidwrite(int serverHandle, int itemHandle, MxaccessGateway.MxValue value, int userId) Invokes MXAccessWrite.voidwrite2(int serverHandle, int itemHandle, MxaccessGateway.MxValue value, MxaccessGateway.MxValue timestampValue, int userId) Invokes MXAccessWrite2, which carries an explicit timestamp.write2Bulk(int serverHandle, List<MxaccessGateway.Write2BulkEntry> entries) BulkWrite2— sequential MXAccess Write2 (timestamped) per entry.voidwriteArrayElements(int serverHandle, int itemHandle, MxaccessGateway.MxDataType elementDataType, int totalLength, Map<Integer, MxaccessGateway.MxValue> elements, int userId) Writes a subset of an array's elements using MXAccessWrite, building a write-onlyMxaccessGateway.MxSparseArrayvalue that the gateway expands into a full, default-filled array before forwarding to the worker.writeBulk(int serverHandle, List<MxaccessGateway.WriteBulkEntry> entries) BulkWrite— sequential MXAccess Write per entry on the worker's STA.writeRaw(int serverHandle, int itemHandle, MxaccessGateway.MxValue value, int userId) Invokes MXAccessWriteand returns the raw reply.writeSecured2Bulk(int serverHandle, List<MxaccessGateway.WriteSecured2BulkEntry> entries) BulkWriteSecured2— sequential timestamped + verified write per entry.writeSecuredBulk(int serverHandle, List<MxaccessGateway.WriteSecuredBulkEntry> entries) BulkWriteSecured— credential-sensitive values must not be logged by callers; mirrors the single-item write-secured redaction contract.
-
Method Details
-
forSessionId
Builds a session handle for an existing gateway session id without issuing anOpenSessioncall. Useful for CLI tools that operate against a session opened in a separate invocation.- Parameters:
client- the gateway client used for further commandssessionId- the existing gateway session id- Returns:
- a session handle bound to the supplied id
-
sessionId
Returns the gateway-assigned session id.- Returns:
- the session id
-
openReply
Returns the originalMxaccessGateway.OpenSessionReplythat this session was opened with.- Returns:
- the open-session reply
-
closeRaw
Sends aCloseSessionRPC and caches the reply so subsequent calls are idempotent.- Returns:
- the raw close-session reply
- Throws:
MxGatewayException- on transport or protocol failure
-
close
public void close()- Specified by:
closein interfaceAutoCloseable
-
register
Invokes MXAccessRegisterand returns the server handle.- Parameters:
clientName- the MXAccess client name to register- Returns:
- the
ServerHandlereturned by MXAccess - Throws:
MxGatewayException- on transport or protocol failure
-
registerRaw
Invokes MXAccessRegisterand returns the raw reply.- Parameters:
clientName- the MXAccess client name to register- Returns:
- the raw command reply
- Throws:
MxGatewayException- on transport or protocol failure
-
unregister
public void unregister(int serverHandle) Invokes MXAccessUnregister.- Parameters:
serverHandle- theServerHandlereturned byregister(String)- Throws:
MxGatewayException- on transport or protocol failure
-
addItem
Invokes MXAccessAddItemand returns the new item handle.- Parameters:
serverHandle- theServerHandleowning the itemitemDefinition- the MXAccess item definition (tag reference)- Returns:
- the
ItemHandleassigned by MXAccess - Throws:
MxGatewayException- on transport or protocol failure
-
addItemRaw
Invokes MXAccessAddItemand returns the raw reply.- Parameters:
serverHandle- theServerHandleowning the itemitemDefinition- the MXAccess item definition- Returns:
- the raw command reply
- Throws:
MxGatewayException- on transport or protocol failure
-
addItem2
Invokes MXAccessAddItem2and returns the new item handle.- Parameters:
serverHandle- theServerHandleowning the itemitemDefinition- the MXAccess item definitionitemContext- the MXAccess item context (e.g. galaxy/object scope)- Returns:
- the
ItemHandleassigned by MXAccess - Throws:
MxGatewayException- on transport or protocol failure
-
addItem2Raw
public MxaccessGateway.MxCommandReply addItem2Raw(int serverHandle, String itemDefinition, String itemContext) Invokes MXAccessAddItem2and returns the raw reply.- Parameters:
serverHandle- theServerHandleowning the itemitemDefinition- the MXAccess item definitionitemContext- the MXAccess item context- Returns:
- the raw command reply
- Throws:
MxGatewayException- on transport or protocol failure
-
removeItem
public void removeItem(int serverHandle, int itemHandle) Invokes MXAccessRemoveItem.- Parameters:
serverHandle- theServerHandleowning the itemitemHandle- theItemHandleto remove- Throws:
MxGatewayException- on transport or protocol failure
-
removeItemRaw
Invokes MXAccessRemoveItemand returns the raw reply.- Parameters:
serverHandle- theServerHandleowning the itemitemHandle- theItemHandleto remove- Returns:
- the raw command reply
- Throws:
MxGatewayException- on transport or protocol failure
-
advise
public void advise(int serverHandle, int itemHandle) Invokes MXAccessAdviseso the item starts emitting data-change events.- Parameters:
serverHandle- theServerHandleowning the itemitemHandle- theItemHandleto advise- Throws:
MxGatewayException- on transport or protocol failure
-
adviseRaw
Invokes MXAccessAdviseand returns the raw reply.- Parameters:
serverHandle- theServerHandleowning the itemitemHandle- theItemHandleto advise- Returns:
- the raw command reply
- Throws:
MxGatewayException- on transport or protocol failure
-
unAdvise
public void unAdvise(int serverHandle, int itemHandle) Invokes MXAccessUnAdviseso the item stops emitting data-change events.- Parameters:
serverHandle- theServerHandleowning the itemitemHandle- theItemHandleto un-advise- Throws:
MxGatewayException- on transport or protocol failure
-
unAdviseRaw
Invokes MXAccessUnAdviseand returns the raw reply.- Parameters:
serverHandle- theServerHandleowning the itemitemHandle- theItemHandleto un-advise- Returns:
- the raw command reply
- Throws:
MxGatewayException- on transport or protocol failure
-
addItemBulk
public List<MxaccessGateway.SubscribeResult> addItemBulk(int serverHandle, List<String> tagAddresses) Invokes the bulkAddItemvariant.- Parameters:
serverHandle- theServerHandleowning the itemstagAddresses- the MXAccess tag addresses to add- Returns:
- a per-tag
MxaccessGateway.SubscribeResultlist - Throws:
MxGatewayException- on transport or protocol failureNullPointerException- iftagAddressesisnull
-
adviseItemBulk
public List<MxaccessGateway.SubscribeResult> adviseItemBulk(int serverHandle, List<Integer> itemHandles) Invokes the bulkAdvisevariant.- Parameters:
serverHandle- theServerHandleowning the itemsitemHandles- theItemHandlelist to advise- Returns:
- a per-item
MxaccessGateway.SubscribeResultlist - Throws:
MxGatewayException- on transport or protocol failureNullPointerException- ifitemHandlesisnull
-
removeItemBulk
public List<MxaccessGateway.SubscribeResult> removeItemBulk(int serverHandle, List<Integer> itemHandles) Invokes the bulkRemoveItemvariant.- Parameters:
serverHandle- theServerHandleowning the itemsitemHandles- theItemHandlelist to remove- Returns:
- a per-item
MxaccessGateway.SubscribeResultlist - Throws:
MxGatewayException- on transport or protocol failureNullPointerException- ifitemHandlesisnull
-
unAdviseItemBulk
public List<MxaccessGateway.SubscribeResult> unAdviseItemBulk(int serverHandle, List<Integer> itemHandles) Invokes the bulkUnAdvisevariant.- Parameters:
serverHandle- theServerHandleowning the itemsitemHandles- theItemHandlelist to un-advise- Returns:
- a per-item
MxaccessGateway.SubscribeResultlist - Throws:
MxGatewayException- on transport or protocol failureNullPointerException- ifitemHandlesisnull
-
subscribeBulk
public List<MxaccessGateway.SubscribeResult> subscribeBulk(int serverHandle, List<String> tagAddresses) Invokes the gatewaySubscribeBulkconvenience that combines AddItem and Advise for the supplied tag addresses.- Parameters:
serverHandle- theServerHandleowning the itemstagAddresses- the MXAccess tag addresses to subscribe- Returns:
- a per-tag
MxaccessGateway.SubscribeResultlist - Throws:
MxGatewayException- on transport or protocol failureNullPointerException- iftagAddressesisnull
-
unsubscribeBulk
public List<MxaccessGateway.SubscribeResult> unsubscribeBulk(int serverHandle, List<Integer> itemHandles) Invokes the gatewayUnsubscribeBulkconvenience that combines UnAdvise and RemoveItem for the supplied item handles.- Parameters:
serverHandle- theServerHandleowning the itemsitemHandles- theItemHandlelist to unsubscribe- Returns:
- a per-item
MxaccessGateway.SubscribeResultlist - Throws:
MxGatewayException- on transport or protocol failureNullPointerException- ifitemHandlesisnull
-
writeBulk
public List<MxaccessGateway.BulkWriteResult> writeBulk(int serverHandle, List<MxaccessGateway.WriteBulkEntry> entries) BulkWrite— sequential MXAccess Write per entry on the worker's STA.Per-entry failures appear as
MxaccessGateway.BulkWriteResultentries withwasSuccessful == false; this method does not throw for per-entry MXAccess failures (it still throwsMxGatewayExceptionon transport or protocol-level failures).- Parameters:
serverHandle- theServerHandleowning the itemsentries- the per-item (handle, value, user id) tuples- Returns:
- a per-entry
MxaccessGateway.BulkWriteResultlist - Throws:
MxGatewayException- on transport or protocol failureNullPointerException- ifentriesisnull
-
write2Bulk
public List<MxaccessGateway.BulkWriteResult> write2Bulk(int serverHandle, List<MxaccessGateway.Write2BulkEntry> entries) BulkWrite2— sequential MXAccess Write2 (timestamped) per entry.Per-entry semantics mirror
writeBulk(int, List).- Parameters:
serverHandle- theServerHandleowning the itemsentries- the per-item (handle, value, timestamp, user id) tuples- Returns:
- a per-entry
MxaccessGateway.BulkWriteResultlist - Throws:
MxGatewayException- on transport or protocol failureNullPointerException- ifentriesisnull
-
writeSecuredBulk
public List<MxaccessGateway.BulkWriteResult> writeSecuredBulk(int serverHandle, List<MxaccessGateway.WriteSecuredBulkEntry> entries) BulkWriteSecured— credential-sensitive values must not be logged by callers; mirrors the single-item write-secured redaction contract.Per-entry semantics mirror
writeBulk(int, List).- Parameters:
serverHandle- theServerHandleowning the itemsentries- the per-item (handle, value, current+verifier user id) tuples- Returns:
- a per-entry
MxaccessGateway.BulkWriteResultlist - Throws:
MxGatewayException- on transport or protocol failureNullPointerException- ifentriesisnull
-
writeSecured2Bulk
public List<MxaccessGateway.BulkWriteResult> writeSecured2Bulk(int serverHandle, List<MxaccessGateway.WriteSecured2BulkEntry> entries) BulkWriteSecured2— sequential timestamped + verified write per entry.Per-entry semantics mirror
writeBulk(int, List).- Parameters:
serverHandle- theServerHandleowning the itemsentries- the per-item (handle, value, timestamp, current+verifier user id) tuples- Returns:
- a per-entry
MxaccessGateway.BulkWriteResultlist - Throws:
MxGatewayException- on transport or protocol failureNullPointerException- ifentriesisnull
-
readBulk
public List<MxaccessGateway.BulkReadResult> readBulk(int serverHandle, List<String> tagAddresses, Duration timeout) BulkRead— snapshot the current value of each requested tag.MXAccess COM has no synchronous read; the worker returns the cached
OnDataChangevalue for any tag that is already advised (wasCached == true) without modifying the existing subscription, and falls back to a full AddItem + Advise + wait + UnAdvise + RemoveItem snapshot lifecycle otherwise. The suppliedtimeoutbounds the per-tag wait in the snapshot case; passDuration.ZERO(ornull) to use the worker default (1000 ms). Per-tag failures appear asMxaccessGateway.BulkReadResultentries withwasSuccessful == false; this method does not throw for per-tag MXAccess failures.- Parameters:
serverHandle- theServerHandleowning the itemstagAddresses- the tag addresses to readtimeout- per-tag snapshot timeout (zero or null = worker default)- Returns:
- a per-tag
MxaccessGateway.BulkReadResultlist - Throws:
MxGatewayException- on transport or protocol failureNullPointerException- iftagAddressesisnullIllegalArgumentException- iftimeoutis negative or exceedsInteger.MAX_VALUEmilliseconds
-
write
Invokes MXAccessWrite.- Parameters:
serverHandle- theServerHandleowning the itemitemHandle- theItemHandleto writevalue- the value to writeuserId- the MXAccess user id used for security checks- Throws:
MxGatewayException- on transport or protocol failure
-
writeRaw
public MxaccessGateway.MxCommandReply writeRaw(int serverHandle, int itemHandle, MxaccessGateway.MxValue value, int userId) Invokes MXAccessWriteand returns the raw reply.- Parameters:
serverHandle- theServerHandleowning the itemitemHandle- theItemHandleto writevalue- the value to writeuserId- the MXAccess user id used for security checks- Returns:
- the raw command reply
- Throws:
MxGatewayException- on transport or protocol failure
-
writeArrayElements
public void writeArrayElements(int serverHandle, int itemHandle, MxaccessGateway.MxDataType elementDataType, int totalLength, Map<Integer, MxaccessGateway.MxValue> elements, int userId) Writes a subset of an array's elements using MXAccessWrite, building a write-onlyMxaccessGateway.MxSparseArrayvalue that the gateway expands into a full, default-filled array before forwarding to the worker.Default-fill semantics: only the indices supplied in
elementsare written; every unmentioned index is reset to the element type's default (for example0,false, or an empty string), not preserved from the array's current contents. Use a fullMxaccessGateway.MxValuearray write when you need to keep existing element values.totalLengthis required and defines the length of the expanded array; supplied indices must be within[0, totalLength). Elements are iterated in ascending index order so the produced command is deterministic.Because the proto fields
MxSparseArray.total_lengthandMxSparseElement.indexareuint32, passing a negative Javaintwould silently sign-extend to a large unsigned value on the wire. This method therefore rejects negativetotalLengthand negative element indices withIllegalArgumentExceptionrather than allowing a hard-to-diagnose gateway error.- Parameters:
serverHandle- theServerHandleowning the itemitemHandle- theItemHandleto writeelementDataType- theMxaccessGateway.MxDataTypeof the array's elementstotalLength- the total length of the expanded array; must be > 0elements- the indices to write mapped to their scalar values; each index must be in[0, totalLength); unmentioned indices are reset to the element type defaultuserId- the MXAccess user id used for security checks- Throws:
IllegalArgumentException- iftotalLengthis not positive, or if any element index is negative or ≥totalLengthMxGatewayException- on transport or protocol failure
-
write2
public void write2(int serverHandle, int itemHandle, MxaccessGateway.MxValue value, MxaccessGateway.MxValue timestampValue, int userId) Invokes MXAccessWrite2, which carries an explicit timestamp.- Parameters:
serverHandle- theServerHandleowning the itemitemHandle- theItemHandleto writevalue- the value to writetimestampValue- the timestamp value to associate with the writeuserId- the MXAccess user id used for security checks- Throws:
MxGatewayException- on transport or protocol failure
-
streamEvents
Subscribes to gateway events for this session starting from the beginning of the worker event log.- Returns:
- an iterator-style stream of events
-
streamEventsAfter
Subscribes to gateway events for this session starting after the supplied worker sequence number.- Parameters:
afterWorkerSequence- the resume cursor; events with worker sequence greater than this value are delivered- Returns:
- an iterator-style stream of events
-
invokeCommand
Sends a pre-builtMxaccessGateway.MxCommandfor this session and returns the raw reply, attaching a freshly generated client correlation id.- Parameters:
command- the command to send- Returns:
- the raw command reply
- Throws:
MxGatewayException- on transport or protocol failure
-