Skip to content
Prev Previous commit
Next Next commit
Removed explicit default erlang converter from RabbitControlErlangCon…
…verter and in the creation of ControlActions that only need the default converter.

Added getter method in ErlangTemplate to handle use of appropriate converter to leverage existing declared converter.
Removed unused getter in ErlangTemplate for converter.
  • Loading branch information
Helena Edelson committed Feb 23, 2011
commit 215b4e7dfa8f47da083d353f1482d3e3c16d7708
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,11 @@ public OtpErlangObject doInConnection(Connection connection) throws Exception {
}

public OtpErlangObject executeRpc(ControlAction action, Object... args) {
return executeErlangRpc(action.getModule(), action.getFunction(), (OtpErlangList) action.getConverter().toErlang(args));
return executeErlangRpc(action.getModule(), action.getFunction(), (OtpErlangList) getErlangConverter(action).toErlang(args));
}

public Object executeAndConvertRpc(ControlAction action, Object... args) {
return action.getConverter().fromErlang(executeRpc(action, args));
return getErlangConverter(action).fromErlang(executeRpc(action, args));
}

public Object executeAndConvertRpc(String module, String function, Object... args) {
Expand Down Expand Up @@ -96,9 +96,8 @@ public void handleResponseError(String module, String function, OtpErlangObject
}
}


public ErlangConverter getErlangConverter() {
return erlangConverter;
public ErlangConverter getErlangConverter(ControlAction action) {
return action.getConverter() != null ? action.getConverter() : erlangConverter;
}

public void setErlangConverter(ErlangConverter erlangConverter) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ public class RabbitControlAction implements ControlAction {
public RabbitControlAction() {
}

protected RabbitControlAction(String module, String function, ErlangConverter converter) {
this(null, module, function, converter);
protected RabbitControlAction(Class key, String module, String function) {
this(key, module, function, null);
}

protected RabbitControlAction(Class key, String module, String function, ErlangConverter converter) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,6 @@ public class RabbitControlErlangConverter extends SimpleErlangConverter implemen

private Map<String, ControlAction> controlActionMap;

private static ErlangConverter DEFAULT_CONVERTER = new SimpleErlangConverter();

private ControlAction[] controlActions;

/**
Expand Down Expand Up @@ -120,52 +118,52 @@ public static ControlAction create(boolean isLatestVersion) {

public static class AddUser extends RabbitControlAction {
public static ControlAction create(boolean isLatestVersion) {
return isLatestVersion ? new RabbitControlAction(AddUser.class, "rabbit_auth_backend_internal", "add_user", DEFAULT_CONVERTER)
: new RabbitControlAction(AddUser.class, "rabbit_access_control", "add_user", DEFAULT_CONVERTER);
return isLatestVersion ? new RabbitControlAction(AddUser.class, "rabbit_auth_backend_internal", "add_user")
: new RabbitControlAction(AddUser.class, "rabbit_access_control", "add_user");
}
}

public static class DeleteUser extends RabbitControlAction {
public static ControlAction create(boolean isLatestVersion) {
return isLatestVersion ? new RabbitControlAction(DeleteUser.class, "rabbit_auth_backend_internal", "delete_user", DEFAULT_CONVERTER)
: new RabbitControlAction(DeleteUser.class, "rabbit_access_control", "delete_user", DEFAULT_CONVERTER);
return isLatestVersion ? new RabbitControlAction(DeleteUser.class, "rabbit_auth_backend_internal", "delete_user")
: new RabbitControlAction(DeleteUser.class, "rabbit_access_control", "delete_user");
}
}

public static class ChangePassword extends RabbitControlAction {
public static ControlAction create(boolean isLatestVersion) {
return isLatestVersion ? new RabbitControlAction(ChangePassword.class, "rabbit_auth_backend_internal", "change_password", DEFAULT_CONVERTER)
: new RabbitControlAction(ChangePassword.class, "rabbit_access_control", "change_password", DEFAULT_CONVERTER);
return isLatestVersion ? new RabbitControlAction(ChangePassword.class, "rabbit_auth_backend_internal", "change_password")
: new RabbitControlAction(ChangePassword.class, "rabbit_access_control", "change_password");
}
}

public static class StartBrokerApplication extends RabbitControlAction {
public static ControlAction create() {
return new RabbitControlAction(StartBrokerApplication.class, "rabbit", "start", DEFAULT_CONVERTER);
return new RabbitControlAction(StartBrokerApplication.class, "rabbit", "start");
}
}

public static class StopBrokerApplication extends RabbitControlAction {
public static ControlAction create() {
return new RabbitControlAction(StopBrokerApplication.class, "rabbit", "stop", DEFAULT_CONVERTER);
return new RabbitControlAction(StopBrokerApplication.class, "rabbit", "stop");
}
}

public static class StopNode extends RabbitControlAction {
public static ControlAction create() {
return new RabbitControlAction(StopNode.class, "rabbit", "stop_and_halt", DEFAULT_CONVERTER);
return new RabbitControlAction(StopNode.class, "rabbit", "stop_and_halt");
}
}

public static class ResetNode extends RabbitControlAction {
public static ControlAction create() {
return new RabbitControlAction(ResetNode.class, "rabbit_mnesia", "reset", DEFAULT_CONVERTER);
return new RabbitControlAction(ResetNode.class, "rabbit_mnesia", "reset");
}
}

public static class ForceResetNode extends RabbitControlAction {
public static ControlAction create() {
return new RabbitControlAction(ForceResetNode.class, "rabbit_mnesia", "force_reset", DEFAULT_CONVERTER);
return new RabbitControlAction(ForceResetNode.class, "rabbit_mnesia", "force_reset");
}
}

Expand All @@ -182,15 +180,13 @@ public static ControlAction create() {
}

/* TODO converter */

public static class ListExchanges extends RabbitControlAction {
public static ControlAction create() {
return new RabbitControlAction("rabbit_exchange", "list", null);
return new RabbitControlAction(ListExchanges.class, "rabbit_exchange", "list", null);
}
}

/* TODO */

/* TODO */
public static class ListBindings extends RabbitControlAction {
public static ControlAction create() {
return null;
Expand Down Expand Up @@ -404,5 +400,5 @@ private String extractNameValueFromTuple(OtpErlangTuple value) {
return new String(((OtpErlangBinary) nameElement).binaryValue());
}
}

}