Skip to content
This repository has been archived by the owner on Jan 22, 2024. It is now read-only.

jaggr-web and non-osgi sample - Implementation of review comments #199

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions jaggr-web/src/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Manifest-Version: 1.0
Class-Path:

Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# (C) Copyright 2012, IBM Corporation
#
# Licensed 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.

com.ibm.jaggr.core.impl.modulebuilder.i18n.I18nModuleBuilder
com.ibm.jaggr.core.impl.modulebuilder.javascript.JavaScriptModuleBuilder
com.ibm.jaggr.core.impl.modulebuilder.css.CSSModuleBuilder
com.ibm.jaggr.core.impl.modulebuilder.text.TextModuleBuilder
com.ibm.jaggr.core.impl.modulebuilder.less.LessModuleBuilder
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# (C) Copyright 2012, IBM Corporation
#
# Licensed 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.

com.ibm.jaggr.core.impl.resource.FileResourceFactory
com.ibm.jaggr.core.impl.resource.ClasspathResourceFactory
com.ibm.jaggr.core.impl.resource.JarResourceFactory



Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# (C) Copyright 2012, IBM Corporation
#
# Licensed 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.

com.ibm.jaggr.web.impl.transport.DojoHttpTransport
123 changes: 123 additions & 0 deletions jaggr-web/src/com/ibm/jaggr/web/PlatformServicesImpl.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
/*
* � Copyright IBM Corp. 2013
*
* Licensed 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 com.ibm.jaggr.web;

import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.ArrayList;
import java.util.Dictionary;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;

import com.ibm.jaggr.core.IPlatformServices;
import com.ibm.jaggr.core.IServiceReference;
import com.ibm.jaggr.core.IServiceRegistration;

public class PlatformServicesImpl implements IPlatformServices {

private Map<String, Object> serviceReferenceMap;

public PlatformServicesImpl() {
//But this will be a problem if we ever try to support a command console
//because the console communicates with the aggregator instances that are registered in the service registry,
//and for that to work, the service registry has to be a global object.
serviceReferenceMap = new ConcurrentHashMap<String, Object>();
}

@Override
public IServiceRegistration registerService(String clazz, Object service, Dictionary<String, String> properties) {
StringBuilder sb = new StringBuilder();
String uniqueKey = sb.append(clazz).append("_") //$NON-NLS-1$
.append(service.getClass().getName()).toString();
if (!serviceReferenceMap.containsKey(uniqueKey)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To use ConcurrentMap in a thread-safe way, you need to use the putIfAbsent() method instead of containsKey() to add a key to the map only if it is not already there.

Object[] serviceDetails = new Object[3];
serviceDetails[0] = clazz;
serviceDetails[1] = service;
serviceDetails[2] = properties;
serviceReferenceMap.put(uniqueKey, serviceDetails);
}
IServiceRegistration serviceRegistation = new ServiceRegistrationWeb(uniqueKey, this);

return serviceRegistation;
}


public void unRegisterService(Object serviceRegistration) {
if (serviceReferenceMap.containsKey((String) serviceRegistration)) {
serviceReferenceMap.remove((String) serviceRegistration);
return;
}
}

@Override
public IServiceReference[] getServiceReferences(String clazz, String filter) {
return getServiceReferences(clazz);
}

public IServiceReference[] getServiceReferences(String clazz) {
ArrayList<IServiceReference> serviceReferences = new ArrayList<IServiceReference>();
Set<String> srs = serviceReferenceMap.keySet();
for(String sr : srs){
int index = ((String) sr).indexOf("_"); //$NON-NLS-1$
String clz = ((String) sr).substring(0, index);
if(clz.equalsIgnoreCase(clazz) || clazz == null){
serviceReferences.add(new ServiceReferenceWeb(sr));
}
}
IServiceReference[] serviceRefs = new IServiceReference[serviceReferences.size()];
for(int i = 0; i < serviceReferences.size(); i++){
serviceRefs[i] = serviceReferences.get(i);
}
return serviceRefs;
}

@Override
public Object getService(IServiceReference serviceReference) {
Object[] serviceDetails = null;
serviceDetails = (Object[])(serviceReferenceMap.get((String)serviceReference.getPlatformObject()));
return serviceDetails[1];
}

@Override
public synchronized boolean ungetService(IServiceReference serviceReference) {
boolean status = false;
if(serviceReferenceMap.containsKey((String)serviceReference.getPlatformObject())){
serviceReferenceMap.remove((String)serviceReference.getPlatformObject());
status = true;
return status;
}
return status;
}

@Override
public URL getResource(String resourceName) {
return null;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that this should return getAppContextURI().resolve(resourceName).

}

@Override
public Dictionary<String, String> getHeaders() {
return null;
}

@Override
public URI getAppContextURI() throws URISyntaxException {
return null;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this return new URI("classpath:///");. That would make it possible to use URIs like "/WebContent/..." instead of "classpath:///WebContent/..." in aggrConfig.js (see AbstractAggregatorImpl.newResource() when URI is not absolute).

}

}
36 changes: 36 additions & 0 deletions jaggr-web/src/com/ibm/jaggr/web/ServiceReferenceWeb.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* � Copyright IBM Corp. 2013
*
* Licensed 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 com.ibm.jaggr.web;

import com.ibm.jaggr.core.IServiceReference;

public class ServiceReferenceWeb implements IServiceReference {

String serviceReference = null;


public ServiceReferenceWeb(String serviceRef){
serviceReference = serviceRef;
}

@Override
public Object getPlatformObject(){
return serviceReference;

}

}
36 changes: 36 additions & 0 deletions jaggr-web/src/com/ibm/jaggr/web/ServiceRegistrationWeb.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* � Copyright IBM Corp. 2013
*
* Licensed 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 com.ibm.jaggr.web;

import com.ibm.jaggr.core.IServiceRegistration;

public class ServiceRegistrationWeb implements IServiceRegistration {

String ServiceRegistration = null;
PlatformServicesImpl platformServices = null;

public ServiceRegistrationWeb(String serviceRegistrationWeb, PlatformServicesImpl platformServicesWeb){
ServiceRegistration = serviceRegistrationWeb;
platformServices = platformServicesWeb;
}

@Override
public void unregister() {
platformServices.unRegisterService(ServiceRegistration);
}

}
Loading