All Projects → AlbieLiang → Ipcinvoker

AlbieLiang / Ipcinvoker

Licence: apache-2.0
A IPC Invoker for Android Development.

Programming Languages

java
68154 projects - #9 most used programming language

Projects that are alternatives of or similar to Ipcinvoker

qtalk-go
versatile stream IO and RPC based IPC stack for Go
Stars: ✭ 29 (-83.52%)
Mutual labels:  ipc, rpc
electron-ipc-bus
An IPC bus for Electron.
Stars: ✭ 23 (-86.93%)
Mutual labels:  ipc, rpc
metacom
RPC communication protocol for Metarhia stack 🔌
Stars: ✭ 42 (-76.14%)
Mutual labels:  ipc, rpc
sirdez
Glorious Binary Serialization and Deserialization for TypeScript.
Stars: ✭ 20 (-88.64%)
Mutual labels:  ipc, rpc
Discordipc
Connect locally to the Discord client using IPC for a subset of RPC features like Rich Presence and Activity Join/Spectate
Stars: ✭ 66 (-62.5%)
Mutual labels:  rpc, ipc
coreipc
WCF-like service model API for communication over named pipes and TCP. .NET and node.js clients.
Stars: ✭ 22 (-87.5%)
Mutual labels:  ipc, rpc
InterProcessCommunication
Inter-process Communication
Stars: ✭ 11 (-93.75%)
Mutual labels:  ipc, rpc
Ether1
Official Go implementation of The Etho Protocol
Stars: ✭ 41 (-76.7%)
Mutual labels:  ipc, rpc
Scalecube Services
v2.0 - ScaleCube Services provides a low latency Reactive Microservices library for serverless service registry and discovery based on gossip protocol and without single point-of-failure or bottlenecks.
Stars: ✭ 23 (-86.93%)
Mutual labels:  rpc, ipc
Rpc Thunderdome
A comparison between Proteus RPC and other commonly used RPC frameworks
Stars: ✭ 22 (-87.5%)
Mutual labels:  rpc, ipc
csgo richpresence
Discord Rich Presence support for Counter-Strike: Global Offensive!
Stars: ✭ 16 (-90.91%)
Mutual labels:  ipc, rpc
Shadesmar
Fast C++ IPC using shared memory (with msgpack)
Stars: ✭ 126 (-28.41%)
Mutual labels:  rpc, ipc
Sgf
This is a Smart Game Foundation (Not Framework)
Stars: ✭ 122 (-30.68%)
Mutual labels:  rpc, ipc
Jstp
Fast RPC for browser and Node.js based on TCP, WebSocket, and MDSF
Stars: ✭ 132 (-25%)
Mutual labels:  rpc, ipc
Awesome Kotlin Android
awesome kotlin for android !
Stars: ✭ 164 (-6.82%)
Mutual labels:  android-development
Advancedrecycleview
♻ RecycleView with multiple view types, inner horizontal RecycleView and layout animation
Stars: ✭ 172 (-2.27%)
Mutual labels:  android-development
Surgingdemo
surging 使用入门示例。完成一个基本业务的增删改查示例,并运用Surging强大的分布式缓存功能
Stars: ✭ 165 (-6.25%)
Mutual labels:  rpc
Awesomedialog
A Beautiful Dialog Library for Kotlin Android
Stars: ✭ 163 (-7.39%)
Mutual labels:  android-development
Kraps Rpc
A RPC framework leveraging Spark RPC module
Stars: ✭ 175 (-0.57%)
Mutual labels:  rpc
Awesome Kotlin
A curated list of awesome Kotlin frameworks, libraries, documents and other resources
Stars: ✭ 2,128 (+1109.09%)
Mutual labels:  android-development

IPCInvoker

license Release Version wiki PRs Welcome

在Android开发过程中,经常需要写一些跨进程的逻辑,一般情况下我们都是通过AIDL接口来调用的,写AIDL接口并不是一件容易的事情,需要写Service,定义特定的业务接口,调用时需要绑定Service等。

IPCInvoker就是一个用来简化跨进程调用的组件,IPCInvoker底层也是通过AIDL实现的,只是把接口封装得更加容易使用。

引入组件库

IPCInvoker组件库已经提交到jcenter上了,可以直接dependencies中配置引用

dependencies {
    api 'cc.suitalk.android:ipc-invoker:<last-version>'
}

在项目中使用

为每个需要支持IPCInvoker的进程创建一个Service

这里以PushProcessIPCService为示例,代码如下:

public class PushProcessIPCService extends BaseIPCService {

    public static final String PROCESS_NAME = "cc.suitalk.ipcinvoker.sample:push";

    @Override
    public String getProcessName() {
        return PROCESS_NAME;
    }
}

在manifest.xml中配置service

<service android:name="cc.suitalk.ipcinvoker.sample.service.PushProcessIPCService" android:process=":push"/>

在项目的Application中setup IPCInvoker

这里需要在你的项目所有需要支持跨进程调用的进程中调用IPCInvoker.setup(Application, IPCInvokerInitDelegate)方法,并在传入的IPCInvokerInitDelegate接口实现中将该进程需要支持访问的其它进程相应的Service的class添加到IPCInvoker当中,示例如下:

public class IPCInvokerApplication extends Application {

    @Override
    public void onCreate() {
        super.onCreate();
        // Initialize IPCInvoker
        IPCInvoker.setup(this, new DefaultInitDelegate() {
            
            @Override
            public void onAttachServiceInfo(IPCInvokerInitializer initializer) {
                initializer.addIPCService(PushProcessIPCService.PROCESS_NAME, PushProcessIPCService.class);
            }
        });
    }
}

在项目代码中通过IPCInvoker调用跨进程逻辑

通过IPCInvoker同步调用跨进程逻辑

public class InvokeSyncSample {

    private static final String TAG = "InvokeSyncSample";

    public static void invokeSync() {
        Integer result = IPCInvoker.invokeSync(
                PushProcessIPCService.PROCESS_NAME, "Albie", HashCode.class);
        Log.i(TAG, "invoke result : %s", result);
    }

    private static class HashCode implements IPCSyncInvokeTask<String, Integer> {

        @Override
        public IPCInteger invoke(String data) {
            return data.hashCode();
        }
    }
}

通过IPCInvoker异步调用跨进程逻辑

public class InvokeAsyncSample {

    private static final String TAG = "InvokeAsyncSample";

    public static void invokeAsync() {
        IPCInvoker.invokeAsync(PushProcessIPCService.PROCESS_NAME,
                "Albie", HashCode.class, new IPCInvokeCallback<Integer>() {
            @Override
            public void onCallback(Integer data) {
                Log.i(TAG, "onCallback : hascode : %d", data);
            }
        });
    }

    private static class HashCode implements IPCAsyncInvokeTask<String, Integer> {

        @Override
        public void invoke(String data, IPCInvokeCallback<Integer> callback) {
            callback.onCallback(data.hashCode());
        }
    }
}

IPCInvoker支持自定义实现的Parcelable类作为跨进程调用的数据结构,同时也支持基础类型的包装类、Map和List,对于既非基础类型也非Parcelable类型,则需要自定义TypeTransfer来达到可跨进程传输的效果。

通过IPCTask实现跨进程调用

IPCTask提供了相对IPCInvoker更为丰富的接口,支持设置连接超时,连接回调,异常回调和确实结果等。与此同时IPCTask支持基本数据类型,并提供了不同于IPCInvoker链式调用方式。

异步调用

public class IPCTaskTestCase {
    
    private static final String TAG = "IPCTaskTestCase";
    
    public static void invokeAsync() {
        IPCTask.create("cc.suitalk.ipcinvoker.sample:push")
                .timeout(10)
                .async(AsyncInvokeTask.class)
                .data("test invokeAsync")
                .defaultResult(false)
                .callback(true, new IPCInvokeCallback<Boolean>() {
                    @Override
                    public void onCallback(Boolean data) {
                        /// callback on UI Thread
                        Log.i(TAG, "invokeAsync result : %s", data);
                    }
                }).invoke();
    }

    private static class AsyncInvokeTask implements IPCAsyncInvokeTask<String, Boolean> {

        @Override
        public void invoke(String data, IPCInvokeCallback<Boolean> callback) {
            callback.onCallback(true);
        }
    }
}

同步调用

public class IPCTaskTestCase {

    private static final String TAG = "IPCTaskTestCase";

    public static void invokeSync() {
        Map<String, Object> map = new HashMap<>();
        map.put("key", "value");
        Boolean result = IPCTask.create("cc.suitalk.ipcinvoker.sample:push")
                .timeout(20)
                .sync(SyncInvokeTask.class)
                .data(map)
                .defaultResult(false)
                .invoke();
        Log.i(TAG, "invokeSync result : %s", result);
    }

    private static class SyncInvokeTask implements IPCSyncInvokeTask<Map<String, Object>, Boolean> {

        @Override
        public Boolean invoke(Map<String, Object> data) {
            return true;
        }
    }
}

此外,IPCInvoker还支持跨进程事件监听和分发等丰富的功能,详细使用说明请参考wiki ,更多使用示例请移步Sample工程

License

   Copyright 2017 Albie Liang

   Licensed 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.
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].