diff options
author | Eike Stepper | 2016-02-04 11:02:49 +0000 |
---|---|---|
committer | Eike Stepper | 2016-02-04 11:06:07 +0000 |
commit | 08257c866d21ff0592802c754820f9996d45802e (patch) | |
tree | 8f9f3f898c442cf6670f97339d5ab237b0c64d25 /plugins/org.eclipse.emf.cdo.server.net4j | |
parent | 45b55081f4200d675e18ec5cbd4a120b1b52bfe4 (diff) | |
download | cdo-08257c866d21ff0592802c754820f9996d45802e.tar.gz cdo-08257c866d21ff0592802c754820f9996d45802e.tar.xz cdo-08257c866d21ff0592802c754820f9996d45802e.zip |
[486458] Provide support for optimized loading and notifying of object units
https://bugs.eclipse.org/bugs/show_bug.cgi?id=486458
Diffstat (limited to 'plugins/org.eclipse.emf.cdo.server.net4j')
2 files changed, 131 insertions, 0 deletions
diff --git a/plugins/org.eclipse.emf.cdo.server.net4j/src/org/eclipse/emf/cdo/server/internal/net4j/protocol/CDOServerProtocol.java b/plugins/org.eclipse.emf.cdo.server.net4j/src/org/eclipse/emf/cdo/server/internal/net4j/protocol/CDOServerProtocol.java index 158ec41677..8b87235fcd 100644 --- a/plugins/org.eclipse.emf.cdo.server.net4j/src/org/eclipse/emf/cdo/server/internal/net4j/protocol/CDOServerProtocol.java +++ b/plugins/org.eclipse.emf.cdo.server.net4j/src/org/eclipse/emf/cdo/server/internal/net4j/protocol/CDOServerProtocol.java @@ -391,6 +391,9 @@ public class CDOServerProtocol extends SignalProtocol<InternalSession> implement case SIGNAL_RESET_TRANSACTION: return new ResetTransactionIndication(this); + case SIGNAL_UNIT: + return new UnitIndication(this); + default: return super.createSignalReactor(signalID); } diff --git a/plugins/org.eclipse.emf.cdo.server.net4j/src/org/eclipse/emf/cdo/server/internal/net4j/protocol/UnitIndication.java b/plugins/org.eclipse.emf.cdo.server.net4j/src/org/eclipse/emf/cdo/server/internal/net4j/protocol/UnitIndication.java new file mode 100644 index 0000000000..7277f935fa --- /dev/null +++ b/plugins/org.eclipse.emf.cdo.server.net4j/src/org/eclipse/emf/cdo/server/internal/net4j/protocol/UnitIndication.java @@ -0,0 +1,128 @@ +/* + * Copyright (c) 2016 Eike Stepper (Berlin, Germany) and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Eike Stepper - initial API and implementation + */ +package org.eclipse.emf.cdo.server.internal.net4j.protocol; + +import org.eclipse.emf.cdo.common.id.CDOID; +import org.eclipse.emf.cdo.common.protocol.CDODataInput; +import org.eclipse.emf.cdo.common.protocol.CDODataOutput; +import org.eclipse.emf.cdo.common.protocol.CDOProtocolConstants; +import org.eclipse.emf.cdo.common.revision.CDORevision; +import org.eclipse.emf.cdo.common.revision.CDORevisionHandler; +import org.eclipse.emf.cdo.server.IUnit; +import org.eclipse.emf.cdo.server.IUnitManager; +import org.eclipse.emf.cdo.spi.server.InternalView; + +import org.eclipse.net4j.util.om.monitor.OMMonitor; +import org.eclipse.net4j.util.om.monitor.OMMonitor.Async; + +import java.io.IOException; + +/** + * @author Eike Stepper + */ +public class UnitIndication extends CDOServerReadIndicationWithMonitoring +{ + private int viewID; + + private CDOID rootID; + + private byte opcode; + + public UnitIndication(CDOServerProtocol protocol) + { + super(protocol, CDOProtocolConstants.SIGNAL_UNIT); + } + + @Override + protected void indicating(CDODataInput in, OMMonitor monitor) throws Exception + { + viewID = in.readInt(); + rootID = in.readCDOID(); + opcode = in.readByte(); + } + + @Override + protected void responding(final CDODataOutput out, OMMonitor monitor) throws Exception + { + final InternalView view = getView(viewID); + IUnitManager unitManager = getRepository().getUnitManager(); + + if (opcode == CDOProtocolConstants.UNIT_CHECK) + { + out.writeBoolean(unitManager.isUnit(rootID)); + return; + } + + if (opcode == CDOProtocolConstants.UNIT_CLOSE) + { + IUnit unit = unitManager.getUnit(rootID); + if (unit != null) + { + unit.close(view); + out.writeBoolean(true); + return; + } + + out.writeBoolean(false); + return; + } + + final IOException[] ioException = { null }; + final RuntimeException[] runtimeException = { null }; + + monitor.begin(); + Async async = monitor.forkAsync(); + + try + { + boolean success = view.openUnit(rootID, opcode == CDOProtocolConstants.UNIT_CREATE, new CDORevisionHandler() + { + public boolean handleRevision(CDORevision revision) + { + try + { + view.unsubscribe(revision.getID()); + out.writeCDORevision(revision, CDORevision.UNCHUNKED); // Exposes revision to client side + return true; + } + catch (IOException ex) + { + ioException[0] = ex; + } + catch (RuntimeException ex) + { + runtimeException[0] = ex; + } + + return false; + } + }); + + if (ioException[0] != null) + { + throw ioException[0]; + } + + if (runtimeException[0] != null) + { + throw runtimeException[0]; + } + + out.writeCDORevision(null, CDORevision.UNCHUNKED); // No more revisions + out.writeBoolean(success); + } + finally + { + async.stop(); + monitor.done(); + } + } +} |