You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@labs.apache.org by no...@apache.org on 2009/07/15 10:51:04 UTC
svn commit: r794197 - in /labs/hupa/src/main/java/org/apache/hupa:
client/mvp/ server/ server/gin/ shared/data/ shared/rpc/
Author: norman
Date: Wed Jul 15 08:51:03 2009
New Revision: 794197
URL: http://svn.apache.org/viewvc?rev=794197&view=rev
Log:
Better "re-use" of connections
Added:
labs/hupa/src/main/java/org/apache/hupa/server/NoopHandler.java
labs/hupa/src/main/java/org/apache/hupa/shared/rpc/Noop.java
labs/hupa/src/main/java/org/apache/hupa/shared/rpc/NoopResult.java
Modified:
labs/hupa/src/main/java/org/apache/hupa/client/mvp/AppPresenter.java
labs/hupa/src/main/java/org/apache/hupa/client/mvp/MainPresenter.java
labs/hupa/src/main/java/org/apache/hupa/server/AbstractIMAPActionHandler.java
labs/hupa/src/main/java/org/apache/hupa/server/ExposeMessageHandler.java
labs/hupa/src/main/java/org/apache/hupa/server/FetchFoldersHandler.java
labs/hupa/src/main/java/org/apache/hupa/server/FetchMessagesHandler.java
labs/hupa/src/main/java/org/apache/hupa/server/LoginUserHandler.java
labs/hupa/src/main/java/org/apache/hupa/server/LogoutUserHandler.java
labs/hupa/src/main/java/org/apache/hupa/server/gin/ServerModul.java
labs/hupa/src/main/java/org/apache/hupa/shared/data/IMAPUser.java
Modified: labs/hupa/src/main/java/org/apache/hupa/client/mvp/AppPresenter.java
URL: http://svn.apache.org/viewvc/labs/hupa/src/main/java/org/apache/hupa/client/mvp/AppPresenter.java?rev=794197&r1=794196&r2=794197&view=diff
==============================================================================
--- labs/hupa/src/main/java/org/apache/hupa/client/mvp/AppPresenter.java (original)
+++ labs/hupa/src/main/java/org/apache/hupa/client/mvp/AppPresenter.java Wed Jul 15 08:51:03 2009
@@ -20,12 +20,20 @@
package org.apache.hupa.client.mvp;
+import net.customware.gwt.dispatch.client.DispatchAsync;
+
import org.apache.hupa.client.rpc.EventBus;
+import org.apache.hupa.shared.data.IMAPUser;
import org.apache.hupa.shared.events.LoginEvent;
import org.apache.hupa.shared.events.LoginEventHandler;
import org.apache.hupa.shared.events.LogoutEvent;
import org.apache.hupa.shared.events.LogoutEventHandler;
+import org.apache.hupa.shared.rpc.Noop;
+import org.apache.hupa.shared.rpc.NoopResult;
+import com.google.gwt.core.client.GWT;
+import com.google.gwt.user.client.Timer;
+import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.HasWidgets;
import com.google.inject.Inject;
@@ -35,19 +43,44 @@
private HasWidgets container;
private LoginPresenter loginPresenter;
private MainPresenter mainPresenter;
+ private Timer noopTimer;
+ private DispatchAsync dispatcher;
+ private IMAPUser user;
+
@Inject
- public AppPresenter(final EventBus bus, LoginPresenter loginPresenter, MainPresenter mainPresenter) {
+ public AppPresenter(final DispatchAsync dispatcher,final EventBus bus, LoginPresenter loginPresenter, MainPresenter mainPresenter) {
this.bus = bus;
+ this.dispatcher = dispatcher;
this.loginPresenter = loginPresenter;
this.mainPresenter = mainPresenter;
bindHandlers();
+
}
private void bindHandlers() {
bus.addHandler(LoginEvent.TYPE, new LoginEventHandler() {
public void onLogin(LoginEvent event) {
+ user = event.getUser();
+ noopTimer = new Timer() {
+
+ @Override
+ public void run() {
+ dispatcher.execute(new Noop(user), new AsyncCallback<NoopResult>() {
+
+ public void onFailure(Throwable caught) {
+ GWT.log("Error while NOOP", caught);
+ }
+
+ public void onSuccess(NoopResult result) {
+ }
+
+ });
+ }
+
+ };
+ noopTimer.scheduleRepeating(30000);
container.clear();
mainPresenter.go(container);
}
@@ -58,6 +91,9 @@
public void onLogout(LogoutEvent event) {
container.clear();
loginPresenter.go(container);
+ if (noopTimer != null) {
+ noopTimer.cancel();
+ }
}
});
Modified: labs/hupa/src/main/java/org/apache/hupa/client/mvp/MainPresenter.java
URL: http://svn.apache.org/viewvc/labs/hupa/src/main/java/org/apache/hupa/client/mvp/MainPresenter.java?rev=794197&r1=794196&r2=794197&view=diff
==============================================================================
--- labs/hupa/src/main/java/org/apache/hupa/client/mvp/MainPresenter.java (original)
+++ labs/hupa/src/main/java/org/apache/hupa/client/mvp/MainPresenter.java Wed Jul 15 08:51:03 2009
@@ -28,7 +28,6 @@
import org.apache.hupa.client.rpc.EventBus;
import org.apache.hupa.client.widgets.IMAPTreeItem;
-import org.apache.hupa.server.ExposeMessageHandler;
import org.apache.hupa.shared.data.IMAPFolder;
import org.apache.hupa.shared.data.IMAPMessage;
import org.apache.hupa.shared.data.IMAPUser;
@@ -55,6 +54,9 @@
import com.google.gwt.event.logical.shared.HasSelectionHandlers;
import com.google.gwt.event.logical.shared.SelectionEvent;
import com.google.gwt.event.logical.shared.SelectionHandler;
+import com.google.gwt.user.client.Window;
+import com.google.gwt.user.client.Window.ClosingEvent;
+import com.google.gwt.user.client.Window.ClosingHandler;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.HasValue;
import com.google.gwt.user.client.ui.HasWidgets;
@@ -143,6 +145,14 @@
});
+ Window.addWindowClosingHandler(new ClosingHandler() {
+
+ public void onWindowClosing(ClosingEvent event) {
+ doLogout();
+ }
+
+ });
+
}
protected void loadTreeItems() {
@@ -202,17 +212,7 @@
display.getLogoutClick().addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
- dispatcher.execute(new LogoutUser(user), new AsyncCallback<LogoutUserResult>() {
-
- public void onFailure(Throwable caught) {
- GWT.log("ERROR",caught);
- }
-
- public void onSuccess(LogoutUserResult result) {
- bus.fireEvent(new LogoutEvent(result.getUser()));
- }
-
- });
+ doLogout();
}
});
@@ -242,6 +242,21 @@
}
+ private void doLogout() {
+ if (user != null) {
+ dispatcher.execute(new LogoutUser(user), new AsyncCallback<LogoutUserResult>() {
+
+ public void onFailure(Throwable caught) {
+ GWT.log("ERROR",caught);
+ }
+
+ public void onSuccess(LogoutUserResult result) {
+ bus.fireEvent(new LogoutEvent(result.getUser()));
+ }
+
+ });
+ }
+ }
private void showMessageTable() {
display.getCenterContainer().clear();
Modified: labs/hupa/src/main/java/org/apache/hupa/server/AbstractIMAPActionHandler.java
URL: http://svn.apache.org/viewvc/labs/hupa/src/main/java/org/apache/hupa/server/AbstractIMAPActionHandler.java?rev=794197&r1=794196&r2=794197&view=diff
==============================================================================
--- labs/hupa/src/main/java/org/apache/hupa/server/AbstractIMAPActionHandler.java (original)
+++ labs/hupa/src/main/java/org/apache/hupa/server/AbstractIMAPActionHandler.java Wed Jul 15 08:51:03 2009
@@ -20,6 +20,8 @@
package org.apache.hupa.server;
import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
import org.apache.hupa.shared.data.IMAPUser;
import org.columba.ristretto.imap.IMAPException;
@@ -32,14 +34,22 @@
public abstract class AbstractIMAPActionHandler<A extends Action<R>, R extends Result> implements ActionHandler<A,R>{
- protected IMAPProtocol getProtocol(IMAPUser user) throws IOException,
+ protected final Map<IMAPUser,IMAPProtocol> pool = new HashMap<IMAPUser ,IMAPProtocol>();
+
+ protected synchronized IMAPProtocol getProtocol(IMAPUser user) throws IOException,
IMAPException {
- IMAPProtocol protocol = new IMAPProtocol("myblog.kicks-ass.org",
- IMAPProtocol.DEFAULT_PORT);
- protocol.openPort();
- protocol.login(user.getName(), user.getPassword().toCharArray());
-
+ IMAPProtocol protocol = pool.get(user);
+ if (protocol == null) {
+ protocol = new IMAPProtocol("myblog.kicks-ass.org",
+ IMAPProtocol.DEFAULT_PORT);
+ }
+ if (protocol.getState() == IMAPProtocol.NOT_CONNECTED) {
+ protocol.openPort();
+ }
+ if (protocol.getState() == IMAPProtocol.NON_AUTHENTICATED) {
+ protocol.login(user.getName(), user.getPassword().toCharArray());
+ }
+ pool.put(user,protocol);
return protocol;
-
}
}
Modified: labs/hupa/src/main/java/org/apache/hupa/server/ExposeMessageHandler.java
URL: http://svn.apache.org/viewvc/labs/hupa/src/main/java/org/apache/hupa/server/ExposeMessageHandler.java?rev=794197&r1=794196&r2=794197&view=diff
==============================================================================
--- labs/hupa/src/main/java/org/apache/hupa/server/ExposeMessageHandler.java (original)
+++ labs/hupa/src/main/java/org/apache/hupa/server/ExposeMessageHandler.java Wed Jul 15 08:51:03 2009
@@ -151,15 +151,7 @@
throw new ActionException("Unable to expose msg for uid "
+ msg.getUid());
- } finally {
- if (proto != null) {
- try {
- proto.close();
- } catch (Exception e) {
- // Ignore on close
- }
- }
- }
+ }
}
}
Modified: labs/hupa/src/main/java/org/apache/hupa/server/FetchFoldersHandler.java
URL: http://svn.apache.org/viewvc/labs/hupa/src/main/java/org/apache/hupa/server/FetchFoldersHandler.java?rev=794197&r1=794196&r2=794197&view=diff
==============================================================================
--- labs/hupa/src/main/java/org/apache/hupa/server/FetchFoldersHandler.java (original)
+++ labs/hupa/src/main/java/org/apache/hupa/server/FetchFoldersHandler.java Wed Jul 15 08:51:03 2009
@@ -95,15 +95,7 @@
e.printStackTrace();
throw new ActionException("Unable to get folders for User "
+ user);
- } finally {
- if (protocol != null) {
- try {
- protocol.close();
- } catch (Exception e) {
- // Ignore on close
- }
- }
- }
+ }
}
private void handleIMAPFolderTree(List<IMAPFolder> fList,
Modified: labs/hupa/src/main/java/org/apache/hupa/server/FetchMessagesHandler.java
URL: http://svn.apache.org/viewvc/labs/hupa/src/main/java/org/apache/hupa/server/FetchMessagesHandler.java?rev=794197&r1=794196&r2=794197&view=diff
==============================================================================
--- labs/hupa/src/main/java/org/apache/hupa/server/FetchMessagesHandler.java (original)
+++ labs/hupa/src/main/java/org/apache/hupa/server/FetchMessagesHandler.java Wed Jul 15 08:51:03 2009
@@ -158,14 +158,6 @@
throw new ActionException(
"Error while fetching headers for user " + user.getName()
+ ": " + e.getMessage());
- } finally {
- if (proto != null) {
- try {
- proto.close();
- } catch (Exception e) {
- // Ignore on close
- }
- }
}
}
}
Modified: labs/hupa/src/main/java/org/apache/hupa/server/LoginUserHandler.java
URL: http://svn.apache.org/viewvc/labs/hupa/src/main/java/org/apache/hupa/server/LoginUserHandler.java?rev=794197&r1=794196&r2=794197&view=diff
==============================================================================
--- labs/hupa/src/main/java/org/apache/hupa/server/LoginUserHandler.java (original)
+++ labs/hupa/src/main/java/org/apache/hupa/server/LoginUserHandler.java Wed Jul 15 08:51:03 2009
@@ -29,7 +29,6 @@
import org.apache.hupa.shared.rpc.LoginUser;
import org.apache.hupa.shared.rpc.LoginUserResult;
import org.columba.ristretto.imap.IMAPException;
-import org.columba.ristretto.imap.IMAPProtocol;
public class LoginUserHandler extends
AbstractIMAPActionHandler<LoginUser, LoginUserResult> {
@@ -57,10 +56,8 @@
IMAPUser user = new IMAPUser();
user.setName(username);
user.setPassword(password);
- IMAPProtocol protocol = getProtocol(user);
- protocol.openPort();
- protocol.login(username, password.toCharArray());
-
+ getProtocol(user);
+
user.setLoginDate(new Date());
user.setAuthenticated(true);
return user;
Modified: labs/hupa/src/main/java/org/apache/hupa/server/LogoutUserHandler.java
URL: http://svn.apache.org/viewvc/labs/hupa/src/main/java/org/apache/hupa/server/LogoutUserHandler.java?rev=794197&r1=794196&r2=794197&view=diff
==============================================================================
--- labs/hupa/src/main/java/org/apache/hupa/server/LogoutUserHandler.java (original)
+++ labs/hupa/src/main/java/org/apache/hupa/server/LogoutUserHandler.java Wed Jul 15 08:51:03 2009
@@ -20,12 +20,16 @@
package org.apache.hupa.server;
+import java.io.IOException;
+
import net.customware.gwt.dispatch.server.ExecutionContext;
import net.customware.gwt.dispatch.shared.ActionException;
import org.apache.hupa.shared.data.IMAPUser;
import org.apache.hupa.shared.rpc.LogoutUser;
import org.apache.hupa.shared.rpc.LogoutUserResult;
+import org.columba.ristretto.imap.IMAPException;
+import org.columba.ristretto.imap.IMAPProtocol;
public class LogoutUserHandler extends AbstractIMAPActionHandler<LogoutUser, LogoutUserResult> {
@@ -33,6 +37,9 @@
throws ActionException {
IMAPUser user = action.getUser();
user.setAuthenticated(false);
+
+ disconnect(user);
+
return new LogoutUserResult(user);
}
@@ -42,8 +49,25 @@
public void rollback(LogoutUser arg0, LogoutUserResult arg1,
ExecutionContext arg2) throws ActionException {
- // TODO Auto-generated method stub
}
+
+ protected void disconnect(IMAPUser user) {
+ try {
+ IMAPProtocol proto = getProtocol(user);
+ if (proto.getState() != IMAPProtocol.NOT_CONNECTED) {
+ proto.logout();
+ }
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (IMAPException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ synchronized (pool) {
+ pool.remove(user);
+ }
+ }
}
Added: labs/hupa/src/main/java/org/apache/hupa/server/NoopHandler.java
URL: http://svn.apache.org/viewvc/labs/hupa/src/main/java/org/apache/hupa/server/NoopHandler.java?rev=794197&view=auto
==============================================================================
--- labs/hupa/src/main/java/org/apache/hupa/server/NoopHandler.java (added)
+++ labs/hupa/src/main/java/org/apache/hupa/server/NoopHandler.java Wed Jul 15 08:51:03 2009
@@ -0,0 +1,51 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one *
+ * or more contributor license agreements. See the NOTICE file *
+ * distributed with this work for additional information *
+ * regarding copyright ownership. The ASF licenses this file *
+ * to you under the Apache License, Version 2.0 (the *
+ * "License"); you may not use this file except in compliance *
+ * with the License. You may obtain a copy of the License at *
+ * *
+ * http://www.apache.org/licenses/LICENSE-2.0 *
+ * *
+ * Unless required by applicable law or agreed to in writing, *
+ * software distributed under the License is distributed on an *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY *
+ * KIND, either express or implied. See the License for the *
+ * specific language governing permissions and limitations *
+ * under the License. *
+ ****************************************************************/
+
+package org.apache.hupa.server;
+
+import net.customware.gwt.dispatch.server.ExecutionContext;
+import net.customware.gwt.dispatch.shared.ActionException;
+
+import org.apache.hupa.shared.rpc.Noop;
+import org.apache.hupa.shared.rpc.NoopResult;
+
+public class NoopHandler extends AbstractIMAPActionHandler<Noop, NoopResult>{
+
+ public NoopResult execute(Noop action, ExecutionContext context)
+ throws ActionException {
+ try {
+ getProtocol(action.getUser()).noop();
+ return new NoopResult();
+ } catch (Exception e) {
+ throw new ActionException("Unable to send NOOP",e);
+ }
+
+ }
+
+ public Class<Noop> getActionType() {
+ return Noop.class;
+ }
+
+ public void rollback(Noop arg0, NoopResult arg1, ExecutionContext arg2)
+ throws ActionException {
+ // TODO Auto-generated method stub
+
+ }
+
+}
Modified: labs/hupa/src/main/java/org/apache/hupa/server/gin/ServerModul.java
URL: http://svn.apache.org/viewvc/labs/hupa/src/main/java/org/apache/hupa/server/gin/ServerModul.java?rev=794197&r1=794196&r2=794197&view=diff
==============================================================================
--- labs/hupa/src/main/java/org/apache/hupa/server/gin/ServerModul.java (original)
+++ labs/hupa/src/main/java/org/apache/hupa/server/gin/ServerModul.java Wed Jul 15 08:51:03 2009
@@ -26,6 +26,7 @@
import org.apache.hupa.server.FetchMessagesHandler;
import org.apache.hupa.server.LoginUserHandler;
import org.apache.hupa.server.LogoutUserHandler;
+import org.apache.hupa.server.NoopHandler;
/**
* Module which binds the handlers
@@ -43,5 +44,6 @@
bindHandler(FetchMessagesHandler.class);
bindHandler(LogoutUserHandler.class);
bindHandler(ExposeMessageHandler.class);
+ bindHandler(NoopHandler.class);
}
}
Modified: labs/hupa/src/main/java/org/apache/hupa/shared/data/IMAPUser.java
URL: http://svn.apache.org/viewvc/labs/hupa/src/main/java/org/apache/hupa/shared/data/IMAPUser.java?rev=794197&r1=794196&r2=794197&view=diff
==============================================================================
--- labs/hupa/src/main/java/org/apache/hupa/shared/data/IMAPUser.java (original)
+++ labs/hupa/src/main/java/org/apache/hupa/shared/data/IMAPUser.java Wed Jul 15 08:51:03 2009
@@ -68,4 +68,13 @@
public String toString() {
return getName();
}
+
+ public boolean equals(Object object) {
+ if (object instanceof IMAPUser) {
+ if (((IMAPUser) object).getName().equals(getName())) {
+ return true;
+ }
+ }
+ return false;
+ }
}
Added: labs/hupa/src/main/java/org/apache/hupa/shared/rpc/Noop.java
URL: http://svn.apache.org/viewvc/labs/hupa/src/main/java/org/apache/hupa/shared/rpc/Noop.java?rev=794197&view=auto
==============================================================================
--- labs/hupa/src/main/java/org/apache/hupa/shared/rpc/Noop.java (added)
+++ labs/hupa/src/main/java/org/apache/hupa/shared/rpc/Noop.java Wed Jul 15 08:51:03 2009
@@ -0,0 +1,45 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one *
+ * or more contributor license agreements. See the NOTICE file *
+ * distributed with this work for additional information *
+ * regarding copyright ownership. The ASF licenses this file *
+ * to you under the Apache License, Version 2.0 (the *
+ * "License"); you may not use this file except in compliance *
+ * with the License. You may obtain a copy of the License at *
+ * *
+ * http://www.apache.org/licenses/LICENSE-2.0 *
+ * *
+ * Unless required by applicable law or agreed to in writing, *
+ * software distributed under the License is distributed on an *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY *
+ * KIND, either express or implied. See the License for the *
+ * specific language governing permissions and limitations *
+ * under the License. *
+ ****************************************************************/
+
+package org.apache.hupa.shared.rpc;
+
+import org.apache.hupa.shared.data.IMAPUser;
+
+import net.customware.gwt.dispatch.shared.Action;
+
+public class Noop implements Action<NoopResult>{
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 4076791577558340559L;
+ private IMAPUser user;
+
+ @SuppressWarnings("unused")
+ private Noop() {
+
+ }
+ public Noop(IMAPUser user) {
+ this.user = user;
+ }
+
+ public IMAPUser getUser() {
+ return user;
+ }
+}
Added: labs/hupa/src/main/java/org/apache/hupa/shared/rpc/NoopResult.java
URL: http://svn.apache.org/viewvc/labs/hupa/src/main/java/org/apache/hupa/shared/rpc/NoopResult.java?rev=794197&view=auto
==============================================================================
--- labs/hupa/src/main/java/org/apache/hupa/shared/rpc/NoopResult.java (added)
+++ labs/hupa/src/main/java/org/apache/hupa/shared/rpc/NoopResult.java Wed Jul 15 08:51:03 2009
@@ -0,0 +1,34 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one *
+ * or more contributor license agreements. See the NOTICE file *
+ * distributed with this work for additional information *
+ * regarding copyright ownership. The ASF licenses this file *
+ * to you under the Apache License, Version 2.0 (the *
+ * "License"); you may not use this file except in compliance *
+ * with the License. You may obtain a copy of the License at *
+ * *
+ * http://www.apache.org/licenses/LICENSE-2.0 *
+ * *
+ * Unless required by applicable law or agreed to in writing, *
+ * software distributed under the License is distributed on an *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY *
+ * KIND, either express or implied. See the License for the *
+ * specific language governing permissions and limitations *
+ * under the License. *
+ ****************************************************************/
+
+package org.apache.hupa.shared.rpc;
+
+import net.customware.gwt.dispatch.shared.Result;
+
+public class NoopResult implements Result{
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 5530385273335407315L;
+
+ public NoopResult() {
+
+ }
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@labs.apache.org
For additional commands, e-mail: commits-help@labs.apache.org