How to write custom unit calculator

We are using Coherence 3.4.2 for Java. I am trying to write our own unit calculator. As I played with the example coming with Coherence, I modify the explore-config.xml as following:
<cache-config>
<caching-scheme-mapping>
<!--
Caches with any name will be created as default replicated.
-->
<cache-mapping>
<cache-name>*</cache-name>
<scheme-name>default-distributed</scheme-name>
</cache-mapping>
<cache-mapping>
<cache-name>VirtualCache</cache-name>
<scheme-name>default-distributed</scheme-name>
</cache-mapping>
</caching-scheme-mapping>
<caching-schemes>
<!--
Default Replicated caching scheme.
-->
<replicated-scheme>
<scheme-name>default-replicated</scheme-name>
<service-name>ReplicatedCache</service-name>
<backing-map-scheme>
<class-scheme>
<scheme-ref>default-backing-map</scheme-ref>
</class-scheme>
</backing-map-scheme>
</replicated-scheme>
<!--
Default Distributed caching scheme.
-->
<distributed-scheme>
<scheme-name>default-distributed</scheme-name>
<service-name>DistributedCache</service-name>
<backing-map-scheme>
<local-scheme>
<high-units>272</high-units>
<low-units>50</low-units>
*<unit-calculator><class-scheme><class-name>com.tangosol.examples.explore.TestMemoryCalculator</class-name></class-scheme></unit-calculator>*
</local-scheme>
</backing-map-scheme>
</distributed-scheme>
<!--
Default backing map scheme definition used by all
The caches that do not require any eviction policies
-->
<class-scheme>
<scheme-name>default-backing-map</scheme-name>
<class-name>com.tangosol.util.SafeHashMap</class-name>
</class-scheme>
</caching-schemes>
</cache-config>
I write the very simple java code:
package com.tangosol.examples.explore;
import com.tangosol.net.cache.OldCache;
class TestMemoryCalculator implements OldCache.UnitCalculator {
public TestMemoryCalculator() {
public int calculateUnits(Object oKey, Object oValue) {
int size = 0;
System.out.println("size = " + size);
return size;
When I try to run the example program, I got the following error:
yzhang@bsdhcp174172:~/work/coherence> java -cp ./lib/coherence.jar:./lib/tangosol.jar:./examples/java -Dtangosol.coherence.cacheconfig=./examples/config/explore-config-dist.xml com.tangosol.examples.explore.SimpleCacheExplorer
2009-05-27 14:57:55.019/0.294 Oracle Coherence 3.4.2/411 <Info> (thread=main, member=n/a): Loaded operational configuration from resource "jar:file:/home/yzhang/work/coherence/lib/coherence.jar!/tangosol-coherence.xml"
2009-05-27 14:57:55.025/0.300 Oracle Coherence 3.4.2/411 <Info> (thread=main, member=n/a): Loaded operational overrides from resource "jar:file:/home/yzhang/work/coherence/lib/coherence.jar!/tangosol-coherence-override-dev.xml"
2009-05-27 14:57:55.025/0.300 Oracle Coherence 3.4.2/411 <D5> (thread=main, member=n/a): Optional configuration override "/tangosol-coherence-override.xml" is not specified
2009-05-27 14:57:55.031/0.306 Oracle Coherence 3.4.2/411 <D5> (thread=main, member=n/a): Optional configuration override "/custom-mbeans.xml" is not specified
Oracle Coherence Version 3.4.2/411
Grid Edition: Development mode
Copyright (c) 2000-2009 Oracle. All rights reserved.
2009-05-27 14:57:55.260/0.535 Oracle Coherence GE 3.4.2/411 <Info> (thread=main, member=n/a): Loaded cache configuration from file "/home/yzhang/work/coherence/examples/config/explore-config-dist.xml"
2009-05-27 14:57:55.555/0.830 Oracle Coherence GE 3.4.2/411 <Warning> (thread=main, member=n/a): UnicastUdpSocket failed to set receive buffer size to 1428 packets (2096304 bytes); actual size is 178 packets (262144 bytes). Consult your OS documentation regarding increasing the maximum socket buffer size. Proceeding with the actual value may cause sub-optimal performance.
2009-05-27 14:57:55.695/0.970 Oracle Coherence GE 3.4.2/411 <D5> (thread=Cluster, member=n/a): Service Cluster joined the cluster with senior service member n/a
2009-05-27 14:57:58.897/4.172 Oracle Coherence GE 3.4.2/411 <Info> (thread=Cluster, member=n/a): Created a new cluster "cluster:0x2FFB" with Member(Id=1, Timestamp=2009-05-27 14:57:55.564, Address=172.19.174.172:8088, MachineId=4524, Location=site:americas.nokia.com,machine:bsdhcp174172,process:16242, Role=TangosolSimpleCacheExplorer, Edition=Grid Edition, Mode=Development, CpuCount=2, SocketCount=1) UID=0xAC13AEAC00000121836F916C11AC1F98
2009-05-27 14:57:59.062/4.337 Oracle Coherence GE 3.4.2/411 <D5> (thread=DistributedCache, member=1): Service DistributedCache joined the cluster with senior service member 1
2009-05-27 14:57:59.118/4.393 Oracle Coherence GE 3.4.2/411 <Error> (thread=DistributedCache, member=1): BackingMapManager com.tangosol.net.DefaultConfigurableCacheFactory$Manager: failed to instantiate a cache: Yong
2009-05-27 14:57:59.118/4.393 Oracle Coherence GE 3.4.2/411 <Error> (thread=DistributedCache, member=1):
java.lang.IllegalArgumentException: Unknown unit calculator:
<class-scheme>
<class-name>com.tangosol.examples.explore.TestMemoryCalculator</class-name>
</class-scheme>
at com.tangosol.net.DefaultConfigurableCacheFactory.instantiateLocalCache(DefaultConfigurableCacheFactory.java:1641)
at com.tangosol.net.DefaultConfigurableCacheFactory.configureBackingMap(DefaultConfigurableCacheFactory.java:1063)
at com.tangosol.net.DefaultConfigurableCacheFactory.configureBackingMap(DefaultConfigurableCacheFactory.java:1059)
at com.tangosol.net.DefaultConfigurableCacheFactory$Manager.instantiateBackingMap(DefaultConfigurableCacheFactory.java:3124)
at com.tangosol.coherence.component.util.daemon.queueProcessor.service.grid.DistributedCache$Storage.instantiateResourceMap(DistributedCache.CDB:19)
at com.tangosol.coherence.component.util.daemon.queueProcessor.service.grid.DistributedCache$Storage.setCacheName(DistributedCache.CDB:27)
at com.tangosol.coherence.component.util.daemon.queueProcessor.service.grid.DistributedCache$ConfigListener.entryInserted(DistributedCache.CDB:15)
at com.tangosol.util.MapEvent.dispatch(MapEvent.java:191)
at com.tangosol.util.MapEvent.dispatch(MapEvent.java:164)
at com.tangosol.util.MapListenerSupport.fireEvent(MapListenerSupport.java:556)
at com.tangosol.util.ObservableHashMap.dispatchEvent(ObservableHashMap.java:229)
at com.tangosol.util.ObservableHashMap$Entry.onAdd(ObservableHashMap.java:270)
at com.tangosol.util.SafeHashMap.put(SafeHashMap.java:244)
at com.tangosol.coherence.component.util.collections.WrapperMap.put(WrapperMap.CDB:1)
at com.tangosol.coherence.component.util.daemon.queueProcessor.service.Grid$ServiceConfigMap.put(Grid.CDB:13)
at com.tangosol.coherence.component.util.daemon.queueProcessor.service.grid.DistributedCache$StorageIdRequest.onReceived(DistributedCache.CDB:40)
at com.tangosol.coherence.component.util.daemon.queueProcessor.service.Grid.onMessage(Grid.CDB:9)
at com.tangosol.coherence.component.util.daemon.queueProcessor.service.Grid.onNotify(Grid.CDB:130)
at com.tangosol.coherence.component.util.daemon.queueProcessor.service.grid.DistributedCache.onNotify(DistributedCache.CDB:3)
at com.tangosol.coherence.component.util.Daemon.run(Daemon.CDB:37)
at java.lang.Thread.run(Thread.java:619)
Of course, if I replaced my TestMemoryCalculator with the SimpleMemoryCalculator coming with coherence, it works. My question is that why my custom unit calculator in this example DOES NOT work? And what part I did it wrong?
Thanks

Hi java8964,
It probably didn't compile because you didn't implement getName() method:
package com.tangosol.examples.explore;
import com.tangosol.net.cache.OldCache;
class TestMemoryCalculator implements OldCache.UnitCalculator
    public TestMemoryCalculator()
    public int calculateUnits(Object oKey, Object oValue)
        int size = 0;
        System.out.println("size = " + size);
        return size;
    public String getName()
        return "TestMemoryCalculator";
    } Regards,
Dimitri

Similar Messages

  • How to write customer exit in my BI query to get (current fiscal quarter) and (current fiscal quarter - 1 ) without user input

    Hi all,
    I need your help how to write customer exit in my BI query to get (current fiscal quarter) and (current fiscal quarter - 1 ) without user input.
    in my query info object is 0CALQUARTER and variable is ZFIS_QTR.
    in 0CALQUARTER fiscal quarter stored in 201301,201302,201303,201304 and 201401 format, for current fiscal quarter 201401 and (current fiscal quarter - 1 ) would be 201304.
    please replay ASAP to deliver the report to client.
    thanks in advance.
    -- Rakesh Nagpure

    I am Getting the same error for both the codes that i have written...
    Do i Need to write sth else in the code...
    Code:
    WHEN 'ZVLIVELEASES'.
      IF I_STEP = 2.
            L_DATE = SY-DATUM.
            SELECT * FROM "DSO_ACTIVE_TABLE"
                INTO TABLE ITAB_LL where "EXPIRY_DATE" > L_DATE.
            LOOP AT ITAB_LL INTO WA_LL.
            CLEAR l_s_range.
            l_s_range-sign = 'I'.
            l_s_range-opt = 'EQ'.
            l_s_range-low = WA_LL-"EXPIRY_DATE".
           APPEND L_S_RANGE TO E_T_RANGE.
            ENDLOOP.
       ENDIF.
    Error: Error for variable in customer enhancement ZLIVELEASES

  • How to write utp(unit test plan)

    how to write utp(unit test plan)

    Hi,
      Steps to be followed for UTP.
    UTP : Unit Test Plan. Testing the program by the developer who developed the program is termed as Unit Test Plan.
    Two aspects are to be considered in UTP.
    1. Black Box Testing
    2. White Box Testing.
    1. Black Box Testing : The program is executed to view the output.
    2. White Box Testing : The code is checked for performance tuning and syntax errors.
    Follow below mentioned steps.
    <b>Black Box Testing</b>
    1. Cover all the test scenarios in the test plan. Test plan is usually prepared at the time of Techincal Spec preparation, by the testing team. Make sure that all the scenarios mentioned in the test plan are coverd in UTP.
    2. Execute your code for positive and negative test. Postive tests - to execute the code and check if the program works as per expected. Negative Test - Execute code to know if the code is working in scenarios in which it is not supposed to work. The code should work only in the mentioned scenarios and not in all cases.
    <b>White Box Testing.</b>
    1. Check the Select statments in your code. Check if any redundant fields are being fetched by the select statements.
    2. Check If there is any redundant code in the program.
    3. Check whether the code adheres to the Coding standards of your client or your company.
    4. Check if all the variables are cleared appropriately.
    5. Optimize the code by following the performance tuning procedures.
    <b>Using tools provided by SAP</b>
    1. Check your program using <b>EXTENDED PROGRAM CHECK</b>.
    2. Use SQL Trace to estimate the performace and the response of the each statement in the code. If changes are required, mention the same in UTP.
    3. Use Runtime Analyser and Code Inspector to test your code.
    4. Paste the screen shots of all the tests in the UTP document. This gives a clear picture of the tests conducted on the program.
    All the above steps are to be mentioned in UTP.
    Regards,
    Vara

  • SRM Smartform - How to write custom logic to get data

    Hi Experts,
    I am new to SRM 7.0 now. I want to know where the code logic can be written to print the custom smart form?
    I have already create custom smarts form ZBBP_PO, and implement the BADI  BBP_OUTPUT_CHANGE_SF to pass the custom form name.
    But i don't know where to write the code for fetching the source data. In ECC, we can write the code in a separate report program. How it does in SRM now? It is said some class and method will print the form. How to find it? and how to add custom logic.?
    Or the logic of fetching source data should be embeded in the smart form? I don't like to write much more codes directly in smart form.
    Thanks!

    Yeah, I know it. but I don't want to write code logic into the Smartforms. in ECC, i always write the code in a separated program which will pass the data to smartform and call function module to print it.
    i just want to know whether i can write the code in somewhere else in SRM, not in smartform.

  • How to write customer exist for Keyfigure( query )

    Hi gurus,
    I have to write customer exist for a key figure.
    Please tell me how to write it.
    Thanks,
    James

    Pankesh,
    SE24 is for  defining classes .. are you sure this is for customer exits ?..
    Use a formula variable filled by a customer exit... go to TCode CMOD and follow the normal procedure for defining Exits.. look up the forums for detailed steps on how to write an exit..
    Arun
    Hope it helps...

  • How to write custom messages to Data Manager package log from within SSIS?

    Just wonder in BPC 7.0/7.5 MS how do you write custom messages to Data Manager package log from within SSIS?  I mean I want to log output of specific custom tasks (non-BPC) in SSIS control flow to the resultant BPC package log created when running SSIS package in Data Manager.  Can this be done in a Script Task or some other way?  Not much documentation out there on this.
    Thanks,
    Brian

    Hi Brian
    In order to achieve what you want, it can get tricky in your package, ultimately It would depend on the task, for example if you had an execute SQL task, you could use a RAISEERROR command in your SQL statement and BPC would return the error message that you specified.
    If you had other tasks, then it would be a bit more tricky, you would have to have custom messages based on event handlers.
    Please see below links for examples :
    [Custom messages for logging|http://msdn.microsoft.com/en-us/library/ms345174.aspx]
    [Custom Logging Using Event Handlers |http://consultingblogs.emc.com/jamiethomson/archive/2005/06/11/SSIS_3A00_-Custom-Logging-Using-Event-Handlers.aspx]
    Hope this helps
    Kind Regards
    Daniel

  • How to write custom prerender or init  method?

    some ide provide override prerender() and init() methods,i can use this methods,
    i use differnt ide but i didnt find prerender and init methods ,so i try to write these but i couldnt.
    i did ;
    1) write phaselistener
    2) and extends my beans with phaselistener
    public class phases implements PhaseListener {
    public phases() {
    public void init() {
    System.out.println("/******************phase****init*****************************");
    public void afterPhase(PhaseEvent phaseEvent) {
    public void beforePhase(PhaseEvent event) {
    if (event.getPhaseId()==PhaseId.RESTORE_VIEW) {/// this mean is page init
    init();
    protected boolean isPostBack() {
    if (getFacesContext().getRenderResponse())
    return false;
    else
    return true;
    and my bean is ;
    public class login extends phases {
    @Override
    public void init() {
    System.out.println("/**********************init*****************************");
    but nothing (didnt enter the init method);;
    pls How can i do this?
    Edited by: ermanbas on Jun 13, 2009 9:16 PM
    Edited by: ermanbas on Jun 13, 2009 9:17 PM

    That's why it sucks to be tied up to an ide feature. Do not extend your beans from a phaselistener. You need sth like;
    http://cagataycivici.wordpress.com/2006/06/06/managed_beans_aware_of_the/
    Edited by: CagatayCivici on Jun 16, 2009 4:06 PM

  • How to write customer exit for the variable

    Hi Experts,
    I have a requirement to create the variable, the scenaria is like this..
    I need to create the variable which gives the period/year values,if yours enters the values 05.2007 then the variable should return the first monthe the year i.e.01.2007.
    I hope it can be done by writing the customer exit..but iam unware how to achieve this.
    Please explain me step by step and cope for customer exit to done this.
    Points will be awarded
    Suraj.

    hi Suraj,
    there should variable sap exit for first month,
    for customer exit, check this how to doc for steps
    https://websmp210.sap-ag.de/~sapdownload/011000358700002762582003E/HowToDeriveVariableValue.pdf
    your code may look like
      INCLUDE ZXRSRU01                                                   *
      DATA: L_S_RANGE TYPE RSR_S_RANGESID.
      DATA: LOC_VAR_RANGE LIKE RRRANGEEXIT.
      CASE I_VNAM.
      WHEN 'your 1st month variable'.
        IF I_STEP = 2.                                  "after the popup
          LOOP AT I_T_VAR_RANGE INTO LOC_VAR_RANGE
                  WHERE VNAM = 'your user input variable'.
            CLEAR L_S_RANGE.
            L_S_RANGE-LOW      = LOC_VAR_RANGE-LOW(4)."low value, e.g.200001
            L_S_RANGE-LOW+4(2) = '01'.
            L_S_RANGE-SIGN     = 'I'.
            L_S_RANGE-OPT      = 'EQ'.
            APPEND L_S_RANGE TO E_T_RANGE.
            EXIT.
          ENDLOOP.
        ENDIF.
      ENDCASE.
    hope this helps.

  • How to write customer exit code to get current user as default in variable

    Hi guys,
           I design a query which has a variable called var_employee , I also set some default values for this variable in query designer. But I would like to set the current user account who logon on (who execute the query) in the dropdownlist as default user when the variable selection screen appear. of course after that he can choose other avaiable value.
          I look up some related threads, all says that this need some customer exit code, and they mention to use CMOD to create the customer exit , but I don't know the detail process, as I am pretty new on this.
         The attribute of the var_employee  variable is :  employee(defined info object by myself) characterstic value, customer exit.
         Can somebody show me the process to create the customer exit, and the apap code in detail if possbile. then I can try.
          Thanks a lot in advance.
    Best Regards,
    Ben

    Hi,
    Please have a look at:
    https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/f1a7e790-0201-0010-0a8d-f08a4662562d
    Krzys

  • Help needed in writting Customer exit - ABAP Code

    Hi Friends,
    I have a scenario in one of the query and need to write a customer exit for the same. Here is the scenario:
    I am using one input variable XXX to get input from user which feeds value to one of the charateristic  lets say "CHAR1" in query. I have one more characteristic "CHAR2" which has to get the value from the same variable XXX. This is not allowed in BI7.0 as the variable is Hierarchy Node type. It gives error that "Variable XXX is used for two different characteristics."
    So i need to create one more vaiable YYY which will get the value from XXX and then YYY will feed value to CHAR2.  I would appreciate if some one could tell me step by step how to write customer exit and give me the piece of ABAP code i need to write in my case.
    Your help will be appreciated in terms of points.
    Thanks,
    manmit

    Hi Arun,
    1. What should CHAR2 take - Hierarchy node variable or something else ?
    --> CHAR2 is a simple charateristic
    2. In your scenario - why have CHAR1 and CHAR2 ? why not have the user enter values against CHAR2 ??
    --> We dont want user to enter two input as the input values for both Chars are same.
    3. Did you try using a replacement path variable with the CHAR2 variable taking values from Variable on CHAR1 ?
    --> In BI7.0 replacement path variable only take values from Query results. So not able to do the same.
    Thanks

  • How to write UT

    Hi abapers,
    Can u plz explain me How to write UTP(Unit test plan).
    Thanks in advance
    venkat

    Hi,
    You posted on the wrong forum, this is Berkeley DB XML (DB XML).
    The Oracle XML DB (XML DB) is here:
    XML DB
    I am not an expert in XML DB, but your code might look like this:
    DECLARE
         xmldoc dbms_xmldom.DOMDocument;
    BEGIN
         xmldoc := dbms_xmldom.newDOMDocument(V_name);
         dbms_xmldom.writeToFILE(xmldoc, '/path_to_directory/file_name.xml'); -- path is in *nix format
    END;although, for a more professional suggestion you should post on the XML DB forum.
    Regards,
    Andrei

  • How to write the expression when create the calculated column?

    Dear,
           I want to create some calculated column in my attribute view, but I don't know how to write the code in the expression, is there any introduction about this part, how to use those function and how about the grammar in this expression code ?  or is there any example about this calculated column?
       Thanks for your sincerely answer.

    Hi Zongjie,
    you can find some information about the creation of calculated columns in the HANA Modeling Guide (http://help.sap.com/hana/SAP_HANA_Modeling_Guide_for_SAP_HANA_Studio_en.pdf).
    Within chapter 6.2.1 (Create Analytic Views) you can see under point 7 some basics and also a simple example. The same is also valid for Calculation Views.
    Chapter 8.9 (Using Functions in Expressions) describes the different available functions.
    You also can use the integrated search in the HANA Studio by clicking the "?" button in the button left corner. Then you get some links in the side panel with related information.
    In general you can write your expression manually or you can just drag and drop the functions, elements, operators into the editor window. For example if you drag and drop the "if" function into the editor window you get "if(intarg,arg2,arg3)" inserted. The arguments can be replaced manually or also by drag and drop.
    It is also worse to use the "Validate Syntax" button on top of the editor window. It gives you directly a feedback if your expression syntax is correct. If not you get some helpful information about the problem (ok, sometimes it is a little bit confusing because of the cryptic error message format ).
    Best Regards,
    Florian

  • How to Write a CUstomer Exit for a variable in BEx

    Hi,
    How to write a customer exit variable in bex Query designer
    Do i need developers key for this (If so what type of key do i need so that i can ask basis tean to generate)
    Info Object: ZEXP_DTE (Expiry Date)
    Variable on ZEXP_DTE :
    ZEDTE
    Type: Customer Exit
    Can any one please tell me how to write a code in CMOD from this (Step-by Step)
    Expiry Date > Current Cal Day
    As arun said
    'l_s_range-low = SY-DATUM.
    l_s_range-opt = 'I'.
    l_s_range-sign = 'GT'.
    APPEND l_s_range TO e_t_range.'
    I want to insert the above code for the above customer exit but as i am new to BW as  ABAP please explain me what are the steps involved in CMOD
    Thanks

    Hi,
    To write customer exit for a variable, you require Access key.
    Contact your BASIS to get that.
    Access Key,BASIS?
    To write Customer exit,
    User Exits
    User Exit for Variable
    /thread/809285 [original link is broken]
    Hope these helps u...
    Regards,
    KK.

  • How to write a procedure to run the call the custom package from backend

    Hi All
    Oracle 10g
    Oracle Apps R12
    I am working with oracle order management here we have a customize Package called (Pick Release).Due to some problem we have running this concurrent program by manually giving Route_id as parameter. The route_id is taken from the route Table. By using this query
    select distinct route_id from route@DB_LINK_APPS_TO_ROADSHOW
    where trunc(route_date) = trunc (sysdate+2).
    so daily we have nearly 42 routes and we are running this concurrent program manually nearly times.
    so now how to write a procedure for this
    Step 1 Getting the route from route table.( By cursor we can get the route_id Accordingly)
    Step 2 How to trigger the custom package from back end and execute accordingly to that output of the cursor(route_id)
    If the cursor get 40 routes is it then the concurrent program runs 40 times according to that route_id.
    can some could provide the steps to do this
    Thanks & Regards
    Srikkanth.M

    This is about 4 or 5 lines of PL/SQL and the name of the custom package is not provided.
    If you request someone in this forum to do your work for free -because obviously you didn't even try to write it, which must be considered abusing this forum- you must at least provide sufficient info so someone can do it.
    And no, I won't do it for you.
    Sybrand Bakker
    Senior Oracle DBA

  • How to write new userexit to assign customer material info record to a cust

    Hi Guru's,
    how to write new userexit to assign a customer material info record to a customer hierarchy
    please provide step by step process that would be helpfull to me..
    thansk in advance and will give full points..
    Srinivas...

    Hi,
    Can u please give me the clarification whether u want to create new exit or u want to enhance the existing one?

Maybe you are looking for