Skip to content
This repository has been archived by the owner on Feb 11, 2022. It is now read-only.

Migration guide

Ryan Feline edited this page May 31, 2017 · 7 revisions

Pre v1 Melin

Below is a sample usage of Merlin pre v1 release.

merlin = new Merlin.Builder()
                .setEndPoint("http://google.com")
                .setResponseCodeValidator(new ResponseCodeValidator() {
                    @Override
                    public boolean isResponseCodeValid(int responseCode) {
                        return true;
                    }
                }).withAllCallbacks()
                .withLogging(true)
                .build(this);

        merlin.registerConnectable(new Connectable() {
            @Override
            public void onConnect() {
                Log.e(getClass().getSimpleName(), "onConnect");
            }
        });

        merlin.registerBindable(new Bindable() {
            @Override
            public void onBind(NetworkStatus networkStatus) {
                Log.e(getClass().getSimpleName(), "onBind");
            }
        });

        merlin.registerDisconnectable(new Disconnectable() {
            @Override
            public void onDisconnect() {
                Log.e(getClass().getSimpleName(), "onDisconnect");
            }
        });

Migrating the above example

Below is the migration of the above code to v1 Merlin.

merlin = new Merlin.Builder()
                .withEndpoint(Endpoint.from("http://google.com"))
                .withResponseCodeValidator(new ResponseCodeValidator() {
                    @Override
                    public boolean isResponseCodeValid(int responseCode) {
                        return true;
                    }
                }).withAllCallbacks()
                .build(this);

        Logger.attach(new DemoLogHandle());

        merlin.registerConnectable(new Connectable() {
            @Override
            public void onConnect() {
                Log.e(getClass().getSimpleName(), "onConnect");
            }
        });

        merlin.registerBindable(new Bindable() {
            @Override
            public void onBind(NetworkStatus networkStatus) {
                Log.e(getClass().getSimpleName(), "onBind");
            }
        });

        merlin.registerDisconnectable(new Disconnectable() {
            @Override
            public void onDisconnect() {
                Log.e(getClass().getSimpleName(), "onDisconnect");
            }
        });
    }

    private static class DemoLogHandle implements Logger.LogHandle {

        private static final String TAG = "DemoLogHandle";

        @Override
        public void v(Object... message) {
            Log.v(TAG, message[0].toString());
        }

        // ... Methods omitted for brevity.

        @Override
        public void i(Object... message) {
            Log.i(TAG, message[0].toString());
        }
    }

Notable changes for migration

  • All builder methods now follow the format with[ComponentToBuildWith].
    • setEndPoint() -> withEndpoint()
    • setResponseCodeValidator() -> withResponseCodeValidator()
  • Endpoint to enforce type safety on the HostPinger. Clients now need to pass an Endpoint to the MerlinBuilder.withEndpoint() call.

  • MerlinBuilder.withLogging() has been deprecated and replaced with a Logger. Clients can now specify a LogHandle dictating where all instances of Merlin log to.


Migrating RxJava Merlin

Clients are no longer forced to support RxJava when importing the standard Merlin dependency. Clients can now add these optional dependencies to the build.gradle file in addition to the standard Merlin dependency.

compile 'com.novoda:merlin-rxjava:[version_number]'
compile 'com.novoda:merlin-rxjava2:[version_number]'