gatein SVN: r609 - portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/webui/portal.
by do-not-reply@jboss.org
Author: hoang_to
Date: 2009-11-16 06:10:22 -0500 (Mon, 16 Nov 2009)
New Revision: 609
Modified:
portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/webui/portal/UIPortalComposer.java
Log:
GTNPORTAL-99:Remove permission setting tab while edit layout for dashboard
Modified: portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/webui/portal/UIPortalComposer.java
===================================================================
--- portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/webui/portal/UIPortalComposer.java 2009-11-16 10:20:11 UTC (rev 608)
+++ portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/webui/portal/UIPortalComposer.java 2009-11-16 11:10:22 UTC (rev 609)
@@ -280,7 +280,10 @@
UIMaskWorkspace uiMaskWS = uiApp.getChildById(UIPortalApplication.UI_MASK_WS_ID);
UIPortalForm portalForm = uiMaskWS.createUIComponent(UIPortalForm.class, null, "UIPortalForm");
- portalForm.setPortalOwner(((PortalRequestContext)WebuiRequestContext.getCurrentInstance()).getPortalOwner());
+ portalForm.setPortalOwner(uiPortal.getOwner());
+ if(PortalConfig.USER_TYPE.equals(uiPortal.getOwnerType())){
+ portalForm.removeChildById("PermissionSetting");
+ }
uiMaskWS.setWindowSize(700, -1);
event.getRequestContext().addUIComponentToUpdateByAjax(uiMaskWS);
}
15 years, 1 month
gatein SVN: r608 - portal/trunk/portlet/exoadmin/src/main/java/org/exoplatform/applicationregistry/webui/component.
by do-not-reply@jboss.org
Author: tan_pham_dinh
Date: 2009-11-16 05:20:11 -0500 (Mon, 16 Nov 2009)
New Revision: 608
Modified:
portal/trunk/portlet/exoadmin/src/main/java/org/exoplatform/applicationregistry/webui/component/UIGadgetEditor.java
Log:
GTNPORTAL-67: Change message when invalid with GadgetSpecValidator in UIGadgetEditor
Modified: portal/trunk/portlet/exoadmin/src/main/java/org/exoplatform/applicationregistry/webui/component/UIGadgetEditor.java
===================================================================
--- portal/trunk/portlet/exoadmin/src/main/java/org/exoplatform/applicationregistry/webui/component/UIGadgetEditor.java 2009-11-16 09:57:14 UTC (rev 607)
+++ portal/trunk/portlet/exoadmin/src/main/java/org/exoplatform/applicationregistry/webui/component/UIGadgetEditor.java 2009-11-16 10:20:11 UTC (rev 608)
@@ -22,7 +22,6 @@
import org.apache.commons.lang.StringEscapeUtils;
import org.apache.shindig.common.uri.Uri;
import org.apache.shindig.gadgets.spec.GadgetSpec;
-import org.apache.shindig.gadgets.spec.SpecParserException;
import org.exoplatform.application.gadget.Gadget;
import org.exoplatform.application.gadget.GadgetRegistryService;
import org.exoplatform.application.gadget.Source;
@@ -205,7 +204,7 @@
{
new GadgetSpec(Uri.parse("http://exoplatform.org"), (String)uiInput.getValue());
}
- catch (SpecParserException se)
+ catch (Exception se)
{
throw new MessageException(new ApplicationMessage("UIGadgetEditor.msg.invalidSpec", null,
ApplicationMessage.WARNING));
15 years, 1 month
gatein SVN: r607 - portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/webui/portal.
by do-not-reply@jboss.org
Author: hoang_to
Date: 2009-11-16 04:57:14 -0500 (Mon, 16 Nov 2009)
New Revision: 607
Modified:
portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/webui/portal/UIPortalComponentActionListener.java
Log:
GTNPORTAL-83: Remove redundant Java code
Modified: portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/webui/portal/UIPortalComponentActionListener.java
===================================================================
--- portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/webui/portal/UIPortalComponentActionListener.java 2009-11-16 08:44:26 UTC (rev 606)
+++ portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/webui/portal/UIPortalComponentActionListener.java 2009-11-16 09:57:14 UTC (rev 607)
@@ -126,7 +126,6 @@
Util.getUIPortalApplication().addMessage(
new ApplicationMessage("UIPortalApplication.msg.deletePageBody", new Object[]{},
ApplicationMessage.WARNING));
- event.getRequestContext().addUIComponentToUpdateByAjax(Util.getUIPortalApplication().getUIPopupMessages());
return;
}
15 years, 1 month
gatein SVN: r606 - portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/application.
by do-not-reply@jboss.org
Author: julien_viet
Date: 2009-11-16 03:44:26 -0500 (Mon, 16 Nov 2009)
New Revision: 606
Modified:
portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/application/PortalStatisticService.java
Log:
fix getPortalList in portal statistic service
Modified: portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/application/PortalStatisticService.java
===================================================================
--- portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/application/PortalStatisticService.java 2009-11-16 08:38:47 UTC (rev 605)
+++ portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/application/PortalStatisticService.java 2009-11-16 08:44:26 UTC (rev 606)
@@ -24,9 +24,10 @@
import org.exoplatform.management.annotations.ManagedName;
import org.exoplatform.management.jmx.annotations.NameTemplate;
import org.exoplatform.management.jmx.annotations.Property;
-import org.exoplatform.services.jcr.ext.registry.RegistryService;
+import org.exoplatform.portal.config.UserPortalConfigService;
import org.picocontainer.Startable;
+import java.util.List;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
@@ -43,11 +44,11 @@
private ConcurrentMap<String, PortalStatistic> apps = new ConcurrentHashMap<String, PortalStatistic>();
- private RegistryService regService_;
+ private UserPortalConfigService configService;
- public PortalStatisticService(RegistryService res)
+ public PortalStatisticService(UserPortalConfigService res)
{
- regService_ = res;
+ configService = res;
}
@@ -58,36 +59,16 @@
@ManagedDescription("The list of identifier of the known portals")
public String[] getPortalList()
{
- /*
- ArrayList<String> list = new ArrayList<String>();
- SessionProvider sessionProvider = SessionProvider.createSystemProvider();
- StringBuilder builder = new StringBuilder("select * from " + "exo:registryEntry");
-
- try {
- String registryNodePath = regService_.getRegistry(sessionProvider).getNode().getPath();
- Session session = regService_.getRegistry(sessionProvider).getNode().getSession();
- generateLikeScript(builder, "jcr:path", registryNodePath + "/%");
- generateLikeScript(builder, "exo:dataType", "PortalConfig");
- QueryManager queryManager = session.getWorkspace().getQueryManager();
- javax.jcr.query.Query query = queryManager.createQuery(builder.toString(), "sql");
- QueryResult result = query.execute();
-
- NodeIterator itr = result.getNodes();
- while (itr.hasNext()) {
- Node node = itr.nextNode();
- String entryPath = node.getPath().substring(registryNodePath.length() + 1);
- RegistryEntry entry = regService_.getEntry(sessionProvider, entryPath);
- list.add(mapper_.fromDocument(entry.getDocument(), PortalConfig.class).getName());
- }
- Collections.sort(list);
- } catch (Exception ex) {
- ex.printStackTrace();
- } finally {
- sessionProvider.close();
- }
- return list.toArray(new String[list.size()]);
- */
- throw new UnsupportedOperationException("Todo with MOP");
+ try
+ {
+ List<String> names = configService.getAllPortalNames();
+ return names.toArray(new String[names.size()]);
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ return new String[0];
+ }
}
/*
@@ -158,19 +139,6 @@
return getPortalStatistic(id).viewCount();
}
- private void generateLikeScript(StringBuilder sql, String name, String value)
- {
- if (value == null || value.length() < 1)
- return;
- if (sql.indexOf(" where") < 0)
- sql.append(" where ");
- else
- sql.append(" and ");
- value = value.replace('*', '%');
- value = value.replace('?', '_');
- sql.append(name).append(" like '").append(value).append("'");
- }
-
private double toSeconds(double value)
{
return value == -1 ? -1 : value / 1000D;
15 years, 1 month
gatein SVN: r605 - in portal/trunk/web: portal/src/main/webapp/WEB-INF/classes/locale/portal and 1 other directories.
by do-not-reply@jboss.org
Author: tan_pham_dinh
Date: 2009-11-16 03:38:47 -0500 (Mon, 16 Nov 2009)
New Revision: 605
Modified:
portal/trunk/web/eXoResources/src/main/webapp/javascript/eXo/gadget/UIGadget.js
portal/trunk/web/portal/src/main/webapp/WEB-INF/classes/locale/portal/webui_ar.xml
portal/trunk/web/portal/src/main/webapp/WEB-INF/classes/locale/portal/webui_en.properties
portal/trunk/web/portal/src/main/webapp/WEB-INF/classes/locale/portal/webui_es.properties
portal/trunk/web/portal/src/main/webapp/WEB-INF/classes/locale/portal/webui_fr.properties
portal/trunk/web/portal/src/main/webapp/WEB-INF/classes/locale/portal/webui_ru.properties
portal/trunk/web/portal/src/main/webapp/WEB-INF/classes/locale/portal/webui_uk.properties
portal/trunk/web/portal/src/main/webapp/WEB-INF/classes/locale/portal/webui_vi.properties
portal/trunk/web/portal/src/main/webapp/groovy/portal/webui/application/UIGadget.gtmpl
Log:
GTNPORTAL-93: Add tootltip to control buttons of UIGadget and localize them
Modified: portal/trunk/web/eXoResources/src/main/webapp/javascript/eXo/gadget/UIGadget.js
===================================================================
--- portal/trunk/web/eXoResources/src/main/webapp/javascript/eXo/gadget/UIGadget.js 2009-11-16 07:40:13 UTC (rev 604)
+++ portal/trunk/web/eXoResources/src/main/webapp/javascript/eXo/gadget/UIGadget.js 2009-11-16 08:38:47 UTC (rev 605)
@@ -197,10 +197,12 @@
minimized = true;
gadgetApp.style.display = "none";
DOMUtil.replaceClass(selectedElement, "MinimizeGadget", "RestoreGadget");
+ selectedElement.title = selectedElement.getAttribute("unminiTitle");
} else {
minimized = false;
gadgetApp.style.display = "block";
DOMUtil.replaceClass(selectedElement, "RestoreGadget", "MinimizeGadget");
+ selectedElement.title = selectedElement.getAttribute("miniTitle");
}
var compId = portletFrag.parentNode.id;
Modified: portal/trunk/web/portal/src/main/webapp/WEB-INF/classes/locale/portal/webui_ar.xml
===================================================================
--- portal/trunk/web/portal/src/main/webapp/WEB-INF/classes/locale/portal/webui_ar.xml 2009-11-16 07:40:13 UTC (rev 604)
+++ portal/trunk/web/portal/src/main/webapp/WEB-INF/classes/locale/portal/webui_ar.xml 2009-11-16 08:38:47 UTC (rev 605)
@@ -2279,5 +2279,19 @@
<Group>Group</Group>
</header>
</UIAddGroupNavigation>
-</bundle>
-
+ <!--
+ ############################################################################
+ # org.exoplatform.portal.webui.application.UIGadget #
+ ############################################################################
+ -->
+ <UIGadget>
+ <tooltip>
+ <Minimize>تصغير</Minimize>
+ <Unminimize>استعادة</Unminimize>
+ <Maximize>تكبير</Maximize>
+ <Unmaximize>استعادة بانخفاض</Unmaximize>
+ <editGadget>Edit Gadget</editGadget>
+ <deleteGadget>Delete this gadget</deleteGadget>
+ </tooltip>
+ </UIGadget>
+</bundle>
\ No newline at end of file
Modified: portal/trunk/web/portal/src/main/webapp/WEB-INF/classes/locale/portal/webui_en.properties
===================================================================
--- portal/trunk/web/portal/src/main/webapp/WEB-INF/classes/locale/portal/webui_en.properties 2009-11-16 07:40:13 UTC (rev 604)
+++ portal/trunk/web/portal/src/main/webapp/WEB-INF/classes/locale/portal/webui_en.properties 2009-11-16 08:38:47 UTC (rev 605)
@@ -1363,3 +1363,14 @@
UIAddGroupNavigation.Action.Add=Add Navigation
UIAddGroupNavigation.Label.NoPermission=This user doesn't have permisson to add navigation
UIAddGroupNavigation.header.Group=Group
+
+ ############################################################################
+ # org.exoplatform.portal.webui.application.UIGadget #
+ ############################################################################
+
+UIGadget.tooltip.Minimize=Minimize
+UIGadget.tooltip.Unminimize=Restore
+UIGadget.tooltip.Maximize=Maximize
+UIGadget.tooltip.Unmaximize=Restore Down
+UIGadget.tooltip.editGadget=Edit Gadget
+UIGadget.tooltip.deleteGadget=Delete Gadget
\ No newline at end of file
Modified: portal/trunk/web/portal/src/main/webapp/WEB-INF/classes/locale/portal/webui_es.properties
===================================================================
--- portal/trunk/web/portal/src/main/webapp/WEB-INF/classes/locale/portal/webui_es.properties 2009-11-16 07:40:13 UTC (rev 604)
+++ portal/trunk/web/portal/src/main/webapp/WEB-INF/classes/locale/portal/webui_es.properties 2009-11-16 08:38:47 UTC (rev 605)
@@ -1363,3 +1363,14 @@
UIAddGroupNavigation.Action.Add=A\u00f1adir Navegaci\u00f3n
UIAddGroupNavigation.Label.NoPermission=Este usuario no tiene permisos para a\u00f1adir una Navegaci\u00f3n
UIAddGroupNavigation.header.Group=Grupo
+
+ ############################################################################
+ # org.exoplatform.portal.webui.application.UIGadget #
+ ############################################################################
+
+UIGadget.tooltip.Minimize=Minimizar
+UIGadget.tooltip.Unminimize=Restaurar
+UIGadget.tooltip.Maximize=Maximizar
+UIGadget.tooltip.Unmaximize=Restaurar
+UIGadget.tooltip.editGadget=Editar Gadget
+UIGadget.tooltip.deleteGadget=Borrar Gadget
Modified: portal/trunk/web/portal/src/main/webapp/WEB-INF/classes/locale/portal/webui_fr.properties
===================================================================
--- portal/trunk/web/portal/src/main/webapp/WEB-INF/classes/locale/portal/webui_fr.properties 2009-11-16 07:40:13 UTC (rev 604)
+++ portal/trunk/web/portal/src/main/webapp/WEB-INF/classes/locale/portal/webui_fr.properties 2009-11-16 08:38:47 UTC (rev 605)
@@ -1331,3 +1331,14 @@
UIAddGroupNavigation.Action.Add=Add Navigation
UIAddGroupNavigation.Label.NoPermission=This user doesn't have permisson to add navigation
UIAddGroupNavigation.header.Group=Group
+
+ ############################################################################
+ # org.exoplatform.portal.webui.application.UIGadget #
+ ############################################################################
+
+UIGadget.tooltip.Minimize=Réduire
+UIGadget.tooltip.Unminimize=Restaurer
+UIGadget.tooltip.Maximize=Agrandir
+UIGadget.tooltip.Unmaximize=Restaurer Again
+UIGadget.tooltip.editGadget=Editer la Gadget
+UIGadget.tooltip.deleteGadget=Supprimer la Gadget
Modified: portal/trunk/web/portal/src/main/webapp/WEB-INF/classes/locale/portal/webui_ru.properties
===================================================================
--- portal/trunk/web/portal/src/main/webapp/WEB-INF/classes/locale/portal/webui_ru.properties 2009-11-16 07:40:13 UTC (rev 604)
+++ portal/trunk/web/portal/src/main/webapp/WEB-INF/classes/locale/portal/webui_ru.properties 2009-11-16 08:38:47 UTC (rev 605)
@@ -1354,3 +1354,14 @@
UIAddGroupNavigation.Action.Add=Добавить навигацию
UIAddGroupNavigation.Label.NoPermission=This user doesn't have permisson to add navigation
UIAddGroupNavigation.header.Group=Группа
+
+ ############################################################################
+ # org.exoplatform.portal.webui.application.UIGadget #
+ ############################################################################
+
+UIGadget.tooltip.Minimize=Свернуть
+UIGadget.tooltip.Unminimize=Восстановить
+UIGadget.tooltip.Maximize=Развернуть
+UIGadget.tooltip.Unmaximize=Восстановить
+UIGadget.tooltip.editGadget=Изменить гаджеты
+UIGadget.tooltip.deleteGadget=Удалить гаджеты
Modified: portal/trunk/web/portal/src/main/webapp/WEB-INF/classes/locale/portal/webui_uk.properties
===================================================================
--- portal/trunk/web/portal/src/main/webapp/WEB-INF/classes/locale/portal/webui_uk.properties 2009-11-16 07:40:13 UTC (rev 604)
+++ portal/trunk/web/portal/src/main/webapp/WEB-INF/classes/locale/portal/webui_uk.properties 2009-11-16 08:38:47 UTC (rev 605)
@@ -1344,3 +1344,14 @@
UIAddGroupNavigation.Action.Add=Додати навігацію
UIAddGroupNavigation.Label.NoPermission=This user doesn't have permisson to add navigation
+
+ ############################################################################
+ # org.exoplatform.portal.webui.application.UIGadget #
+ ############################################################################
+
+UIGadget.tooltip.Minimize=Мінімізувати
+UIGadget.tooltip.Unminimize=Відновити
+UIGadget.tooltip.Maximize=Максимізувати
+UIGadget.tooltip.Unmaximize=Відновити
+UIGadget.tooltip.editGadget=Редагувати Ґаджети
+UIGadget.tooltip.deleteGadget=Видалити Ґаджети
Modified: portal/trunk/web/portal/src/main/webapp/WEB-INF/classes/locale/portal/webui_vi.properties
===================================================================
--- portal/trunk/web/portal/src/main/webapp/WEB-INF/classes/locale/portal/webui_vi.properties 2009-11-16 07:40:13 UTC (rev 604)
+++ portal/trunk/web/portal/src/main/webapp/WEB-INF/classes/locale/portal/webui_vi.properties 2009-11-16 08:38:47 UTC (rev 605)
@@ -1330,3 +1330,14 @@
UIAddGroupNavigation.Action.Add=Add Navigation
UIAddGroupNavigation.header.Group=Group
UIAddGroupNavigation.Label.NoPermission=This user doesn't have permisson to add navigation
+
+ ############################################################################
+ # org.exoplatform.portal.webui.application.UIGadget #
+ ############################################################################
+
+UIGadget.tooltip.Minimize=Thu nhỏ cửa sổ
+UIGadget.tooltip.Unminimize=Khôi phục
+UIGadget.tooltip.Maximize=Phóng lớn cửa sổ
+UIGadget.tooltip.Unmaximize=Thu nhỏ cửa sổ
+UIGadget.tooltip.editGadget=Sửa Gadget
+UIGadget.tooltip.deleteGadget=Xóa Gadget
Modified: portal/trunk/web/portal/src/main/webapp/groovy/portal/webui/application/UIGadget.gtmpl
===================================================================
--- portal/trunk/web/portal/src/main/webapp/groovy/portal/webui/application/UIGadget.gtmpl 2009-11-16 07:40:13 UTC (rev 604)
+++ portal/trunk/web/portal/src/main/webapp/groovy/portal/webui/application/UIGadget.gtmpl 2009-11-16 08:38:47 UTC (rev 605)
@@ -19,7 +19,13 @@
jsmanager.importJavascript("eXo.gadget.UIGadget");
rcontext.getJavascriptManager().addCustomizedOnLoadScript("eXo.gadget.UIGadget.confirmDeleteGadget = '" + _ctx.appRes("UIGadgetContainerManagement.confirm.DeleteGadget") + "';");
jsmanager.addCustomizedOnLoadScript("eXo.gadget.UIGadget.createGadget('$url','content-$id', $metadata, $userPref, '$view', '$hostName', " + (isDev ? 1 : 0)
- + ", " + (isDebug ? 1 : 0) + ", " + (noCache ? 1 : 0) + ");")
+ + ", " + (isDebug ? 1 : 0) + ", " + (noCache ? 1 : 0) + ");");
+
+ boolean isMini = Boolean.parseBoolean(uicomponent.getProperties().get("minimized"));
+ String miniTitle = _ctx.appRes("UIGadget.tooltip.Minimize");
+ String unminiTitle = _ctx.appRes("UIGadget.tooltip.Unminimize");
+ String maxiTitle = _ctx.appRes("UIGadget.tooltip.Maximize");
+ String unmaxiTitle = _ctx.appRes("UIGadget.tooltip.Unmaximize");
%>
<div class="UIGadget" id="$id" style="left: $posX; top: $posY; z-Index: $zIndex; width: 100%" >
<div class="GadgetControl" style="visibility: visible;">
@@ -27,11 +33,13 @@
<div class="RightControlBar">
<div class="CenterControlBar">
<div class="GadgetTitle" style="display: none"><%= uicomponent.getApplicationName() %></div>
- <div class="CloseGadget IconControl" onclick="eXo.gadget.UIGadget.deleteGadget(this)" onmousedown="event.cancelBubble=true;"><span></span></div>
- <div class="<%=Boolean.parseBoolean(uicomponent.getProperties().get("minimized")) ? "RestoreGadget": "MinimizeGadget";%> MinimizeAction IconControl"
- onclick="eXo.gadget.UIGadget.minimizeGadget(this)" onmousedown="event.cancelBubble=true;" style="display:none;"><span></span></div>
- <div class="EditGadget IconControl" onclick="eXo.gadget.UIGadget.editGadget('$id')" onmousedown="event.cancelBubble=true;"><span></span></div>
- <div class="MaximizeGadget IconControl" onclick="eXo.gadget.UIGadget.maximizeGadget(this)" onmousedown="event.cancelBubble=true;" title="Maximize"><span></span></div>
+ <div class="CloseGadget IconControl" onclick="eXo.gadget.UIGadget.deleteGadget(this)" onmousedown="event.cancelBubble=true;" title="<%=_ctx.appRes("UIGadget.tooltip.deleteGadget")%>"><span></span></div>
+ <div class="<%=isMini ? "RestoreGadget": "MinimizeGadget";%> MinimizeAction IconControl"
+ onclick="eXo.gadget.UIGadget.minimizeGadget(this)" onmousedown="event.cancelBubble=true;" style="display:none;"
+ title="<%=isMini ? unminiTitle : miniTitle%>" miniTitle="$miniTitle" unminiTitle="$unminiTitle"><span></span></div>
+ <div class="EditGadget IconControl" onclick="eXo.gadget.UIGadget.editGadget('$id')" onmousedown="event.cancelBubble=true;" title="<%=_ctx.appRes("UIGadget.tooltip.editGadget")%>"><span></span></div>
+ <div class="MaximizeGadget IconControl" onclick="eXo.gadget.UIGadget.maximizeGadget(this)" onmousedown="event.cancelBubble=true;"
+ title="<%=view.equals(uicomponent.HOME_VIEW) ? maxiTitle : unmaxiTitle%>"><span></span></div>
<div class="GadgetDragHandleArea"><span></span></div>
<div style="clear: both;"><span></span></div>
</div>
15 years, 1 month
gatein SVN: r604 - in components/common/trunk/common/src/test/java/org/gatein/common: concurrent and 1 other directory.
by do-not-reply@jboss.org
Author: julien_viet
Date: 2009-11-16 02:40:13 -0500 (Mon, 16 Nov 2009)
New Revision: 604
Added:
components/common/trunk/common/src/test/java/org/gatein/common/concurrent/ValveTestCase.java
Removed:
components/common/trunk/common/src/test/java/org/gatein/common/ValveTestCase.java
Log:
move valve unit test to more correct package
Deleted: components/common/trunk/common/src/test/java/org/gatein/common/ValveTestCase.java
===================================================================
--- components/common/trunk/common/src/test/java/org/gatein/common/ValveTestCase.java 2009-11-16 07:39:24 UTC (rev 603)
+++ components/common/trunk/common/src/test/java/org/gatein/common/ValveTestCase.java 2009-11-16 07:40:13 UTC (rev 604)
@@ -1,197 +0,0 @@
-/******************************************************************************
- * JBoss, a division of Red Hat *
- * Copyright 2009, Red Hat Middleware, LLC, and individual *
- * contributors as indicated by the @authors tag. See the *
- * copyright.txt in the distribution for a full listing of *
- * individual contributors. *
- * *
- * This is free software; you can redistribute it and/or modify it *
- * under the terms of the GNU Lesser General Public License as *
- * published by the Free Software Foundation; either version 2.1 of *
- * the License, or (at your option) any later version. *
- * *
- * This software is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
- * Lesser General Public License for more details. *
- * *
- * You should have received a copy of the GNU Lesser General Public *
- * License along with this software; if not, write to the Free *
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org. *
- ******************************************************************************/
-package org.gatein.common;
-
-import java.io.PrintStream;
-import java.util.concurrent.CyclicBarrier;
-import java.util.concurrent.BrokenBarrierException;
-
-import junit.framework.TestCase;
-
-import org.gatein.common.concurrent.Valve;
-
-/**
- * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
- * @version $Revision: 5451 $
- */
-public class ValveTestCase extends TestCase
-{
-
- public ValveTestCase(String key)
- {
- super(key);
- }
-
- public static final PrintStream out = System.out;
-
- public void testTransitions()
- {
- Valve valve = new Valve();
- assertEquals(Valve.CLOSED, valve.getState());
- assertFalse(valve.beforeInvocation());
- try
- {
- valve.closing(10);
- fail("IllegalStateException expected");
- }
- catch (IllegalStateException expected)
- {
- }
- try
- {
- valve.closing();
- fail("IllegalStateException expected");
- }
- catch (IllegalStateException expected)
- {
- }
- try
- {
- valve.closed();
- fail("IllegalStateException expected");
- }
- catch (IllegalStateException expected)
- {
- }
-
- // Open the valve
- valve.open();
- try
- {
- assertTrue(valve.beforeInvocation());
- }
- finally
- {
- valve.afterInvocation();
- }
- try
- {
- valve.open();
- fail("IllegalStateException expected");
- }
- catch (IllegalStateException e)
- {
- }
- try
- {
- valve.closed();
- fail("IllegalStateException expected");
- }
- catch (IllegalStateException e)
- {
- }
-
-
- // Closing the valve
- valve.closing();
- assertEquals(Valve.CLOSING, valve.getState());
- assertFalse(valve.beforeInvocation());
- try
- {
- valve.open();
- fail("IllegalStateException expected");
- }
- catch (IllegalStateException e)
- {
- }
- valve.closing();
-
- // Close the valve
- valve.closed();
- assertEquals(Valve.CLOSED, valve.getState());
- }
-
- public void testTimeOut() throws Exception
- {
- final Valve valve = new Valve();
- final CyclicBarrier barrier = new CyclicBarrier(2);
-
- Thread thread = new Thread()
- {
- public void run()
- {
- try
- {
- assertTrue(valve.beforeInvocation());
-
- // The valve is enterred
- barrier.await();
-
- // Wait
- barrier.await();
- }
- catch (BrokenBarrierException e)
- {
- fail("" + e.getMessage());
- }
- catch (InterruptedException ignore)
- {
- }
- finally
- {
- valve.afterInvocation();
- try
- {
- // Tell the other thread we have finished
- barrier.await();
- }
- catch (BrokenBarrierException e)
- {
- fail("" + e.getMessage());
- }
- catch (InterruptedException ignore)
- {
- }
- }
- }
- };
-
- // Open valve and start thread
- valve.open();
- thread.start();
-
- // Wait until the thread called beforeInvocation
- barrier.await();
-
- // Attemtp to close
- assertFalse(valve.closing(100));
-
- // Check it is in closing state
- assertEquals(Valve.CLOSING, valve.getState());
-
- // Ask the invoker thread to finish
- barrier.await();
-
- // Wait until invocation is finished
- barrier.await();
-
- // Close, no thread are inside
- valve.closing();
- assertEquals(Valve.CLOSING, valve.getState());
-
- //
- valve.closed();
- assertEquals(Valve.CLOSED, valve.getState());
- }
-
-}
Copied: components/common/trunk/common/src/test/java/org/gatein/common/concurrent/ValveTestCase.java (from rev 597, components/common/trunk/common/src/test/java/org/gatein/common/ValveTestCase.java)
===================================================================
--- components/common/trunk/common/src/test/java/org/gatein/common/concurrent/ValveTestCase.java (rev 0)
+++ components/common/trunk/common/src/test/java/org/gatein/common/concurrent/ValveTestCase.java 2009-11-16 07:40:13 UTC (rev 604)
@@ -0,0 +1,197 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2009, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org. *
+ ******************************************************************************/
+package org.gatein.common.concurrent;
+
+import java.io.PrintStream;
+import java.util.concurrent.CyclicBarrier;
+import java.util.concurrent.BrokenBarrierException;
+
+import junit.framework.TestCase;
+
+import org.gatein.common.concurrent.Valve;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 5451 $
+ */
+public class ValveTestCase extends TestCase
+{
+
+ public ValveTestCase(String key)
+ {
+ super(key);
+ }
+
+ public static final PrintStream out = System.out;
+
+ public void testTransitions()
+ {
+ Valve valve = new Valve();
+ assertEquals(Valve.CLOSED, valve.getState());
+ assertFalse(valve.beforeInvocation());
+ try
+ {
+ valve.closing(10);
+ fail("IllegalStateException expected");
+ }
+ catch (IllegalStateException expected)
+ {
+ }
+ try
+ {
+ valve.closing();
+ fail("IllegalStateException expected");
+ }
+ catch (IllegalStateException expected)
+ {
+ }
+ try
+ {
+ valve.closed();
+ fail("IllegalStateException expected");
+ }
+ catch (IllegalStateException expected)
+ {
+ }
+
+ // Open the valve
+ valve.open();
+ try
+ {
+ assertTrue(valve.beforeInvocation());
+ }
+ finally
+ {
+ valve.afterInvocation();
+ }
+ try
+ {
+ valve.open();
+ fail("IllegalStateException expected");
+ }
+ catch (IllegalStateException e)
+ {
+ }
+ try
+ {
+ valve.closed();
+ fail("IllegalStateException expected");
+ }
+ catch (IllegalStateException e)
+ {
+ }
+
+
+ // Closing the valve
+ valve.closing();
+ assertEquals(Valve.CLOSING, valve.getState());
+ assertFalse(valve.beforeInvocation());
+ try
+ {
+ valve.open();
+ fail("IllegalStateException expected");
+ }
+ catch (IllegalStateException e)
+ {
+ }
+ valve.closing();
+
+ // Close the valve
+ valve.closed();
+ assertEquals(Valve.CLOSED, valve.getState());
+ }
+
+ public void testTimeOut() throws Exception
+ {
+ final Valve valve = new Valve();
+ final CyclicBarrier barrier = new CyclicBarrier(2);
+
+ Thread thread = new Thread()
+ {
+ public void run()
+ {
+ try
+ {
+ assertTrue(valve.beforeInvocation());
+
+ // The valve is enterred
+ barrier.await();
+
+ // Wait
+ barrier.await();
+ }
+ catch (BrokenBarrierException e)
+ {
+ fail("" + e.getMessage());
+ }
+ catch (InterruptedException ignore)
+ {
+ }
+ finally
+ {
+ valve.afterInvocation();
+ try
+ {
+ // Tell the other thread we have finished
+ barrier.await();
+ }
+ catch (BrokenBarrierException e)
+ {
+ fail("" + e.getMessage());
+ }
+ catch (InterruptedException ignore)
+ {
+ }
+ }
+ }
+ };
+
+ // Open valve and start thread
+ valve.open();
+ thread.start();
+
+ // Wait until the thread called beforeInvocation
+ barrier.await();
+
+ // Attemtp to close
+ assertFalse(valve.closing(100));
+
+ // Check it is in closing state
+ assertEquals(Valve.CLOSING, valve.getState());
+
+ // Ask the invoker thread to finish
+ barrier.await();
+
+ // Wait until invocation is finished
+ barrier.await();
+
+ // Close, no thread are inside
+ valve.closing();
+ assertEquals(Valve.CLOSING, valve.getState());
+
+ //
+ valve.closed();
+ assertEquals(Valve.CLOSED, valve.getState());
+ }
+
+}
15 years, 1 month
gatein SVN: r603 - in components/common/trunk/common/src: test/java/org/gatein/common and 1 other directories.
by do-not-reply@jboss.org
Author: julien_viet
Date: 2009-11-16 02:39:24 -0500 (Mon, 16 Nov 2009)
New Revision: 603
Added:
components/common/trunk/common/src/main/java/org/gatein/common/concurrent/AtomicPositiveLong.java
components/common/trunk/common/src/main/java/org/gatein/common/concurrent/BoundedBuffer.java
components/common/trunk/common/src/main/java/org/gatein/common/concurrent/LongSampler.java
components/common/trunk/common/src/main/java/org/gatein/common/concurrent/ObjectRef.java
components/common/trunk/common/src/test/java/org/gatein/common/concurrent/
components/common/trunk/common/src/test/java/org/gatein/common/concurrent/AtomicPositiveLongTestCase.java
components/common/trunk/common/src/test/java/org/gatein/common/concurrent/BoundedBufferTestCase.java
components/common/trunk/common/src/test/java/org/gatein/common/concurrent/LongSamplerTestCase.java
Log:
GTNCOMMON-6 : copied the concurrent classes from GateIn portal to GateIn common
Added: components/common/trunk/common/src/main/java/org/gatein/common/concurrent/AtomicPositiveLong.java
===================================================================
--- components/common/trunk/common/src/main/java/org/gatein/common/concurrent/AtomicPositiveLong.java (rev 0)
+++ components/common/trunk/common/src/main/java/org/gatein/common/concurrent/AtomicPositiveLong.java 2009-11-16 07:39:24 UTC (rev 603)
@@ -0,0 +1,110 @@
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.gatein.common.concurrent;
+
+import java.util.concurrent.atomic.AtomicLong;
+
+/**
+ * Extends the @link{AtomicLong} to contain positive longs. If no initial value
+ * is provided when the object is created then the value is -1 to indicate that
+ * it is not yet initialized.
+ *
+ * @author <a href="mailto:julien.viet@exoplatform.com">Julien Viet</a>
+ * @version $Revision$
+ */
+public class AtomicPositiveLong extends AtomicLong
+{
+
+ /**
+ * Create an atomic positive long with an inital provided value.
+ *
+ * @param initialValue the initial value
+ * @throws IllegalArgumentException if the value is negative
+ */
+ public AtomicPositiveLong(long initialValue) throws IllegalArgumentException
+ {
+ super(initialValue);
+
+ //
+ if (initialValue == -1)
+ {
+ throw new IllegalArgumentException();
+ }
+ }
+
+ /**
+ * Create an atomic positive long with no initial value.
+ */
+ public AtomicPositiveLong()
+ {
+ super(-1);
+ }
+
+ /**
+ * Update the value if the new value is greater than the previous one or if the long is not initialized.
+ *
+ * @param newValue the new value
+ * @throws IllegalArgumentException if the new value is negative
+ */
+ public void setIfGreater(long newValue) throws IllegalArgumentException
+ {
+ if (newValue < 0)
+ {
+ throw new IllegalArgumentException();
+ }
+ while (true)
+ {
+ long oldValue = get();
+ if (newValue > oldValue || oldValue == -1)
+ {
+ compareAndSet(oldValue, newValue);
+ }
+ else
+ {
+ break;
+ }
+ }
+ }
+
+ /**
+ * Update the value if the new value is lower than the previous one or if the long is not initialized.
+ *
+ * @param newValue the new value
+ * @throws IllegalArgumentException if the new value is negative
+ */
+ public void setIfLower(long newValue) throws IllegalArgumentException
+ {
+ if (newValue < 0)
+ {
+ throw new IllegalArgumentException();
+ }
+ while (true)
+ {
+ long oldValue = get();
+ if (newValue < oldValue || oldValue == -1)
+ {
+ compareAndSet(oldValue, newValue);
+ }
+ else
+ {
+ break;
+ }
+ }
+ }
+}
Added: components/common/trunk/common/src/main/java/org/gatein/common/concurrent/BoundedBuffer.java
===================================================================
--- components/common/trunk/common/src/main/java/org/gatein/common/concurrent/BoundedBuffer.java (rev 0)
+++ components/common/trunk/common/src/main/java/org/gatein/common/concurrent/BoundedBuffer.java 2009-11-16 07:39:24 UTC (rev 603)
@@ -0,0 +1,184 @@
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.gatein.common.concurrent;
+
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+import java.util.NoSuchElementException;
+
+/**
+ * <p>A thread safe bounded buffer.</p>
+ *
+ * <p>The idea of this class is that it retains only the last elements added
+ * to the buffer up to a determined size, but it is possible to make snapshot of the buffer elements and iterate
+ * over them with a neglectable impact on synchronization.</p>
+ *
+ * <p>It maintains a linked list. When a new element is added, the first element will have for
+ * successor that new element. If the number of elements is greater than the max size then the last element
+ * is discarded.</p>
+ *
+ * <p> When a snapshot for iteration is required, the class only needs to keep a reference to the last element of the list
+ * and keep also the actual size of the list. The copy is made in an atomic manner for consistency. Note that this class
+ * expose only a notion of iterator to its client instead of a notion of list as iterator have a notion of being short
+ * lived objects. Indeed keeping a reference on an iterator would create a memory leak and so this class must be used
+ * with caution.</p>
+ *
+ * @author <a href="mailto:julien.viet@exoplatform.com">Julien Viet</a>
+ * @version $Revision$
+ * @todo develop a non blocking implementation pretty much like the ConcurrentLinkedQueue does
+ * @todo although I don't think this class is a bottleneck as there is very short lived synchronization
+ * @todo and actually I don't know if it's feasible to have a non blocking impl due to the size value
+ *
+ */
+public class BoundedBuffer<T> implements Iterable<T>
+{
+
+ /** The max size. */
+ private final int maxSize;
+
+ /** The elder element. */
+ private ObjectRef<T> last;
+
+ /** The younger element. */
+ private ObjectRef<T> first;
+
+ /** The size, it is declared as volatile for the @link{getSize()} method. */
+ private volatile int size;
+
+ public BoundedBuffer(int maxSize)
+ {
+ if (maxSize < 1)
+ {
+ throw new IllegalArgumentException("Buffer size needs to be greater than zero");
+ }
+
+ //
+ this.maxSize = maxSize;
+ this.size = 0;
+ }
+
+ public int getMaxSize()
+ {
+ return maxSize;
+ }
+
+ public int getSize()
+ {
+ return size;
+ }
+
+ /**
+ * Add an element to the buffer.
+ *
+ * @param t the element to add
+ */
+ public void add(T t)
+ {
+ synchronized (this)
+ {
+ if (first == null)
+ {
+ first = new ObjectRef<T>(t);
+ last = first;
+ size = 1;
+ }
+ else
+ {
+ ObjectRef<T> tmp = first;
+ first = new ObjectRef<T>(t);
+ tmp.next.set(first);
+ if (size < maxSize)
+ {
+ size++;
+ }
+ else
+ {
+ last = last.next.get();
+ }
+ }
+ }
+ }
+
+ /**
+ * Make a snapshot of the buffer and iterate over the elements. It is important to not keep reference
+ * on an iterator returned by this method otherwise it could create a memory leak.
+ *
+ * @return an iterator over the elements
+ */
+ public Iterator<T> iterator()
+ {
+ if (size == 0)
+ {
+ List<T> empty = Collections.emptyList();
+ return empty.iterator();
+ }
+ else
+ {
+ // Get consistent state
+ final ObjectRef<T> lastSnapshot;
+ final int sizeSnapshot;
+ synchronized (this)
+ {
+ lastSnapshot = last;
+ sizeSnapshot = size;
+ }
+ return new BoundedIterator<T>(lastSnapshot, sizeSnapshot);
+ }
+ }
+
+ private static final class BoundedIterator<T> implements Iterator<T>
+ {
+
+ final int size;
+
+ ObjectRef<T> current;
+
+ int count = 0;
+
+ private BoundedIterator(ObjectRef<T> current, int size)
+ {
+ this.current = current;
+ this.size = size;
+ this.count = 0;
+ }
+
+ public boolean hasNext()
+ {
+ return count < size && current != null;
+ }
+
+ public T next()
+ {
+ if (!hasNext())
+ {
+ throw new NoSuchElementException();
+ }
+ T next = current.object;
+ current = current.next.get();
+ count++;
+ return next;
+ }
+
+ public void remove()
+ {
+ throw new UnsupportedOperationException();
+ }
+ }
+}
Added: components/common/trunk/common/src/main/java/org/gatein/common/concurrent/LongSampler.java
===================================================================
--- components/common/trunk/common/src/main/java/org/gatein/common/concurrent/LongSampler.java (rev 0)
+++ components/common/trunk/common/src/main/java/org/gatein/common/concurrent/LongSampler.java 2009-11-16 07:39:24 UTC (rev 603)
@@ -0,0 +1,71 @@
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.gatein.common.concurrent;
+
+/**
+ * An object that sample long values.
+ *
+ * @author <a href="mailto:julien.viet@exoplatform.com">Julien Viet</a>
+ * @version $Revision$
+ * @todo move to common utils
+ */
+public class LongSampler extends BoundedBuffer<Long>
+{
+
+ public LongSampler(int maxSize)
+ {
+ super(maxSize);
+ }
+
+ /**
+ * Returns the average value.
+ *
+ * @return the average
+ */
+ public double average()
+ {
+ long sumTime = 0;
+ int size = 0;
+ for (long value : this)
+ {
+ sumTime += value;
+ size++;
+ }
+ return size == 0 ? 0 : (double)sumTime / (double)size;
+ }
+
+ /**
+ * Returns the number of values which are greater or equals to the threshold value.
+ *
+ * @param threshold the threshold value
+ * @return the count of values above the provided threshold
+ */
+ public int countAboveThreshold(long threshold)
+ {
+ int count = 0;
+ for (long value : this)
+ {
+ if (value >= threshold)
+ {
+ count++;
+ }
+ }
+ return count;
+ }
+}
Added: components/common/trunk/common/src/main/java/org/gatein/common/concurrent/ObjectRef.java
===================================================================
--- components/common/trunk/common/src/main/java/org/gatein/common/concurrent/ObjectRef.java (rev 0)
+++ components/common/trunk/common/src/main/java/org/gatein/common/concurrent/ObjectRef.java 2009-11-16 07:39:24 UTC (rev 603)
@@ -0,0 +1,43 @@
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.gatein.common.concurrent;
+
+import java.util.concurrent.atomic.AtomicReference;
+
+/**
+ * An internal class to keep a reference onto another object, it is used in the bounded buffer implementation.
+ *
+ * @author <a href="mailto:julien.viet@exoplatform.com">Julien Viet</a>
+ * @version $Revision$
+ */
+class ObjectRef<T>
+{
+
+ /** . */
+ final T object;
+
+ /** . */
+ final AtomicReference<ObjectRef<T>> next;
+
+ ObjectRef(T object)
+ {
+ this.object = object;
+ this.next = new AtomicReference<ObjectRef<T>>();
+ }
+}
Added: components/common/trunk/common/src/test/java/org/gatein/common/concurrent/AtomicPositiveLongTestCase.java
===================================================================
--- components/common/trunk/common/src/test/java/org/gatein/common/concurrent/AtomicPositiveLongTestCase.java (rev 0)
+++ components/common/trunk/common/src/test/java/org/gatein/common/concurrent/AtomicPositiveLongTestCase.java 2009-11-16 07:39:24 UTC (rev 603)
@@ -0,0 +1,112 @@
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.gatein.common.concurrent;
+
+import junit.framework.TestCase;
+
+/**
+ * @author <a href="mailto:julien.viet@exoplatform.com">Julien Viet</a>
+ * @version $Revision$
+ */
+public class AtomicPositiveLongTestCase extends TestCase
+{
+
+ public AtomicPositiveLongTestCase()
+ {
+ }
+
+ public AtomicPositiveLongTestCase(String s)
+ {
+ super(s);
+ }
+
+ public void testConstructorThrowsIAE()
+ {
+ try
+ {
+ new AtomicPositiveLong(-1);
+ fail();
+ }
+ catch (IllegalArgumentException expected)
+ {
+ }
+ }
+
+ public void testUpdateIfGreater1()
+ {
+ AtomicPositiveLong stat = new AtomicPositiveLong(4);
+ assertEquals(4, stat.get());
+ stat.setIfGreater(3);
+ assertEquals(4, stat.get());
+ stat.setIfGreater(5);
+ assertEquals(5, stat.get());
+ }
+
+ public void testUpdateIfGreater2()
+ {
+ AtomicPositiveLong stat = new AtomicPositiveLong();
+ assertEquals(-1, stat.get());
+ stat.setIfGreater(0);
+ assertEquals(0, stat.get());
+ }
+
+ public void testUpdateIfGreaterThrowsIAE()
+ {
+ AtomicPositiveLong stat = new AtomicPositiveLong(4);
+ try
+ {
+ stat.setIfGreater(-1);
+ }
+ catch (IllegalArgumentException expected)
+ {
+ assertEquals(4, stat.get());
+ }
+ }
+
+ public void testUpdateIfLowser1()
+ {
+ AtomicPositiveLong stat = new AtomicPositiveLong(4);
+ assertEquals(4, stat.get());
+ stat.setIfLower(5);
+ assertEquals(4, stat.get());
+ stat.setIfLower(3);
+ assertEquals(3, stat.get());
+ }
+
+ public void testUpdateIfLowser2()
+ {
+ AtomicPositiveLong stat = new AtomicPositiveLong();
+ assertEquals(-1, stat.get());
+ stat.setIfLower(0);
+ assertEquals(0, stat.get());
+ }
+
+ public void testUpdateIfLowerThrowsIAE()
+ {
+ AtomicPositiveLong stat = new AtomicPositiveLong(4);
+ try
+ {
+ stat.setIfLower(-1);
+ }
+ catch (IllegalArgumentException expected)
+ {
+ assertEquals(4, stat.get());
+ }
+ }
+}
Added: components/common/trunk/common/src/test/java/org/gatein/common/concurrent/BoundedBufferTestCase.java
===================================================================
--- components/common/trunk/common/src/test/java/org/gatein/common/concurrent/BoundedBufferTestCase.java (rev 0)
+++ components/common/trunk/common/src/test/java/org/gatein/common/concurrent/BoundedBufferTestCase.java 2009-11-16 07:39:24 UTC (rev 603)
@@ -0,0 +1,127 @@
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.gatein.common.concurrent;
+
+import junit.framework.TestCase;
+
+import java.lang.ref.WeakReference;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Iterator;
+import java.util.List;
+
+/**
+ * @author <a href="mailto:julien.viet@exoplatform.com">Julien Viet</a>
+ * @version $Revision$
+ */
+public class BoundedBufferTestCase extends TestCase
+{
+
+ public BoundedBufferTestCase()
+ {
+ }
+
+ public BoundedBufferTestCase(String s)
+ {
+ super(s);
+ }
+
+ public void testNegativeMaxSize()
+ {
+ try
+ {
+ new BoundedBuffer<Object>(-1);
+ }
+ catch (IllegalArgumentException expected)
+ {
+ }
+ }
+
+ public void testSnapshot()
+ {
+ BoundedBuffer<Object> buffer = new BoundedBuffer<Object>(2);
+ Object o1 = new Object();
+ Object o2 = new Object();
+ Object o3 = new Object();
+ Iterator<Object> i0 = buffer.iterator();
+ buffer.add(o1);
+ Iterator<Object> i1 = buffer.iterator();
+ buffer.add(o2);
+ Iterator<Object> i2 = buffer.iterator();
+ buffer.add(o3);
+ Iterator<Object> i3 = buffer.iterator();
+ assertEquals(Arrays.asList(), toList(i0));
+ assertEquals(Arrays.asList(o1), toList(i1));
+ assertEquals(Arrays.asList(o1, o2), toList(i2));
+ assertEquals(Arrays.asList(o2, o3), toList(i3));
+ }
+
+ public void testNoLeak()
+ {
+ BoundedBuffer<Object> buffer = new BoundedBuffer<Object>(2);
+ Object o1 = new Object();
+ Object o2 = new Object();
+ Object o3 = new Object();
+ buffer.add(o1);
+ buffer.add(o2);
+ buffer.add(o3);
+ WeakReference<Object> ref1 = new WeakReference<Object>(o1);
+ WeakReference<Object> ref2 = new WeakReference<Object>(o2);
+ WeakReference<Object> ref3 = new WeakReference<Object>(o3);
+ o1 = null;
+ o2 = null;
+ o3 = null;
+ forceGC();
+ assertNull(ref1.get());
+ assertNotNull(ref2.get());
+ assertNotNull(ref3.get());
+ }
+
+ private <T> List<T> toList(Iterator<T> iterable)
+ {
+ List<T> list = new ArrayList<T>();
+ while (iterable.hasNext())
+ {
+ T t = iterable.next();
+ list.add(t);
+ }
+ return list;
+ }
+
+ /**
+ * Force a garbage collector.
+ */
+ protected static void forceGC()
+ {
+ WeakReference<Object> dumbReference = new WeakReference<Object>(new Object());
+ // A loop that will wait GC, using the minimal time as possible
+ while (dumbReference.get() != null)
+ {
+ System.gc();
+ try
+ {
+ Thread.sleep(500);
+ }
+ catch (InterruptedException e)
+ {
+ }
+ }
+ }
+}
+
Added: components/common/trunk/common/src/test/java/org/gatein/common/concurrent/LongSamplerTestCase.java
===================================================================
--- components/common/trunk/common/src/test/java/org/gatein/common/concurrent/LongSamplerTestCase.java (rev 0)
+++ components/common/trunk/common/src/test/java/org/gatein/common/concurrent/LongSamplerTestCase.java 2009-11-16 07:39:24 UTC (rev 603)
@@ -0,0 +1,59 @@
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.gatein.common.concurrent;
+
+import junit.framework.TestCase;
+
+/**
+ * @author <a href="mailto:julien.viet@exoplatform.com">Julien Viet</a>
+ * @version $Revision$
+ */
+public class LongSamplerTestCase extends TestCase
+{
+
+ public LongSamplerTestCase()
+ {
+ }
+
+ public LongSamplerTestCase(String s)
+ {
+ super(s);
+ }
+
+ public void testAverage()
+ {
+ LongSampler sampler = new LongSampler(2);
+ sampler.add(2L);
+ sampler.add(4L);
+ assertEquals(3D, sampler.average());
+ sampler.add(8L);
+ assertEquals(6D, sampler.average());
+ }
+
+ public void testAboveThreshold()
+ {
+ LongSampler sampler = new LongSampler(2);
+ sampler.add(1L);
+ sampler.add(2L);
+ assertEquals(0, sampler.countAboveThreshold(3L));
+ assertEquals(1, sampler.countAboveThreshold(2L));
+ assertEquals(2, sampler.countAboveThreshold(1L));
+ assertEquals(2, sampler.countAboveThreshold(0L));
+ }
+}
15 years, 1 month
gatein SVN: r602 - components/common/trunk/common.
by do-not-reply@jboss.org
Author: julien_viet
Date: 2009-11-16 02:10:57 -0500 (Mon, 16 Nov 2009)
New Revision: 602
Modified:
components/common/trunk/common/pom.xml
Log:
GTNCOMMON-5: Sanitize pom.xml from obsolete dependencies
Modified: components/common/trunk/common/pom.xml
===================================================================
--- components/common/trunk/common/pom.xml 2009-11-16 05:06:41 UTC (rev 601)
+++ components/common/trunk/common/pom.xml 2009-11-16 07:10:57 UTC (rev 602)
@@ -22,26 +22,11 @@
</dependency>
<dependency>
- <groupId>jboss</groupId>
- <artifactId>jboss-j2ee</artifactId>
- </dependency>
-
- <dependency>
<groupId>org.jboss</groupId>
<artifactId>jboss-vfs</artifactId>
</dependency>
-
- <dependency>
- <groupId>org.apache.ant</groupId>
- <artifactId>ant</artifactId>
- </dependency>
<dependency>
- <groupId>jboss</groupId>
- <artifactId>jboss-jmx</artifactId>
- </dependency>
-
- <dependency>
<groupId>commons-httpclient</groupId>
<artifactId>commons-httpclient</artifactId>
</dependency>
@@ -52,36 +37,11 @@
</dependency>
<dependency>
- <groupId>org.apache.ant</groupId>
- <artifactId>ant-junit</artifactId>
- </dependency>
-
- <dependency>
- <groupId>org.codehaus.cargo</groupId>
- <artifactId>cargo-core-uberjar</artifactId>
- </dependency>
-
- <dependency>
- <groupId>org.apache.ant</groupId>
- <artifactId>ant-nodeps</artifactId>
- </dependency>
-
- <dependency>
- <groupId>org.apache.ant</groupId>
- <artifactId>ant-launcher</artifactId>
- </dependency>
-
- <dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
+ <scope>test</scope>
</dependency>
- <dependency>
- <groupId>org.slf4j</groupId>
- <artifactId>slf4j-api</artifactId>
- <version>1.5.6</version>
- </dependency>
-
</dependencies>
<build>
15 years, 1 month
gatein SVN: r601 - in portal/trunk: web/eXoResources/src/main/webapp/javascript/eXo/webui and 1 other directory.
by do-not-reply@jboss.org
Author: tan_pham_dinh
Date: 2009-11-16 00:06:41 -0500 (Mon, 16 Nov 2009)
New Revision: 601
Modified:
portal/trunk/portlet/dashboard/src/main/java/org/exoplatform/dashboard/webui/component/UITabPaneDashboard.java
portal/trunk/web/eXoResources/src/main/webapp/javascript/eXo/webui/UITabbedDashboard.js
Log:
GTNPORTAL-103: Error when change title of dashboard tab to null
Modified: portal/trunk/portlet/dashboard/src/main/java/org/exoplatform/dashboard/webui/component/UITabPaneDashboard.java
===================================================================
--- portal/trunk/portlet/dashboard/src/main/java/org/exoplatform/dashboard/webui/component/UITabPaneDashboard.java 2009-11-16 03:48:24 UTC (rev 600)
+++ portal/trunk/portlet/dashboard/src/main/java/org/exoplatform/dashboard/webui/component/UITabPaneDashboard.java 2009-11-16 05:06:41 UTC (rev 601)
@@ -38,7 +38,6 @@
import org.exoplatform.webui.core.UIContainer;
import org.exoplatform.webui.event.Event;
import org.exoplatform.webui.event.EventListener;
-import org.exoplatform.webui.exception.MessageException;
import java.util.ArrayList;
import java.util.List;
@@ -212,6 +211,10 @@
private boolean validateName(String label)
{
+ if (label == null || label.length() < 1)
+ {
+ return false;
+ }
label = label.trim();
if (Character.isDigit(label.charAt(0)) || label.charAt(0) == '-')
{
Modified: portal/trunk/web/eXoResources/src/main/webapp/javascript/eXo/webui/UITabbedDashboard.js
===================================================================
--- portal/trunk/web/eXoResources/src/main/webapp/javascript/eXo/webui/UITabbedDashboard.js 2009-11-16 03:48:24 UTC (rev 600)
+++ portal/trunk/web/eXoResources/src/main/webapp/javascript/eXo/webui/UITabbedDashboard.js 2009-11-16 05:06:41 UTC (rev 601)
@@ -31,7 +31,7 @@
if(keyNum == 13){
var inputElement = eXo.core.Browser.getEventSource(e);
var newTabLabel = inputElement.value;
- if(newTabLabel.length < 1){
+ if(!newTabLabel || newTabLabel.length < 1){
return;
}
var DOMUtil = eXo.core.DOMUtil;
@@ -53,15 +53,10 @@
href += "&objectId=" + nodeIndex;
href += "&newTabLabel=" + encodeURIComponent(newTabLabel);
window.location = href;
- return;
}
//If user presses on the ESCAPE key, then reset the span element on the tab
else if(keyNum == 27){
var inputElement = eXo.core.Browser.getEventSource(e);
-// var spanElement = document.createElement("span");
-// spanElement.ondblclick = "#"; //TODO: Set the callback on this property
-// spanElement.innerHTML = inputElement.name;
-// inputElement.parentNode.replaceChild(spanElement, inputElement);
if(eXo.webui.UITabbedDashboard.backupElement) {
inputElement.parentNode.replaceChild(eXo.webui.UITabbedDashboard.backupElement, inputElement);
eXo.webui.UITabbedDashboard.backupElement = null;
@@ -102,6 +97,7 @@
if(keyNum == 13){
var inputElement = eXo.core.Browser.getEventSource(e);
var newTabLabel = inputElement.value;
+ if(!newTabLabel || newTabLabel.length < 1) return;
//Send request to server to change node name
var href = eXo.env.server.portalBaseURL + "?portal:componentId=" + inputElement.id;
15 years, 1 month
gatein SVN: r600 - portal/trunk/web/portal/src/main/webapp/groovy/portal/webui/application.
by do-not-reply@jboss.org
Author: truong.le
Date: 2009-11-15 22:48:24 -0500 (Sun, 15 Nov 2009)
New Revision: 600
Modified:
portal/trunk/web/portal/src/main/webapp/groovy/portal/webui/application/UIPortlet.gtmpl
Log:
GTNPORTAL-171: Error display in Portlet Title when click Show Info Bar
Modified: portal/trunk/web/portal/src/main/webapp/groovy/portal/webui/application/UIPortlet.gtmpl
===================================================================
--- portal/trunk/web/portal/src/main/webapp/groovy/portal/webui/application/UIPortlet.gtmpl 2009-11-16 03:14:23 UTC (rev 599)
+++ portal/trunk/web/portal/src/main/webapp/groovy/portal/webui/application/UIPortlet.gtmpl 2009-11-16 03:48:24 UTC (rev 600)
@@ -97,7 +97,10 @@
if(portalMode != uiPortalApp.CONTAINER_BLOCK_EDIT_MODE && portalMode != uiPortalApp.APP_BLOCK_EDIT_MODE) {
if(uicomponent.getShowInfoBar()) {
String title = uicomponent.getTitle();
- if(title == null || title.trim().length() < 1) title = portletId;
+ if(title == null || title.trim().length() < 1)
+ title = uicomponent.getDisplayName();
+ if(title == null || title.trim().length() < 1)
+ title = portletId;
/*Begin Window Portlet Bar*/
String visibility = "visible";
String appDisplay = "block";
15 years, 1 month