Results 1 to 3 of 3

Thread: FR (slice, amd, java): ability to specify callback class name

  1. #1
    stepancheg is offline Registered User
    Name: Stepan Koltsov
    Organization: Yandex
    Project: Test
    Join Date
    Jan 2008
    Posts
    3

    FR (slice, amd, java): ability to specify callback class name

    Hi,

    we have a lot of methods with same result signature, like:

    Code:
    string getBanana(long id);
    string updateBanana(long id, string param);
    string findBananas();
    (all methods actually return XML, but it does not matter now).

    When using AMD, three similar callback interfaces will be generated:

    Code:
    AMD_Banana_getBanana
    AMD_Banana_updateBanana
    AMD_Banana_findBananas
    all three interfaces will have the same body, in Java:

    Code:
    void ice_response(String __ret);
    void ice_exception(java.lang.Exception ex);
    We'd like to have an option to use same interface for all three callbacks. Interface methods could be specified like

    Code:
    ["amd:cb_class=com.mycompany.proj.IceXmlCb"]
    string getBanana(long id);
    
    ["amd:cb_class=com.mycompany.proj.IceXmlCb"]
    string updateBanana(long id, string param);
    
    ["amd:cb_class=com.mycompany.proj.IceXmlCb"]
    string findBananas();
    to generate single callback interface com.mycompany.proj.IceXmlCb.

    Motivation: such callback interface (because there is only one interface) could be used in framework. For example, we could have method

    Code:
    void executeQueryAsync(
      String sqlQuery, params, IceXmlCb cb) { ... }
    and then implement ICE methods as:

    Code:
    getBananas(cb) {
      executeQuery("SELECT * FROM banana", { }, cb); }
    getBanana(cb, id) {
      executeQuery("SELECT * FROM banana WHERE id = ?", { id }, cb); }
    updateBanana(cb, id, param) {
      executeQuery("UPDATE banana SET a = ? WHERE id = ?", { param, id }, cb); }
    In current ICE we have to explicitly convert callback interfaces to some common interface:

    Code:
    getBananas(cb) {
      executeQuery("SELECT ...", { }, new IceXmlCb() {
        void ice_response(r) { cb.ice_response(r); }
        void ice_exeption(e) { cb.ice_exception(e); }
      }
    }
    getBanana(...) { /* copy-paste */ }
    updateBanana(...} /* copy-paste */ }
    This solution will work fine if all methods throw same user exception.

    Alternative Feature Request

    Ice should have base AMD callback interface like

    Code:
    interface Ice.AMD_CallbackBase<R> {
      void ice_response(R r);
      void ice_exception(Exception e);
    }
    and generated AMD callback will be:

    Code:
    interface AMD_Bananas_getBanana extends AMD_CallbackBase<String> {
      void ice_response(R r);
      void ice_exception(Exception e);
    }
    This is easier to implement and understand, and it sufficient to solve our problem. In this case executeQueryAsync will have signature:

    Code:
    void executeQueryAsync(
      String sqlQuery, params, AMD_CallbackBase<String> cb) { ... }

  2. #2
    mes's Avatar
    mes
    mes is offline ZeroC Staff
    Name: Mark Spruiell
    Organization: ZeroC, Inc.
    Project: Ice Developer
    Join Date
    Feb 2003
    Location
    California
    Posts
    1,441
    Stephan,

    Welcome to the forum.

    Thanks for the suggestion, we'll consider it for a future release. We've had internal discussions about doing something similar for C#, but it would be easier in C# with the language's delegate feature.

    Take care,
    - Mark

  3. #3
    mefoster is offline Registered User
    Name: Mary Ellen Foster
    Organization: Heriot-Watt University, Edinburgh
    Project: ECHOES learning environment
    Join Date
    Jun 2006
    Posts
    121
    I would also love something like this in Java. Even the second suggestion -- implementing a common super-interface -- would greatly clean up some of my code. At one point, I have a large number of callback-response classes that are pretty much identical, and it would be much nicer if I only had to write that code once.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. AMD callback - using arguments after ice_response()
    By Andrew S in forum Help Center
    Replies: 4
    Last Post: 01-15-2009, 04:23 AM
  2. How to make abstract SLICE class
    By peterlspot in forum Help Center
    Replies: 2
    Last Post: 01-17-2008, 01:14 AM
  3. Replies: 1
    Last Post: 11-29-2007, 07:26 AM
  4. Slice class data members -> private in Java/C++?
    By sasho2 in forum Help Center
    Replies: 3
    Last Post: 04-09-2007, 03:28 PM
  5. May slice struct contain class?
    By minifat in forum Help Center
    Replies: 1
    Last Post: 08-09-2004, 09:16 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •