All Projects → SilenceDut → Router

SilenceDut / Router

Router —— A substitute good of EventBus similar implemented by dynamic proxy

Programming Languages

java
68154 projects - #9 most used programming language

Projects that are alternatives of or similar to Router

Eventline
Micro-framework for routing and handling events for bots and applications 🤖. IFTTT for developers 👩‍💻👨‍💻
Stars: ✭ 305 (+107.48%)
Mutual labels:  eventbus, router
Dowse
The Awareness Hub for the Internet of Things
Stars: ✭ 139 (-5.44%)
Mutual labels:  router
Androideventbus
[DEPRECATED] A lightweight eventbus library for android, simplifies communication between Activities, Fragments, Threads, Services, etc.
Stars: ✭ 1,597 (+986.39%)
Mutual labels:  eventbus
Http
An opinionated framework for scalable web 🌎
Stars: ✭ 136 (-7.48%)
Mutual labels:  router
Luthier Ci
Improved routing, middleware support, authentication tools and more for CodeIgniter 3 framework
Stars: ✭ 129 (-12.24%)
Mutual labels:  router
Esp slip router
A SLIP to WiFi router
Stars: ✭ 135 (-8.16%)
Mutual labels:  router
Eventbus
C# 事件总线实现
Stars: ✭ 127 (-13.61%)
Mutual labels:  eventbus
Nextjs Dynamic Routes
[Deprecated] Super simple way to create dynamic routes with Next.js
Stars: ✭ 145 (-1.36%)
Mutual labels:  router
Pure Http
✨ The simple web framework for Node.js with zero dependencies.
Stars: ✭ 139 (-5.44%)
Mutual labels:  router
Router5
Flexible and powerful universal routing solution
Stars: ✭ 1,704 (+1059.18%)
Mutual labels:  router
React Resource Router
Configuration driven routing solution for React SPAs that manages route matching, data fetching and progressive rendering
Stars: ✭ 136 (-7.48%)
Mutual labels:  router
Laravel Router
An organized approach to handling routes in Laravel.
Stars: ✭ 130 (-11.56%)
Mutual labels:  router
Grip
The microframework for writing powerful web applications.
Stars: ✭ 137 (-6.8%)
Mutual labels:  router
Fastroute
Simple, idiomatic and fast 161 loc http router for golang
Stars: ✭ 128 (-12.93%)
Mutual labels:  router
Pimd
PIM-SM/SSM multicast routing for UNIX
Stars: ✭ 143 (-2.72%)
Mutual labels:  router
React Redux Graphql Apollo Bootstrap Webpack Starter
react js + redux + graphQL + Apollo + react router + hot reload + devTools + bootstrap + webpack starter
Stars: ✭ 127 (-13.61%)
Mutual labels:  router
React Redux Bootstrap Webpack Starter
React 16.9 + Typescript + React-Router 4 + Redux + Bootstrap 4 + Hot Reload + redux-devtools-extension + Webpack 4 + styled-components STARTER
Stars: ✭ 133 (-9.52%)
Mutual labels:  router
Decouplingkit
decoupling between modules in your iOS Project. iOS模块化过程中模块间解耦方案
Stars: ✭ 136 (-7.48%)
Mutual labels:  router
Vue Stack Router
Vue Stack Router
Stars: ✭ 146 (-0.68%)
Mutual labels:  router
Yrv
Your routing! (for Svelte)
Stars: ✭ 143 (-2.72%)
Mutual labels:  router

Latest version

router 1.2.8 —— modified code to avoid concurrent bugs

router 1.2.6 -- use apt to process subscribe annotation

router 1.2.0 -- use WeakReference to avoid MemoryLeak cause by forgot unregister

Project

It had been used in project KnowWeather and diffadapter demo ,you can learn more.

What's Router

English | 中文文档

Router -- A substitute good of EventBus similar implemented by dynamic proxy

dynamic proxy

what's dynamic proxy and how to use , see my blog 代理模式的学习与应用

Background

EventBus is good ,but there are some problems when use.

  • EventBus is not friendly to IDE such as AS.so on registered method ,control+click(or other shortcut key) can't take you to what's actually being called , and there no any prompt when you post a event even you get a mistake.

  • when called post(Event event),EventBus use Event type to find the received method ,so you must define many class for different received methods to avoid invoked unexpected even they have same class type or you only want dispatch a base type such as a int value

above all , when project gets larger or multiple developers work on project,which greatly increases the cost of developing and maintaining.

Feature

  • take even no time and memory when register , only add a object reference to a map.
  • friendly to IDE, you can easily find the action from where it was called. and when you try to send a event there while be a prompt by ide.
  • defined method to match event instead of many methods.
  • both Router and MVP design model using implement interface as a way of communication ,so it fit perfectly in MVP .
  • proven in practice by mature apps.

Use

Router is easily use especially when you had used EventBus before.

Step1. define interface and method whatever you want

interface AnyInterface {
    void anyMethod(AnyType posting) ;
}

Step2. register to Router where you need implement the interface

class AnyClass implement AnyInterface {

    //register on a appropriate lifecycle or constructor
    Router.getInstance().register(this); 
    
    //it will be invoked on UI Thread
    void anyMethod(AnyType object)  {
        //do what you want
    }
}

Step3. invoke the method you defined before

Router.getInstance().getReceiver(AnyInterface.class).anyMethod(AnyType object);

Step4. unregister when not use anymore or a appropriate lifecycle

Router.getInstance().unregister(this);

now a publish/subscribe is completed,simple as EventBus.

Method Invoked Thread

Use Annotation invoke method in different threads

 @Subscribe(runThread = RunThread.MAIN)
 @Subscribe(runThread = RunThread.POSTING)
 @Subscribe(runThread = RunThread.ASYNC)
 @Subscribe(runThread = RunThread.BACKGROUND)

Just like EventBus's way to reduce learning cost. if not add Annotation, will use @Subscribe(runThread = RunThread.Main) as default.

Annotation Mode

mode 1 :add Annotation on implemented method, it as default
@Subscribe(runThread = RunThread.BACKGROUND)
public void anyMethod(String msg) {
    ...
}

anyMethod will invoked on RunThread.BACKGROUND thread

mode 2 :add Annotation on interface's method
Router.getInstance().setAnnotateMethodOnInterface(true);

interface TestRunThread {
     @Subscribe(runThread = RunThread.POSTING)
     void anyMethod(String posting) ;
}

on this mode, all class which implement the method will be invoked on the RunThread.POSTING thread.

more use details , see the simple.

Add to project

gradle

compile 'com.silencedut:router:1.2.8'

maven

<dependency>
  <groupId>com.silencedut</groupId>
  <artifactId>router</artifactId>
  <version>1.2.8</version>
  <type>pom</type>
</dependency>

License

Copyright 2015-2016 SilenceDut

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].