-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3b20aaa
commit ec7da47
Showing
34 changed files
with
300 additions
and
135 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,37 +16,22 @@ | |
*/ | ||
package icu.funkye.redispike.common; | ||
|
||
import java.util.concurrent.CountDownLatch; | ||
import java.util.concurrent.atomic.AtomicBoolean; | ||
import java.util.concurrent.atomic.AtomicInteger; | ||
|
||
import com.alipay.remoting.Connection; | ||
import com.alipay.remoting.ConnectionEventProcessor; | ||
import icu.funkye.redispike.conts.RedisConstants; | ||
import icu.funkye.redispike.factory.AeroSpikeClientFactory; | ||
import org.junit.jupiter.api.Assertions; | ||
|
||
/** | ||
* ConnectionEventProcessor for ConnectionEventType.CONNECT | ||
* | ||
* @author xiaomin.cxm | ||
* @version $Id: CONNECTEventProcessor.java, v 0.1 Apr 8, 2016 10:58:48 AM xiaomin.cxm Exp $ | ||
* @author [email protected] | ||
*/ | ||
public class CONNECTEventProcessor implements ConnectionEventProcessor { | ||
|
||
private AtomicBoolean connected = new AtomicBoolean(); | ||
private AtomicInteger connectTimes = new AtomicInteger(); | ||
private Connection connection; | ||
private String remoteAddr; | ||
private CountDownLatch latch = new CountDownLatch(1); | ||
|
||
@Override | ||
public void onEvent(String remoteAddr, Connection conn) { | ||
Assertions.assertNotNull(remoteAddr); | ||
doCheckConnection(conn); | ||
this.remoteAddr = remoteAddr; | ||
this.connection = conn; | ||
connected.set(true); | ||
connectTimes.incrementAndGet(); | ||
latch.countDown(); | ||
conn.setAttribute(RedisConstants.REDIS_DB, AeroSpikeClientFactory.set); | ||
} | ||
|
||
/** | ||
|
@@ -61,30 +46,4 @@ private void doCheckConnection(Connection conn) { | |
Assertions.assertNotNull(conn.getUrl()); | ||
Assertions.assertNotNull(conn.getChannel().attr(Connection.CONNECTION).get()); | ||
} | ||
|
||
public boolean isConnected() throws InterruptedException { | ||
latch.await(); | ||
return this.connected.get(); | ||
} | ||
|
||
public int getConnectTimes() throws InterruptedException { | ||
latch.await(); | ||
return this.connectTimes.get(); | ||
} | ||
|
||
public Connection getConnection() throws InterruptedException { | ||
latch.await(); | ||
return this.connection; | ||
} | ||
|
||
public String getRemoteAddr() throws InterruptedException { | ||
latch.await(); | ||
return this.remoteAddr; | ||
} | ||
|
||
public void reset() { | ||
this.connectTimes.set(0); | ||
this.connected.set(false); | ||
this.connection = null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,41 +16,18 @@ | |
*/ | ||
package icu.funkye.redispike.common; | ||
|
||
import java.util.concurrent.atomic.AtomicBoolean; | ||
import java.util.concurrent.atomic.AtomicInteger; | ||
|
||
import com.alipay.remoting.Connection; | ||
import com.alipay.remoting.ConnectionEventProcessor; | ||
import org.junit.jupiter.api.Assertions; | ||
|
||
/** | ||
* ConnectionEventProcessor for ConnectionEventType.CLOSE | ||
* | ||
* @author xiaomin.cxm | ||
* @version $Id: DISCONNECTEventProcessor.java, v 0.1 Apr 8, 2016 10:58:48 AM xiaomin.cxm Exp $ | ||
* @author [email protected] | ||
*/ | ||
public class DISCONNECTEventProcessor implements ConnectionEventProcessor { | ||
|
||
private AtomicBoolean dicConnected = new AtomicBoolean(); | ||
private AtomicInteger disConnectTimes = new AtomicInteger(); | ||
|
||
@Override | ||
public void onEvent(String remoteAddr, Connection conn) { | ||
Assertions.assertNotNull(conn); | ||
dicConnected.set(true); | ||
disConnectTimes.incrementAndGet(); | ||
} | ||
|
||
public boolean isDisConnected() { | ||
return this.dicConnected.get(); | ||
} | ||
|
||
public int getDisConnectTimes() { | ||
return this.disConnectTimes.get(); | ||
} | ||
|
||
public void reset() { | ||
this.disConnectTimes.set(0); | ||
this.dicConnected.set(false); | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
src/main/java/icu/funkye/redispike/conts/RedisConstants.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package icu.funkye.redispike.conts; | ||
|
||
/** | ||
* @author [email protected] | ||
*/ | ||
public interface RedisConstants { | ||
|
||
String REDIS_DB = "db"; | ||
|
||
String REDIS_SUCCESS_RESULT = "OK"; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.