Package com.hazelcast.client

Examples of com.hazelcast.client.ClientEndpoint


    protected abstract Predicate getPredicate();

    @Override
    public Object call() {
        final ClientEndpoint endpoint = getEndpoint();
        final ClientEngine clientEngine = getClientEngine();
        final MapService mapService = getService();

        EntryListener<Object, Object> listener = new EntryListener<Object, Object>() {

            private void handleEvent(EntryEvent<Object, Object> event) {
                if (endpoint.live()) {
                    Data key = clientEngine.toData(event.getKey());
                    Data value = clientEngine.toData(event.getValue());
                    Data oldValue = clientEngine.toData(event.getOldValue());
                    PortableEntryEvent portableEntryEvent = new PortableEntryEvent(key, value, oldValue, event.getEventType(), event.getMember().getUuid());
                    endpoint.sendEvent(portableEntryEvent, getCallId());
                }
            }

            public void entryAdded(EntryEvent<Object, Object> event) {
                handleEvent(event);
            }

            public void entryRemoved(EntryEvent<Object, Object> event) {
                handleEvent(event);
            }

            public void entryUpdated(EntryEvent<Object, Object> event) {
                handleEvent(event);
            }

            public void entryEvicted(EntryEvent<Object, Object> event) {
                handleEvent(event);
            }
        };

        EventFilter eventFilter;
        if (getPredicate() == null) {
            eventFilter = new EntryEventFilter(includeValue, key);
        } else {
            eventFilter = new QueryEventFilter(includeValue, key, getPredicate());
        }
        String registrationId = mapService.addEventListener(listener, eventFilter, name);
        endpoint.setListenerRegistration(MapService.SERVICE_NAME, name, registrationId);
        return registrationId;
    }
View Full Code Here


        this.timeout = timeout;
        this.data = data;
    }

    public Object innerCall() throws Exception {
        final ClientEndpoint endpoint = getEndpoint();
        final TransactionContext context = endpoint.getTransactionContext(txnId);
        final TransactionalQueue queue = context.getQueue(name);
        return queue.offer(data, timeout, TimeUnit.MILLISECONDS);
    }
View Full Code Here

        this.name = name;
        this.timeout = timeout;
    }

    public Object innerCall() throws Exception {
        final ClientEndpoint endpoint = getEndpoint();
        final TransactionContext context = endpoint.getTransactionContext(txnId);
        final TransactionalQueue queue = context.getQueue(name);
        return queue.poll(timeout, TimeUnit.MILLISECONDS);
    }
View Full Code Here

    public TxnSizeRequest(String name) {
        this.name = name;
    }

    public Object innerCall() throws Exception {
        final ClientEndpoint endpoint = getEndpoint();
        final TransactionContext context = endpoint.getTransactionContext(txnId);
        final TransactionalQueue queue = context.getQueue(name);
        return queue.size();
    }
View Full Code Here

        this.timeout = timeout;
    }

    @Override
    public Object innerCall() throws Exception {
        final ClientEndpoint endpoint = getEndpoint();
        final TransactionContext context = endpoint.getTransactionContext(txnId);
        final TransactionalQueue queue = context.getQueue(name);
        return queue.peek(timeout, TimeUnit.MILLISECONDS);
    }
View Full Code Here

    }

    @Override
    public Object innerCall() throws Exception {
        ClientEngineImpl clientEngine = getService();
        ClientEndpoint endpoint = getEndpoint();
        TransactionManagerServiceImpl transactionManager =
                (TransactionManagerServiceImpl) clientEngine.getTransactionManagerService();
        TransactionContext context = transactionManager.newClientTransactionContext(options, endpoint.getUuid());
        if (sXid != null) {
            Transaction transaction = TransactionAccessor.getTransaction(context);
            transactionManager.addManagedTransaction(sXid, transaction);
        }
        context.beginTransaction();
        endpoint.setTransactionContext(context);
        return context.getTxnId();
    }
View Full Code Here

        return MapReduceService.SERVICE_NAME;
    }

    @Override
    protected void invoke() {
        final ClientEndpoint endpoint = getEndpoint();

        MapReduceService mapReduceService = getService();
        JobSupervisor supervisor = mapReduceService.getJobSupervisor(name, jobId);

        JobProcessInformation processInformation = null;
        if (supervisor != null && supervisor.getJobProcessInformation() != null) {
            JobProcessInformation current = supervisor.getJobProcessInformation();
            processInformation = new TransferableJobProcessInformation(current.getPartitionStates(),
                    current.getProcessedRecords());
        }
        endpoint.sendResponse(processInformation, getCallId());
    }
View Full Code Here

    public RollbackTransactionRequest() {
    }

    @Override
    public Object innerCall() throws Exception {
        final ClientEndpoint endpoint = getEndpoint();
        endpoint.getTransactionContext(txnId).rollbackTransaction();
        endpoint.removeTransactionContext(txnId);
        return null;
    }
View Full Code Here

    }

    @Override
    public Object call() throws Exception {
        final ClusterServiceImpl service = getService();
        final ClientEndpoint endpoint = getEndpoint();

        final String registrationId = service.addMembershipListener(new MembershipListener() {
            @Override
            public void memberAdded(MembershipEvent membershipEvent) {
                if (endpoint.live()) {
                    final MemberImpl member = (MemberImpl) membershipEvent.getMember();
                    endpoint.sendEvent(new ClientMembershipEvent(member, MembershipEvent.MEMBER_ADDED), getCallId());
                }
            }

            @Override
            public void memberRemoved(MembershipEvent membershipEvent) {
                if (endpoint.live()) {
                    final MemberImpl member = (MemberImpl) membershipEvent.getMember();
                    endpoint.sendEvent(new ClientMembershipEvent(member, MembershipEvent.MEMBER_REMOVED), getCallId());
                }
            }

            public void memberAttributeChanged(MemberAttributeEvent memberAttributeEvent) {
                if (endpoint.live()) {
                    final MemberImpl member = (MemberImpl) memberAttributeEvent.getMember();
                    final String uuid = member.getUuid();
                    final MemberAttributeOperationType op = memberAttributeEvent.getOperationType();
                    final String key = memberAttributeEvent.getKey();
                    final Object value = memberAttributeEvent.getValue();
                    final MemberAttributeChange memberAttributeChange = new MemberAttributeChange(uuid, op, key, value);
                    endpoint.sendEvent(new ClientMembershipEvent(member, memberAttributeChange), getCallId());
                }
            }
        });

        final String name = ClusterServiceImpl.SERVICE_NAME;
        endpoint.setListenerRegistration(name, name, registrationId);

        final Collection<MemberImpl> memberList = service.getMemberList();
        final Collection<Data> response = new ArrayList<Data>(memberList.size());
        final SerializationService serializationService = getClientEngine().getSerializationService();
        for (MemberImpl member : memberList) {
View Full Code Here

    }

    @Override
    protected void invoke() {
        try {
            final ClientEndpoint endpoint = getEndpoint();

            MapReduceService mapReduceService = getService();
            NodeEngine nodeEngine = mapReduceService.getNodeEngine();
            AbstractJobTracker jobTracker = (AbstractJobTracker) mapReduceService.createDistributedObject(name);
            TrackableJobFuture jobFuture = new TrackableJobFuture(name, jobId, jobTracker, nodeEngine, null);
            if (jobTracker.registerTrackableJob(jobFuture)) {
                ICompletableFuture<Object> future = startSupervisionTask(jobFuture, mapReduceService, nodeEngine, jobTracker);
                future.andThen(new ExecutionCallback<Object>() {
                    @Override
                    public void onResponse(Object response) {
                        endpoint.sendResponse(response, getCallId());
                    }

                    @Override
                    public void onFailure(Throwable t) {
                        Throwable throwable = t;
                        if (throwable instanceof ExecutionException) {
                            throwable = throwable.getCause();
                        }
                        endpoint.sendResponse(throwable, getCallId());
                    }
                });
            }
        } catch (Exception e) {
            throw new IllegalStateException("Could not register map reduce job", e);
View Full Code Here

TOP

Related Classes of com.hazelcast.client.ClientEndpoint

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.