Search in sources :

Example 6 with ORemoteFetchListener

use of com.orientechnologies.orient.core.fetch.remote.ORemoteFetchListener in project orientdb by orientechnologies.

the class OAsyncCommandResultListener method result.

@Override
public boolean result(final Object iRecord) {
    if (empty.compareAndSet(true, false))
        try {
            protocol.sendOk(connection, txId);
        } catch (IOException ignored) {
        }
    try {
        fetchRecord(iRecord, new ORemoteFetchListener() {

            @Override
            protected void sendRecord(ORecord iLinked) {
                if (!alreadySent.contains(iLinked.getIdentity())) {
                    alreadySent.add(iLinked.getIdentity());
                    try {
                        // CACHE IT ON THE CLIENT
                        protocol.channel.writeByte((byte) 2);
                        protocol.writeIdentifiable(connection, iLinked);
                    } catch (IOException e) {
                        OLogManager.instance().error(this, "Cannot write against channel", e);
                    }
                }
            }
        });
        alreadySent.add(((OIdentifiable) iRecord).getIdentity());
        // ONE MORE RECORD
        protocol.channel.writeByte((byte) 1);
        protocol.writeIdentifiable(connection, ((OIdentifiable) iRecord).getRecord());
        // TODO review this flush... it's for non blocking...
        protocol.channel.flush();
        if (wrappedResultListener != null)
            // NOTIFY THE WRAPPED LISTENER
            wrappedResultListener.result(iRecord);
    } catch (IOException e) {
        return false;
    }
    return true;
}
Also used : ORemoteFetchListener(com.orientechnologies.orient.core.fetch.remote.ORemoteFetchListener) ORecord(com.orientechnologies.orient.core.record.ORecord) IOException(java.io.IOException)

Example 7 with ORemoteFetchListener

use of com.orientechnologies.orient.core.fetch.remote.ORemoteFetchListener in project orientdb by orientechnologies.

the class OSyncCommandResultListener method linkdedBySimpleValue.

@Override
public void linkdedBySimpleValue(ODocument doc) {
    ORemoteFetchListener listener = new ORemoteFetchListener() {

        @Override
        protected void sendRecord(ORecord iLinked) {
            if (!alreadySent.contains(iLinked))
                fetchedRecordsToSend.add(iLinked);
        }

        @Override
        public void parseLinked(ODocument iRootRecord, OIdentifiable iLinked, Object iUserObject, String iFieldName, OFetchContext iContext) throws OFetchException {
            if (!(iLinked instanceof ORecordId)) {
                sendRecord(iLinked.getRecord());
            }
        }

        @Override
        public void parseLinkedCollectionValue(ODocument iRootRecord, OIdentifiable iLinked, Object iUserObject, String iFieldName, OFetchContext iContext) throws OFetchException {
            if (!(iLinked instanceof ORecordId)) {
                sendRecord(iLinked.getRecord());
            }
        }
    };
    final OFetchContext context = new ORemoteFetchContext();
    OFetchHelper.fetch(doc, doc, OFetchHelper.buildFetchPlan(""), listener, context, "");
}
Also used : OFetchContext(com.orientechnologies.orient.core.fetch.OFetchContext) ORemoteFetchListener(com.orientechnologies.orient.core.fetch.remote.ORemoteFetchListener) ORemoteFetchContext(com.orientechnologies.orient.core.fetch.remote.ORemoteFetchContext) ORecord(com.orientechnologies.orient.core.record.ORecord) OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable) ORecordId(com.orientechnologies.orient.core.id.ORecordId) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Aggregations

ORemoteFetchListener (com.orientechnologies.orient.core.fetch.remote.ORemoteFetchListener)7 ORecord (com.orientechnologies.orient.core.record.ORecord)7 IOException (java.io.IOException)5 OFetchContext (com.orientechnologies.orient.core.fetch.OFetchContext)4 ORemoteFetchContext (com.orientechnologies.orient.core.fetch.remote.ORemoteFetchContext)4 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)4 ORecordId (com.orientechnologies.orient.core.id.ORecordId)3 OInterruptedException (com.orientechnologies.common.concur.lock.OInterruptedException)2 OLockException (com.orientechnologies.common.concur.lock.OLockException)2 OException (com.orientechnologies.common.exception.OException)2 OIOException (com.orientechnologies.common.io.OIOException)2 OIdentifiable (com.orientechnologies.orient.core.db.record.OIdentifiable)2 OFetchListener (com.orientechnologies.orient.core.fetch.OFetchListener)2 OFetchPlan (com.orientechnologies.orient.core.fetch.OFetchPlan)2 OOfflineClusterException (com.orientechnologies.orient.core.storage.impl.local.paginated.OOfflineClusterException)2 SocketException (java.net.SocketException)2