Avatar

Please consider registering
guest

sp_LogInOut Log In sp_Registration Register

Register | Lost password?
Advanced Search

— Forum Scope —




— Match —





— Forum Options —





Minimum search word length is 3 characters - maximum search word length is 84 characters

sp_Feed Topic RSS sp_TopicIcon
Override Modeller generated method
February 18, 2021
11:34, EET
Avatar
Nan
Member
Members
Forum Posts: 17
Member Since:
December 14, 2020
sp_UserOfflineSmall Offline

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

February 18, 2021
14:26, EET
Avatar
Bjarne Boström
Moderator
Moderators
Forum Posts: 1032
Member Since:
April 3, 2012
sp_UserOfflineSmall Offline

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.

February 22, 2021
10:39, EET
Avatar
Nan
Member
Members
Forum Posts: 17
Member Since:
December 14, 2020
sp_UserOfflineSmall Offline

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

February 22, 2021
13:49, EET
Avatar
Bjarne Boström
Moderator
Moderators
Forum Posts: 1032
Member Since:
April 3, 2012
sp_UserOfflineSmall Offline

SDK basically provides the OPC UA interface, what you do behind that is your own application’s implementation and thus something you must do yourself.

Forum Timezone: Europe/Helsinki

Most Users Ever Online: 1919

Currently Online:
16 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: 728

Moderators: 7

Admins: 1

Forum Stats:

Groups: 3

Forums: 15

Topics: 1529

Posts: 6471

Newest Members:

kourtneyquisenbe, ellis87832073466, zkxwilliemae, gabriellabachus, Deakin, KTP25Zof, Wojciech Kubala, efrennowell431, wilfredostuart, caitlynfajardo

Moderators: Jouni Aro: 1026, Pyry: 1, Petri: 0, Bjarne Boström: 1032, Jimmy Ni: 26, Matti Siponen: 349, Lusetti: 0

Administrators: admin: 1