1

I have a cache object property that I'd like to set to the current class and method in context's name, in order to do some tracking on what methods/classes are generating the largest frequency of these objects.

I can easily grab the current class' name using the code below, but am struggling to find a similar method for gathering the current method's name from the documentation.

set obj.ClassName  = ..%ClassName(1)  //Grab class name
set obj.MethodName =                  //Need to grab the method's name here

I know this can be easily accomplished when the method in question is setup as an object generator, but I'd rather not go down this route.. There has to be a simple way to reference the method's name, right?

///I'd rather not do this to my methods if I don't have to.
Method MyMethod() [ CodeMode = objectgenerator ]
mccrackend
  • 137
  • 8
  • Please add a tag to your question indicating what programming language you are using. – Robert Harvey Aug 10 '11 at 16:32
  • Robert - the programming language is Cache Object Script, and there is no tag in the system representing this. I unfortunately don't have enough rep to create one yet either. – mccrackend Aug 10 '11 at 16:44
  • There isn't a supported way to do this. My reaction to this is... If you're not in a a generator method, why would you need it? Maybe I can tell you another technique to accomplish what you want. – codeymccodeface Aug 11 '11 at 13:40
  • I'm running a bunch of web services from Cache, and I have an Ensemble production that I'm using to query external systems in my environment. I'm trying to bastardize the request objects I'm sending from my web services to contain a source method/class of where the ensemble message originated from. I realize that I could/should stand up these web services as business services in the production to get the desired outcome.. but I'm not to that point yet. We've got quite a few active services running from cache currently, and moving them just isn't in the cards right now. – mccrackend Aug 11 '11 at 17:04
  • I think you'll just have to hard code it. – codeymccodeface Aug 12 '11 at 00:33

3 Answers3

2

There is a macro to do this: $$$CurrentMethod, defined within %occIO.inc, which you will find in %SYS so you don't need an include to use it. $$$CurrentClass is also defined there.

aPintOfAle
  • 36
  • 2
1

There is no "official" way to do that in a method.

You can use the $stack($stack,"PLACE") expression to determine currently executed code position. It should be enough for debugging purposes. You may extract a method name from it if you really need. I wouldn't advise to use this in a production code though =)

SSH
  • 2,533
  • 16
  • 21
  • I was afraid there wasn't a straightforward way.. Accepted answer for the workaround with $stack as a possibility. Method generators is probably the best way to do this. – mccrackend Aug 11 '11 at 17:10
1

For things like this I like to use the %Projection classes. You can look up the documentation on how to do it, but the basic idea is that when you compile one class it can be set up to generate another.

If you want to extend what Intersystem's gives you with things like knowing what method you're in (Intersystem's itself just cheats and changes the class compiler without creating a general method everyone can use) you can do some kind of hack like having a #CurrentMethod class parameter and setting up the projection class to replace that with the actual method name on save.

This is a pain to set up, but once you are doing it you can any additional meta-class kinds of features as needed. I do this for similar purposes as you mentioned, and for generating strongly typed result set objects with some convenience methods.

You can also do the same thing in code called from a Cache Studio add-in. Depending on how you write your add-in you could run your code from a menu item, for example.

psr
  • 2,870
  • 18
  • 22