test_class.file: jimsql/jim-rpc/src/test/java/io/jimdb/rpc/client/ConnectEventListenerTest.java
test_class.identifier: ConnectEventListenerTest
test_class.superclass: extends BaseTest
test_case.body: @Test
    public void handleEventTest() {
      ScheduledExecutorService retryExecutor = Executors.newSingleThreadScheduledExecutor();
      ConnectEventListener listener = new ConnectEventListener(retryExecutor);
      Connection conn = pool.getConn();
      conn.connect();
      Assert.assertEquals(true, conn.isActive());
      conn.getChannel().close();
  
      sleep(1000);
      Assert.assertEquals(false, conn.isActive());
      ConnectEvent connectEvent = new ConnectEvent(conn, ConnectEvent.EventType.CLOSE);
      listener.handleEvent(connectEvent);
      sleep(1000);
      Assert.assertEquals(true, conn.isActive());
    }
test_case.class_method_signature: ConnectEventListenerTest.handleEventTest()
test_case.full_signature: @Test public void handleEventTest()
test_case.identifier: handleEventTest
test_case.invocations: newSingleThreadScheduledExecutor getConn connect assertEquals isActive close getChannel sleep assertEquals isActive handleEvent sleep assertEquals isActive
test_case.modifiers: @Test public
test_case.parameters: ()
test_case.return: void
test_case.signature: void handleEventTest()
focal_class.declarator: reconnects
focal_class.modifier: private final
focal_class.original_string: private final ConcurrentHashMap<String, Boolean> reconnects;
focal_class.type: ConcurrentHashMap<String, Boolean>
focal_class.var_name: reconnects
focal_class.declarator: retryExecutor
focal_class.modifier: private final
focal_class.original_string: private final ScheduledExecutorService retryExecutor;
focal_class.type: ScheduledExecutorService
focal_class.var_name: retryExecutor
focal_class.declarator: retryPolicy
focal_class.modifier: private final
focal_class.original_string: private final RetryPolicy retryPolicy;
focal_class.type: RetryPolicy
focal_class.var_name: retryPolicy
focal_class.file: jimsql/jim-rpc/src/main/java/io/jimdb/rpc/client/ConnectEventListener.java
focal_class.identifier: ConnectEventListener
focal_class.interfaces: implements EventListener
focal_class.class_method_signature: ConnectEventListener.ConnectEventListener(ScheduledExecutorService retryExecutor)
focal_class.full_signature: public  ConnectEventListener(ScheduledExecutorService retryExecutor)
focal_class.identifier: ConnectEventListener
focal_class.modifiers: public
focal_class.parameters: (ScheduledExecutorService retryExecutor)
focal_class.signature:  ConnectEventListener(ScheduledExecutorService retryExecutor)
focal_class.class_method_signature: ConnectEventListener.getName()
focal_class.full_signature: @Override public String getName()
focal_class.identifier: getName
focal_class.modifiers: @Override public
focal_class.parameters: ()
focal_class.return: String
focal_class.signature: String getName()
focal_class.class_method_signature: ConnectEventListener.isSupport(Event e)
focal_class.full_signature: @Override public boolean isSupport(Event e)
focal_class.identifier: isSupport
focal_class.modifiers: @Override public
focal_class.parameters: (Event e)
focal_class.return: boolean
focal_class.signature: boolean isSupport(Event e)
focal_class.class_method_signature: ConnectEventListener.handleEvent(Event e)
focal_class.full_signature: @Override public void handleEvent(Event e)
focal_class.identifier: handleEvent
focal_class.modifiers: @Override public
focal_class.parameters: (Event e)
focal_class.return: void
focal_class.signature: void handleEvent(Event e)
focal_method.body: @Override
    public void handleEvent(Event e) {
      final ConnectEvent connEvent = (ConnectEvent) e;
      final Connection conn = connEvent.getConn();
      if (conn == null) {
        return;
      }
  
      final ConnectEvent.EventType type = connEvent.getEventType();
      boolean reconnect = false;
      if (type == ConnectEvent.EventType.CLOSE || type == ConnectEvent.EventType.RECONNECT || type == ConnectEvent.EventType.EXCEPTION) {
        reconnect = reconnects.putIfAbsent(conn.getID(), Boolean.TRUE) == null;
      }
  
      if (reconnect) {
        conn.reconnect = true;
        retryExecutor.execute(new RetryTask("Reconnect-" + conn.getID(), retryPolicy, retryExecutor, new RetryCallback() {
          @Override
          public boolean execute() {
            return conn.reConnect();
          }
  
          @Override
          public void onTerminate(boolean success) {
            reconnects.remove(conn.getID());
            conn.reconnect = false;
          }
        }));
  
        conn.logEvent(ConnectEvent.EventType.RECONNECT);
      }
    }
focal_method.class_method_signature: ConnectEventListener.handleEvent(Event e)
focal_method.full_signature: @Override public void handleEvent(Event e)
focal_method.identifier: handleEvent
focal_method.invocations: getConn getEventType putIfAbsent getID execute getID reConnect remove getID logEvent
focal_method.modifiers: @Override public
focal_method.parameters: (Event e)
focal_method.return: void
focal_method.signature: void handleEvent(Event e)