Archived

This forum has been archived. Please start a new discussion on GitHub.

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

Hi,

we have a lot of methods with same result signature, like:
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:
AMD_Banana_getBanana
AMD_Banana_updateBanana
AMD_Banana_findBananas

all three interfaces will have the same body, in Java:
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
["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
void executeQueryAsync(
  String sqlQuery, params, IceXmlCb cb) { ... }

and then implement ICE methods as:
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:
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
interface Ice.AMD_CallbackBase<R> {
  void ice_response(R r);
  void ice_exception(Exception e);
}

and generated AMD callback will be:
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:
void executeQueryAsync(
  String sqlQuery, params, AMD_CallbackBase<String> cb) { ... }

Comments

  • mes
    mes California
    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
  • 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.