redisNodeList) {
36 | this.redisNodeList = redisNodeList;
37 | }
38 |
39 | @Override
40 | public String toString() {
41 | return "RedisGroup{" +
42 | "redisNodeList=" + redisNodeList +
43 | '}';
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/mpush-tools/src/main/java/com/mpush/tools/crypto/Base64Utils.java:
--------------------------------------------------------------------------------
1 | /*
2 | * (C) Copyright 2015-2016 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | *
16 | * Contributors:
17 | * ohun@live.cn (夜色)
18 | */
19 |
20 | package com.mpush.tools.crypto;
21 |
22 |
23 | import com.mpush.api.Constants;
24 |
25 | import java.util.Base64;
26 |
27 | public class Base64Utils {
28 |
29 | /**
30 | *
31 | * BASE64字符串解码为二进制数据
32 | *
33 | *
34 | * @param base64 base64
35 | * @return 源二进制数据
36 | */
37 | public static byte[] decode(String base64) {
38 | return Base64.getDecoder().decode(base64.getBytes(Constants.UTF_8));
39 | }
40 |
41 | /**
42 | *
43 | * 二进制数据编码为BASE64字符串
44 | *
45 | *
46 | * @param bytes base64
47 | * @return BASE64后的二进制数据
48 | */
49 | public static String encode(byte[] bytes) {
50 | return new String(Base64.getEncoder().encode(bytes), Constants.UTF_8);
51 | }
52 |
53 | }
--------------------------------------------------------------------------------
/mpush-tools/src/main/java/com/mpush/tools/crypto/CryptoException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * (C) Copyright 2015-2016 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | *
16 | * Contributors:
17 | * ohun@live.cn (夜色)
18 | */
19 |
20 | package com.mpush.tools.crypto;
21 |
22 | /**
23 | * Created by ohun on 2015/12/23.
24 | *
25 | * @author ohun@live.cn
26 | */
27 | public class CryptoException extends RuntimeException {
28 |
29 | private static final long serialVersionUID = 368277451733324220L;
30 |
31 | public CryptoException(String message) {
32 | super(message);
33 | }
34 |
35 | public CryptoException(String message, Throwable cause) {
36 | super(message, cause);
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/mpush-tools/src/main/java/com/mpush/tools/event/EventBus.java:
--------------------------------------------------------------------------------
1 | /*
2 | * (C) Copyright 2015-2016 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | *
16 | * Contributors:
17 | * ohun@live.cn (夜色)
18 | */
19 |
20 | package com.mpush.tools.event;
21 |
22 | import com.google.common.eventbus.AsyncEventBus;
23 | import com.mpush.api.event.Event;
24 | import org.slf4j.Logger;
25 | import org.slf4j.LoggerFactory;
26 |
27 | import java.util.concurrent.Executor;
28 |
29 | /**
30 | * Created by ohun on 2015/12/29.
31 | *
32 | * @author ohun@live.cn
33 | */
34 | public class EventBus {
35 | private static final Logger LOGGER = LoggerFactory.getLogger(EventBus.class);
36 | private static com.google.common.eventbus.EventBus eventBus;
37 |
38 | public static void create(Executor executor) {
39 | eventBus = new AsyncEventBus(executor, (exception, context)
40 | -> LOGGER.error("event bus subscriber ex", exception));
41 | }
42 |
43 | public static void post(Event event) {
44 | eventBus.post(event);
45 | }
46 |
47 | public static void register(Object bean) {
48 | eventBus.register(bean);
49 | }
50 |
51 | public static void unregister(Object bean) {
52 | eventBus.unregister(bean);
53 | }
54 |
55 | }
56 |
--------------------------------------------------------------------------------
/mpush-tools/src/main/java/com/mpush/tools/event/EventConsumer.java:
--------------------------------------------------------------------------------
1 | /*
2 | * (C) Copyright 2015-2016 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | *
16 | * Contributors:
17 | * ohun@live.cn (夜色)
18 | */
19 |
20 | package com.mpush.tools.event;
21 |
22 | public abstract class EventConsumer {
23 |
24 | public EventConsumer() {
25 | EventBus.register(this);
26 | }
27 |
28 | }
29 |
--------------------------------------------------------------------------------
/mpush-tools/src/main/java/com/mpush/tools/thread/pool/DefaultExecutor.java:
--------------------------------------------------------------------------------
1 | /*
2 | * (C) Copyright 2015-2016 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | *
16 | * Contributors:
17 | * ohun@live.cn (夜色)
18 | */
19 | package com.mpush.tools.thread.pool;
20 |
21 | import java.util.concurrent.*;
22 |
23 | /**
24 | * Created by yxx on 2016/5/29.
25 | *
26 | * @author ohun@live.cn (夜色)
27 | */
28 | public final class DefaultExecutor extends ThreadPoolExecutor {
29 |
30 | public DefaultExecutor(int corePoolSize, int maximumPoolSize,
31 | long keepAliveTime, TimeUnit unit,
32 | BlockingQueue workQueue,
33 | ThreadFactory threadFactory,
34 | RejectedExecutionHandler handler) {
35 | super(corePoolSize, maximumPoolSize, keepAliveTime, unit, workQueue, threadFactory, handler);
36 | }
37 |
38 | }
39 |
--------------------------------------------------------------------------------
/mpush-tools/src/main/resources/META-INF/services/com.mpush.api.spi.common.JsonFactory:
--------------------------------------------------------------------------------
1 | com.mpush.tools.common.DefaultJsonFactory
--------------------------------------------------------------------------------
/mpush-tools/src/test/java/com/mpush/tools/crypto/AESUtilsTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * (C) Copyright 2015-2016 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | *
16 | * Contributors:
17 | * ohun@live.cn (夜色)
18 | */
19 |
20 | package com.mpush.tools.crypto;
21 |
22 | import com.mpush.api.Constants;
23 | import org.junit.Test;
24 |
25 | import java.util.Random;
26 |
27 | /**
28 | * Created by ohun on 2015/12/25.
29 | */
30 | public class AESUtilsTest {
31 |
32 | @Test
33 | public void testEncryptDES() throws Exception {
34 | String data = "似的士大夫士大夫士大夫首发式发生士大夫";
35 | System.out.println("原文:\n" + data);
36 | byte[] key = new byte[16];
37 | new Random().nextBytes(key);
38 | byte[] d1 = AESUtils.encrypt(data.getBytes(Constants.UTF_8), key,key);
39 | System.out.println("加密后:\n" + new String(d1));
40 | byte[] d2 = AESUtils.decrypt(d1, key,key);
41 | System.out.println("解密后:\n" + new String(d2, Constants.UTF_8));
42 | }
43 |
44 | @Test
45 | public void testDecryptDES() throws Exception {
46 |
47 | }
48 | }
--------------------------------------------------------------------------------
/mpush-zk/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | 4.0.0
7 |
8 |
9 | mpush
10 | com.github.mpusher
11 | 0.8.1
12 | ../pom.xml
13 |
14 |
15 | mpush-zk
16 | jar
17 | mpush-zookeeper
18 | MPUSH消息推送系统zookeeper集群控制模块
19 | https://github.com/mpusher/mpush
20 |
21 |
22 |
23 | ${project.groupId}
24 | mpush-monitor
25 |
26 |
27 | org.apache.curator
28 | curator-recipes
29 |
30 |
31 | org.apache.curator
32 | curator-x-discovery
33 |
34 |
35 |
36 |
--------------------------------------------------------------------------------
/mpush-zk/src/main/java/com/mpush/zk/ZKDiscoveryFactory.java:
--------------------------------------------------------------------------------
1 | /*
2 | * (C) Copyright 2015-2016 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | *
16 | * Contributors:
17 | * ohun@live.cn (夜色)
18 | */
19 |
20 | package com.mpush.zk;
21 |
22 | import com.mpush.api.spi.Spi;
23 | import com.mpush.api.spi.common.ServiceDiscoveryFactory;
24 | import com.mpush.api.srd.ServiceDiscovery;
25 |
26 | /**
27 | * Created by ohun on 2016/12/27.
28 | *
29 | * @author ohun@live.cn (夜色)
30 | */
31 | @Spi(order = 1)
32 | public final class ZKDiscoveryFactory implements ServiceDiscoveryFactory {
33 | @Override
34 | public ServiceDiscovery get() {
35 | return ZKServiceRegistryAndDiscovery.I;
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/mpush-zk/src/main/java/com/mpush/zk/ZKException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * (C) Copyright 2015-2016 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | *
16 | * Contributors:
17 | * ohun@live.cn (夜色)
18 | */
19 |
20 | package com.mpush.zk;
21 |
22 | /**
23 | * Created by yxx on 2016/5/14.
24 | *
25 | * @author ohun@live.cn
26 | */
27 | public class ZKException extends RuntimeException {
28 |
29 | public ZKException() {
30 | }
31 |
32 | public ZKException(String message) {
33 | super(message);
34 | }
35 |
36 | public ZKException(String message, Throwable cause) {
37 | super(message, cause);
38 | }
39 |
40 | public ZKException(Throwable cause) {
41 | super(cause);
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/mpush-zk/src/main/java/com/mpush/zk/ZKRegistryFactory.java:
--------------------------------------------------------------------------------
1 | /*
2 | * (C) Copyright 2015-2016 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | *
16 | * Contributors:
17 | * ohun@live.cn (夜色)
18 | */
19 |
20 | package com.mpush.zk;
21 |
22 | import com.mpush.api.spi.Spi;
23 | import com.mpush.api.spi.common.ServiceRegistryFactory;
24 | import com.mpush.api.srd.ServiceRegistry;
25 |
26 | /**
27 | * Created by ohun on 2016/12/27.
28 | *
29 | * @author ohun@live.cn (夜色)
30 | */
31 | @Spi(order = 1)
32 | public final class ZKRegistryFactory implements ServiceRegistryFactory {
33 | @Override
34 | public ServiceRegistry get() {
35 | return ZKServiceRegistryAndDiscovery.I;
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/mpush-zk/src/main/resources/META-INF/services/com.mpush.api.spi.common.ServiceDiscoveryFactory:
--------------------------------------------------------------------------------
1 | com.mpush.zk.ZKDiscoveryFactory
--------------------------------------------------------------------------------
/mpush-zk/src/main/resources/META-INF/services/com.mpush.api.spi.common.ServiceRegistryFactory:
--------------------------------------------------------------------------------
1 | com.mpush.zk.ZKRegistryFactory
--------------------------------------------------------------------------------