11:34, EET
December 14, 2020
Hi Team,
We have custom created and added Object Type Called LargeObjectType in model. It has writeText method which I want to override on the server side such that when writeText method is called from UAExpert client, the call goes to override method. I have read below solution in forum:
https://forum.prosysopc.com/forum/opc-ua-java-sdk/overriding-filedirectorytype-methods-and-massspectrometerdevicetype-methods/
“We do have an alternative way to make method impls for these cases. For the server side, the codegen creates for each UA Method in the model an interface TypeNameMethodNameMethod, for this case e.g. FileDirectoryTypeCreateFileMethod. Its parameters include the “FileDirectoryTypeNode node”. Create an implementation of this interface and call the static method FileDirectoryTypeNodeBase.setCreateFileMethodImplementation(instance_of_your_impl_here). SDK will then call that for you whenever the method is called (note that then the equivalent method in the XXXTypeNode is not called). Additionally, since statics can be seen via subtypes in java, I might call this via FileDirectoryTypeNode instead of the XXXNodeBase, but either works.”
I have implemented below solution but the call doesn’t reach the overriding method. Kindly help if I am doing something wrong here:
public class testClass implements LargeObjectTypeWriteTextMethod {
@Override
public LargeObjectType.WriteTextMethodOutputs writeText(ServiceContext serviceContext, LargeObjectTypeNode node, UnsignedLong position, String content, UnsignedInteger version, LargeObjectWriteModeEnum writeMode, Boolean markIncomplete) throws StatusException {
LargeObjectTypeWriteTextMethod abc = new LargeObjectTypeWriteTextMethod() {
@Override
public LargeObjectType.WriteTextMethodOutputs writeText(ServiceContext serviceContext, LargeObjectTypeNode node, UnsignedLong position, String content, UnsignedInteger version, LargeObjectWriteModeEnum writeMode, Boolean markIncomplete) throws StatusException {
return null;
}
};
LargeObjectTypeNodeBase.setWriteTextMethodImplementation(abc);
return null;
}
}
Thanks
14:26, EET
April 3, 2012
Hi,
Um, that code doesn’t make any sense, but maybe it got broken since our forum is not really that good related to indentation. Thus my answer may also look a bit odd.
Anyway, as an example, in the DI companion specification LockingServicesType has a Method called InitLock. For that it would go as follows, note that I put this at the start of main, but basically it must be set somewhere before the server is started.
public static void main(String[] args) {
LockingServicesTypeNode.setInitLockMethodImplementation(new LockingServicesTypeInitLockMethod() {
@Override
public Integer initLock(ServiceContext serviceContext, LockingServicesTypeNode node, String context)
throws StatusException {
// Some implementation here based on input
return Integer.valueOf(1000);
}
});
}
OR, if you can run with Java 8 that is a lot nicer with a lambda:
LockingServicesTypeNode.setInitLockMethodImplementation((serviceContext, node, context) -> Integer.valueOf(1000));
Though, in a real-use-case, the implementation wont be as simple as that most likely.
P.S.
Note that this was an alternative to writing it directly to the generated LockingServicesTypeNode. I would say nowadays I would prefer myself not to edit generated files (thus doing it like the above), but the XXXTypeNode + XXXTypeNodeBase logic of generation was made originally so that the method implementations could be written to the XXXTypeNode, which then could be generated once, and all other parts exist in the XXXTypeNodeBase (which XXXTypeNode extends), so that any codegen changes/improvements wouldn’t hopefully need regenerating the XXXTypeNode and manually editing it again.
10:39, EET
December 14, 2020
Thanks a lot.That worked!
Below is the code for write method call:
Before start of server:
LargeObjectTypeNode.setWriteTextMethodImplementation(new myLargeObjectType());
my class:
public class myLargeObjectType implements LargeObjectTypeWriteTextMethod {
@Override
public LargeObjectType.WriteTextMethodOutputs writeText(ServiceContext serviceContext, LargeObjectTypeNode node, UnsignedLong position, String content, UnsignedInteger version, LargeObjectWriteModeEnum writeMode, Boolean markIncomplete) throws StatusException {
//validate xml and return success/failure}}
I want to Manage session:
If 1 client is writing data, the file should be stored in session so that if other client connects, the file can be accessed from the session.
Could you please help with above query.
Thanks
Most Users Ever Online: 1919
Currently Online:
23 Guest(s)
Currently Browsing this Page:
1 Guest(s)
Top Posters:
Heikki Tahvanainen: 402
hbrackel: 144
rocket science: 88
pramanj: 86
Francesco Zambon: 83
Ibrahim: 78
Sabari: 62
kapsl: 57
gjevremovic: 49
Xavier: 43
Member Stats:
Guest Posters: 0
Members: 735
Moderators: 7
Admins: 1
Forum Stats:
Groups: 3
Forums: 15
Topics: 1523
Posts: 6449
Newest Members:
rust, christamcdowall, redaahern07571, nigelbdhmp, travistimmons, AnnelCib, dalenegettinger, howardkennerley, Thomassnism, biancacraft16Moderators: Jouni Aro: 1026, Pyry: 1, Petri: 0, Bjarne Boström: 1026, Jimmy Ni: 26, Matti Siponen: 346, Lusetti: 0
Administrators: admin: 1