class StandardRoleListener implements RoleListener {

    private static final Logger LOG = Log.logger(StandardRoleListener.class);

    private final TaskManager taskManager;

    private final GlobalMasterInfo roleInfo;

    private volatile boolean selfIsMaster;

    public StandardRoleListener(TaskManager taskManager,
                                GlobalMasterInfo roleInfo) {
        this.taskManager = taskManager;
        this.taskManager.enableRoleElection();
        this.roleInfo = roleInfo;
        this.selfIsMaster = false;
    }

    @Override
    public void onAsRoleMaster(StateMachineContext context) {
        if (!selfIsMaster) {
            this.taskManager.onAsRoleMaster();
            LOG.info("Server {} change to master role", context.config().node());
        }
        this.updateMasterInfo(context);
        this.selfIsMaster = true;
    }

    @Override
    public void onAsRoleWorker(StateMachineContext context) {
        if (this.selfIsMaster) {
            this.taskManager.onAsRoleWorker();
            LOG.info("Server {} change to worker role", context.config().node());
        }
        this.updateMasterInfo(context);
        this.selfIsMaster = false;
    }

    @Override
    public void onAsRoleCandidate(StateMachineContext context) {
        // pass
    }

    @Override
    public void onAsRoleAbdication(StateMachineContext context) {
        if (this.selfIsMaster) {
            this.taskManager.onAsRoleWorker();
            LOG.info("Server {} change to worker role", context.config().node());
        }
        this.updateMasterInfo(context);
        this.selfIsMaster = false;
    }

    @Override
    public void error(StateMachineContext context, Throwable e) {
        LOG.error("Server {} exception occurred", context.config().node(), e);
    }

    @Override
    public void unknown(StateMachineContext context) {<FILL_FUNCTION_BODY>}

    public void updateMasterInfo(StateMachineContext context) {
        StateMachineContext.MasterServerInfo master = context.master();
        if (master == null) {
            this.roleInfo.resetMasterInfo();
            return;
        }

        boolean isMaster = Objects.equals(context.node(), master.node());
        this.roleInfo.masterInfo(isMaster, master.url());
    }
}

        if (this.selfIsMaster) {
            this.taskManager.onAsRoleWorker();
            LOG.info("Server {} change to worker role", context.config().node());
        }
        this.updateMasterInfo(context);

        this.selfIsMaster = false;
    
<no_super_class>