/** * Turn the load balancer on or off. * @param on If true, enable balancer. If false, disable balancer. * @param synchronous If true, it waits until current balance() call, if outstanding, to return. * @return Previous balancer value */ @Override public boolean setBalancerRunning(final boolean on, final boolean synchronous) throws IOException { return executeCallable(new MasterCallable<Boolean>(getConnection()) { @Override public Boolean call(int callTimeout) throws ServiceException { PayloadCarryingRpcController controller = rpcControllerFactory.newController(); controller.setCallTimeout(callTimeout); SetBalancerRunningRequest req = RequestConverter.buildSetBalancerRunningRequest(on, synchronous); return master.setBalancerRunning(controller, req).getPrevBalanceValue(); } }); }
/** * Turn the load balancer on or off. * @param on If true, enable balancer. If false, disable balancer. * @param synchronous If true, it waits until current balance() call, if outstanding, to return. * @return Previous balancer value */ public boolean setBalancerRunning(final boolean on, final boolean synchronous) throws MasterNotRunningException, ZooKeeperConnectionException { MasterKeepAliveConnection stub = connection.getKeepAliveMasterService(); try { SetBalancerRunningRequest req = RequestConverter.buildSetBalancerRunningRequest(on, synchronous); return stub.setBalancerRunning(null, req).getPrevBalanceValue(); } catch (ServiceException se) { IOException ioe = ProtobufUtil.getRemoteException(se); if (ioe instanceof MasterNotRunningException) { throw (MasterNotRunningException)ioe; } if (ioe instanceof ZooKeeperConnectionException) { throw (ZooKeeperConnectionException)ioe; } // Throwing MasterNotRunningException even though not really valid in order to not // break interface by adding additional exception type. throw new MasterNotRunningException("Unexpected exception when calling balanceSwitch",se); } finally { stub.close(); } }
@Override public SetBalancerRunningResponse setBalancerRunning(RpcController c, SetBalancerRunningRequest req) throws ServiceException { try { master.checkInitialized(); boolean prevValue = (req.getSynchronous())? synchronousBalanceSwitch(req.getOn()) : master.balanceSwitch(req.getOn()); return SetBalancerRunningResponse.newBuilder().setPrevBalanceValue(prevValue).build(); } catch (IOException ioe) { throw new ServiceException(ioe); } }
/** * Turn the load balancer on or off. * @param on If true, enable balancer. If false, disable balancer. * @param synchronous If true, it waits until current balance() call, if outstanding, to return. * @return Previous balancer value */ @Override public boolean setBalancerRunning(final boolean on, final boolean synchronous) throws IOException { return executeCallable(new MasterCallable<Boolean>(getConnection()) { @Override public Boolean call(int callTimeout) throws ServiceException { SetBalancerRunningRequest req = RequestConverter.buildSetBalancerRunningRequest(on, synchronous); return master.setBalancerRunning(null, req).getPrevBalanceValue(); } }); }
@Override public SetBalancerRunningResponse setBalancerRunning( RpcController controller, SetBalancerRunningRequest req) throws ServiceException { try { boolean prevValue = (req.getSynchronous())? synchronousBalanceSwitch(req.getOn()):balanceSwitch(req.getOn()); return SetBalancerRunningResponse.newBuilder().setPrevBalanceValue(prevValue).build(); } catch (IOException ioe) { throw new ServiceException(ioe); } }
/** * Creates a protocol buffer SetBalancerRunningRequest * * @param on * @param synchronous * @return a SetBalancerRunningRequest */ public static SetBalancerRunningRequest buildSetBalancerRunningRequest( boolean on, boolean synchronous) { return SetBalancerRunningRequest.newBuilder().setOn(on).setSynchronous(synchronous).build(); }
/** * Creates a protocol buffer SetBalancerRunningRequest * * @param on * @param synchronous * @return a SetBalancerRunningRequest */ public static SetBalancerRunningRequest buildSetBalancerRunningRequest(boolean on, boolean synchronous) { return SetBalancerRunningRequest.newBuilder().setOn(on).setSynchronous(synchronous).build(); }