1 /*******************************************************************************
2 * Copyright (c) 2007, 2010 Association for Decentralized Information Management
4 * All rights reserved. This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License v1.0
6 * which accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * VTT Technical Research Centre of Finland - initial API and implementation
11 *******************************************************************************/
12 package org.simantics.db.common.request;
14 import org.simantics.db.AsyncRequestProcessor;
15 import org.simantics.db.RequestProcessor;
16 import org.simantics.db.exception.DatabaseException;
17 import org.simantics.db.procedure.AsyncListener;
18 import org.simantics.db.procedure.AsyncProcedure;
19 import org.simantics.db.procedure.Listener;
20 import org.simantics.db.procedure.Procedure;
21 import org.simantics.db.procedure.SyncListener;
22 import org.simantics.db.procedure.SyncProcedure;
23 import org.simantics.db.request.AsyncRead;
24 import org.simantics.db.request.ReadInterface;
26 public abstract class UnaryAsyncRead<P, R> implements AsyncRead<R>, ReadInterface<R> {
28 final protected P parameter;
31 public int hashCode() {
32 return parameter != null ? parameter.hashCode() : 0;
36 final public int threadHash() {
37 return parameter.hashCode();
41 public boolean equals(Object object) {
44 else if (object == null)
46 else if (getClass() != object.getClass())
48 UnaryAsyncRead<?, ?> r = (UnaryAsyncRead<?, ?>) object;
49 if(parameter != null) {
50 if(!parameter.equals(r.parameter)) return false;
51 } else if(r.parameter != null) return false;
56 public int getFlags() {
60 public UnaryAsyncRead(P parameter) {
61 this.parameter = parameter;
65 public void request(AsyncRequestProcessor processor, AsyncProcedure<R> procedure) {
66 processor.asyncRequest(this, procedure);
70 public void request(AsyncRequestProcessor processor, Procedure<R> procedure) {
71 processor.asyncRequest(this, procedure);
75 public void request(AsyncRequestProcessor processor, SyncProcedure<R> procedure) {
76 processor.asyncRequest(this, procedure);
80 public void request(AsyncRequestProcessor processor, AsyncListener<R> procedure) {
81 processor.asyncRequest(this, procedure);
85 public void request(AsyncRequestProcessor processor, Listener<R> procedure) {
86 processor.asyncRequest(this, procedure);
90 public void request(AsyncRequestProcessor processor, SyncListener<R> procedure) {
91 processor.asyncRequest(this, procedure);
95 public R request(RequestProcessor processor) throws DatabaseException {
96 return processor.syncRequest(this);