Skip to content

Commit

Permalink
Improve performance of teiid view by reducing number of refreshes
Browse files Browse the repository at this point in the history
* TeiidServer
 * Moves the server listener to TeiidServerManager
 * Adds a notify flag that can turn off the firing of the
   refresh listener
 * Adds a reconnect method that makes use of the notify flag
   so reducing the number of server refreshes

* TeiidServerManager
 * Adds the server state listener that used to be in TeiidServer

* TeiidServerContentProvider
 * Finish the refresh thread on disposal of the provider

* TeiidResouceNode
 * Ensure an error is set for the node even if server is null
  • Loading branch information
Paul Richardson committed Nov 10, 2012
1 parent 603cc6a commit ee1c4ff
Show file tree
Hide file tree
Showing 10 changed files with 182 additions and 109 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -215,8 +215,7 @@ setDefaultServerActionToolTip = Set As Default Teiid Instance
setDefaultServerActionDisconnectOldTitle=Disconnect Current Default Teiid Instance
setDefaultServerActionDisconnectOldMessage=Do you wish to disconnect from {0} before switching to new default Teiid Instance?

serverReconnectErrorMsg = Error connecting to Teiid {0}. See log for additional information.


serverEmptyUserMsg = The user name cannot be empty
serverExistsMsg = {0} already exists so it cannot be added
serverInvalidUrlMsg = The value "{0}" is not a valid Teiid URL
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import org.teiid.designer.runtime.TeiidServer;
import org.teiid.designer.runtime.ui.DqpUiConstants;
import org.teiid.designer.runtime.ui.DqpUiPlugin;
import org.teiid.designer.ui.common.util.WidgetUtil;
import org.teiid.designer.ui.common.viewsupport.UiBusyIndicator;


Expand Down Expand Up @@ -43,14 +42,7 @@ public void run() {

@Override
public void run() {
try {
// Call disconnect() first to clear out Server & admin caches
teiidServer.disconnect();
} catch (Exception e) {
UTIL.log(e);
String msg = UTIL.getString("serverReconnectErrorMsg", teiidServer); //$NON-NLS-1$
WidgetUtil.showError(msg);
}
teiidServer.disconnect();
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import org.teiid.designer.runtime.ui.DqpUiConstants;
import org.teiid.designer.runtime.ui.DqpUiPlugin;
import org.teiid.designer.runtime.ui.views.content.TeiidResourceNode;
import org.teiid.designer.ui.common.util.WidgetUtil;
import org.teiid.designer.ui.common.viewsupport.UiBusyIndicator;


Expand Down Expand Up @@ -53,22 +54,10 @@ public void run() {

@Override
public void run() {
try {
// Call disconnect() first to clear out Server & admin caches
teiidServer.disconnect();

if (! teiidServer.isParentConnected())
return;

// Refresh is implied in the getting of the admin object since it will
// automatically load and refresh.
teiidServer.getAdmin();
teiidServer.setConnectionError(null);
} catch (Exception e) {
UTIL.log(e);
String msg = UTIL.getString("serverReconnectErrorMsg", teiidServer); //$NON-NLS-1$
teiidServer.setConnectionError(msg);
}
teiidServer.reconnect();

if (teiidServer.getConnectionError() != null)
WidgetUtil.showError(teiidServer.getConnectionError());
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,15 +87,12 @@ public void run() {
UiBusyIndicator.showWhile(Display.getDefault(), new Runnable() {

@Override
public void run() {
try {
// Call disconnect() first to clear out Server & admin caches
theNewDefaultServer.getAdmin().refresh();
} catch (Exception e) {
UTIL.log(e);
String msg = UTIL.getString("serverReconnectErrorMsg", theNewDefaultServer.getUrl()); //$NON-NLS-1$
WidgetUtil.showError(msg);
}
public void run() {
// Call disconnect() first to clear out Server & admin caches
theNewDefaultServer.reconnect();

if (theNewDefaultServer.getConnectionError() != null)
WidgetUtil.showError(theNewDefaultServer.getConnectionError());
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ public class TeiidServerContentProvider implements ITreeContentProvider {

private class RefreshThread extends Thread {
private boolean refreshCompleted = true;

private boolean die = false;

private LinkedBlockingQueue<Object> queue = new LinkedBlockingQueue<Object>();

Expand All @@ -86,13 +88,24 @@ public void done(IJobChangeEvent event) {
});
}


/**
* End the thread
*/
public void die() {
die = true;
}

public void refresh() {
if (die)
return;

queue.add(new Object());
}

@Override
public void run() {
while (! Thread.currentThread().isInterrupted()) {
while (! Thread.currentThread().isInterrupted() && ! die) {
try {
if (refreshCompleted) {
queue.take();
Expand Down Expand Up @@ -467,5 +480,8 @@ public void dispose() {
pendingUpdates.clear();

DqpPlugin.getInstance().getServerManager().removeListener(configListener);

refreshThread.die();
refreshThread = null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -92,16 +92,14 @@ public final void load() {
try {
teiidServer = (TeiidServer) getServer().loadAdapter(TeiidServer.class, null);

if (teiidServer != null) {
if (teiidServer.isConnected()) {
if (children == null)
children = new ArrayList<IContentNode<? extends IContainerNode<?>>>();
if (teiidServer != null && teiidServer.isConnected()) {
if (children == null)
children = new ArrayList<IContentNode<? extends IContainerNode<?>>>();

children.add(new TeiidServerContainerNode(this, provider));
} else {
setError(new TeiidErrorNode(this, teiidServer, DqpUiConstants.UTIL.getString(getClass().getSimpleName() + ".labelNotConnected"))); //$NON-NLS-1$
return;
}
children.add(new TeiidServerContainerNode(this, provider));
} else {
setError(new TeiidErrorNode(this, teiidServer, DqpUiConstants.UTIL.getString(getClass().getSimpleName() + ".labelNotConnected"))); //$NON-NLS-1$
return;
}

clearError();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public Object getAdapter(Object adaptableObject, Class adapterType) {
if (TeiidServer.class == adapterType)
return adaptToTeiidServer(teiidResourceNode);

if (TeiidResourceNode.class == adapterType)
if (TeiidServerContainerNode.class == adapterType)
return adaptToTeiidServerContainerNode(teiidResourceNode);

return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,11 @@
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.wst.server.core.IServer;
import org.eclipse.wst.server.core.IServerListener;
import org.eclipse.wst.server.core.ServerEvent;
import org.teiid.adminapi.Admin;
import org.teiid.adminapi.AdminException;
import org.teiid.adminapi.AdminFactory;
import org.teiid.core.designer.util.CoreArgCheck;
import org.teiid.designer.core.util.StringUtilities;
import org.teiid.designer.runtime.adapter.TeiidServerAdapterUtil;
import org.teiid.jdbc.TeiidDriver;


Expand Down Expand Up @@ -94,44 +91,12 @@ private static boolean equivalent( Object thisObj,
*/
private IServer parentServer;

private IServerListener serverListener = new IServerListener() {

@Override
public void serverChanged(ServerEvent event) {
if (event == null)
return;

int eventKind = event.getKind();
if ((eventKind & ServerEvent.SERVER_CHANGE) == 0)
return;

// server change event
if ((eventKind & ServerEvent.STATE_CHANGE) == 0)
return;

int state = event.getState();

if (state == IServer.STATE_STOPPING || state == IServer.STATE_STOPPED) {
disconnect();
notifyRefresh();
} else if (state == IServer.STATE_STARTED && TeiidServerAdapterUtil.isJBossServerConnected(event.getServer())) {

// Ask the jboss server what port we are on as it may
// still be set to the default port and this may be different
// in the jboss server.
String port = TeiidServerAdapterUtil.getJdbcPort(parentServer);
teiidJdbcInfo.setPort(port);

try {
getAdmin();
} catch (Exception ex) {
Util.log(ex);
} finally {
notifyRefresh();
}
}
}
};
/**
* Internal flag to ensure {@link #notifyRefresh()} does not
* send any signals to listeners. Should always be called in pairs,
* ie. turn off -> do work -> turn on
*/
private boolean notifyListeners = true;

// ===========================================================================================================================
// Constructors
Expand Down Expand Up @@ -170,8 +135,6 @@ public TeiidServer( String host,

if (parentServer.getServerState() != IServer.STATE_STARTED)
disconnect();

parentServer.addServerListener(serverListener);
}

// ===========================================================================================================================
Expand Down Expand Up @@ -234,6 +197,11 @@ public boolean equals(Object obj) {
return true;
}

/**
* Connect to this {@link TeiidServer}
*
* @throws Exception
*/
public ExecutionAdmin getAdmin() throws Exception {
if (! isParentConnected()) {
throw new Exception(DqpPlugin.Util.getString("jbossServerNotStartedMessage")); //$NON-NLS-1$
Expand All @@ -248,10 +216,37 @@ public ExecutionAdmin getAdmin() throws Exception {
this,
this.eventManager);
this.admin.load();
notifyRefresh();
}

return this.admin;
}

/**
* Disconnect then connect to this server. This is preferable to
* calling {@link #disconnect()} and {@link #connect()} separately
* since it only notifies at the end of the reconnection.
*/
public void reconnect() {
try {
// Call disconnect() first to clear out Server & admin caches
notifyListeners = false;
disconnect();
notifyListeners = true;

if (isParentConnected()) {
// Refresh is implied in the getting of the admin object since it will
// automatically load and refresh.
getAdmin();
}

setConnectionError(null);
} catch (Exception e) {
DqpPlugin.Util.log(e);
String msg = DqpPlugin.Util.getString("serverReconnectErrorMsg", this); //$NON-NLS-1$
setConnectionError(msg);
}
}

public TeiidAdminInfo getTeiidAdminInfo() {
return teiidAdminInfo;
Expand Down Expand Up @@ -380,6 +375,9 @@ public IStatus ping() {
}

public void notifyRefresh() {
if (! notifyListeners)
return;

if (this.admin != null) {
this.admin.getEventManager().notifyListeners(ExecutionConfigurationEvent.createServerRefreshEvent(this));
} else {
Expand Down Expand Up @@ -512,4 +510,4 @@ public String toString() {

return txt;
}
}
}

0 comments on commit ee1c4ff

Please sign in to comment.