Skip to content

Commit

Permalink
Fixed some bugs...
Browse files Browse the repository at this point in the history
  • Loading branch information
Sophos-Elias-Vasylenko committed Oct 27, 2015
1 parent 19af48b commit dbc19ee
Show file tree
Hide file tree
Showing 17 changed files with 283 additions and 484 deletions.
2 changes: 1 addition & 1 deletion cnf/build.bnd
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ pluginpath.modabi: \
${build}/release/uk.co.strangeskies.modabi.bnd.core/uk.co.strangeskies.modabi.bnd.core-${modabi-version}.jar,\
${build}/release/uk.co.strangeskies.modabi.bnd.xml/uk.co.strangeskies.modabi.bnd.xml-${modabi-version}.jar

-pluginpath: \
-pluginpath.base: \
${build}/cache/biz.aQute.repository.aether.jar; \
url = ${bnd-release}/biz.aQute.repository.aether/biz.aQute.repository.aether-latest.jar

Expand Down
2 changes: 1 addition & 1 deletion cnf/central.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
},{
"artifactId":"org.apache.felix.framework","baseline":"5.0.1","bsn":"org.apache.felix.framework","created":1434553121337,"description":"OSGi R6 framework implementation.","errors":1,"groupId":"org.apache.felix","md5":"F870067E8B94B7A00CC56D84F67EFA2C","name":"Apache Felix Framework","phase":"MASTER","revision":"3D486EE5235A5ABBD955CCB1D263772F93DF8A1E","size":601333,"urls":["http://repo1.maven.org/maven2/org/apache/felix/org.apache.felix.framework/5.0.1/org.apache.felix.framework-5.0.1.jar"],"version":"5.0.1"
},{
"artifactId":"org.apache.felix.scr","baseline":"1.8.2","bsn":"org.apache.felix.scr","created":1390016409295,"description":"Implementation of the Declarative Services specification 1.2","groupId":"org.apache.felix","md5":"CE9DB4E6958CBD7E555CEC48FDCD35FC","name":"Apache Felix Declarative Services","phase":"MASTER","revision":"C3047D56EE57DE0752821FD9C3894DDA664F2E37","size":267629,"urls":["http://repo1.maven.org/maven2/org/apache/felix/org.apache.felix.scr/1.8.2/org.apache.felix.scr-1.8.2.jar"],"version":"1.8.2"
"artifactId":"org.apache.felix.metatype","baseline":"1.1.2","bsn":"org.apache.felix.metatype","created":1439196650427,"description":"Implementation of the OSGi Metatype Service Specification 1.2","groupId":"org.apache.felix","md5":"930E7659BC0C724E1933E72D3CC994C1","name":"Apache Felix Metatype Service","phase":"MASTER","revision":"E98972F46B0EBF8BE4A10F9C10F0471528DB54D1","size":73862,"urls":["http://repo1.maven.org/maven2/org/apache/felix/org.apache.felix.metatype/1.1.2/org.apache.felix.metatype-1.1.2.jar"],"version":"1.1.2"
},{
"artifactId":"org.apache.servicemix.bundles.stax-utils","baseline":"20070216.0.0","bsn":"org.apache.servicemix.bundles.stax-utils","created":1346824474672,"description":"This OSGi bundle wraps stax-utils 20070216 jar file.","groupId":"org.apache.servicemix.bundles","md5":"74D11CCD8FCF1F001B39E9D555EAED61","name":"Apache ServiceMix :: Bundles :: stax-utils","phase":"MASTER","qualifier":"1","revision":"3B100EE9FF904F0B63898D796FA47579D010D083","size":138410,"urls":["http://repo1.maven.org/maven2/org/apache/servicemix/bundles/org.apache.servicemix.bundles.stax-utils/20070216_1/org.apache.servicemix.bundles.stax-utils-20070216_1.jar"],"version":"20070216_1"
},{
Expand Down
2 changes: 1 addition & 1 deletion cnf/local/index.xml.sha
Original file line number Diff line number Diff line change
@@ -1 +1 @@
8de8e8866152096f0c4ea5ddd6ed1d633b4d1a6edfbd823245cb57f6639732fd
00d32998f75fb42424a40b7de9e81e4dc9be2ca6a9fc3f2d3bec406919d62140
25 changes: 13 additions & 12 deletions uk.co.strangeskies.modabi.benchmarks/bnd.bnd
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ Bundle-Description: \

-runee: JavaSE-1.8

-pluginpath: \
${pluginpath.modabi}

-plugin: \
uk.co.strangeskies.modabi.bnd.xml.ModabiXmlRegistration

-buildpath: \
${ss;utilities},\
${ss;reflection},\
Expand All @@ -16,8 +22,6 @@ Bundle-Description: \
-includeresource: \
META-INF/modabi=schemata

Private-Package: uk.co.strangeskies.modabi.run

-runrequires: \
osgi.identity;filter:='(osgi.identity=osgi.enroute.logger.simple.provider)',\
osgi.identity;filter:='(osgi.identity=uk.co.strangeskies.utilities.osgi.consolelog)',\
Expand All @@ -30,26 +34,23 @@ Private-Package: uk.co.strangeskies.modabi.run
-runfw: org.eclipse.osgi;version='[3.10.100.v20150529-1857,3.10.100.v20150529-1857]'

-runbundles: \
biz.aQute.bndlib;version='[3.0.0,3.0.1)',\
org.apache.commons.lang3;version='[3.4.0,3.4.1)',\
org.apache.felix.configadmin;version='[1.8.6,1.8.7)',\
org.apache.felix.gogo.command;version='[0.14.0,0.14.1)',\
org.apache.felix.gogo.runtime;version='[0.16.2,0.16.3)',\
org.apache.felix.gogo.shell;version='[0.10.0,0.10.1)',\
org.apache.felix.log;version='[1.0.1,1.0.2)',\
org.apache.felix.metatype;version='[1.1.2,1.1.3)',\
org.apache.felix.scr;version='[2.0.0,2.0.1)',\
org.apache.servicemix.bundles.stax-utils;version='[20070216.0.0,20070216.0.1)',\
org.eclipse.equinox.metatype;version='[1.4.100,1.4.101)',\
org.osgi.service.metatype;version='[1.3.0,1.3.1)',\
osgi.enroute.logger.simple.provider;version='[1.2.1,1.2.2)',\
uk.co.strangeskies.fx;version='[1.0.0,1.0.1)',\
uk.co.strangeskies.mathematics;version='[1.0.0,1.0.1)',\
uk.co.strangeskies.mathematics;version='[1.0.13,1.0.14)',\
uk.co.strangeskies.modabi.benchmarks;version=snapshot,\
uk.co.strangeskies.modabi.bnd.xml;version=snapshot,\
uk.co.strangeskies.modabi.core.api;version=snapshot,\
uk.co.strangeskies.modabi.core.provider;version=snapshot,\
uk.co.strangeskies.reflection;version='[1.0.0,1.0.1)',\
uk.co.strangeskies.utilities;version='[1.0.0,1.0.1)',\
uk.co.strangeskies.utilities.osgi.consolelog;version='[1.0.0,1.0.1)'
uk.co.strangeskies.modabi.io.xml.provider;version=snapshot,\
uk.co.strangeskies.reflection;version='[1.0.13,1.0.14)',\
uk.co.strangeskies.utilities;version='[1.0.13,1.0.14)',\
uk.co.strangeskies.utilities.osgi.consolelog;version='[1.0.13,1.0.14)'

-runvm: -XX:MaxJavaStackTraceDepth=1000000
Export-Package: uk.co.strangeskies.modabi.benchmark
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* You should have received a copy of the GNU Lesser General Public License
* along with uk.co.strangeskies.modabi.benchmarks. If not, see <http://www.gnu.org/licenses/>.
*/
package uk.co.strangeskies.modabi.run;
package uk.co.strangeskies.modabi.benchmark;

import java.io.File;
import java.io.FileNotFoundException;
Expand Down Expand Up @@ -44,6 +44,7 @@
import org.osgi.service.log.LogService;

import uk.co.strangeskies.modabi.SchemaManager;
import uk.co.strangeskies.utilities.ContextClassLoaderRunner;

@Component
public class BenchmarkRunner {
Expand All @@ -66,67 +67,72 @@ public void setLogger(LogService logger) {

@Activate
public void run(BundleContext context) throws BundleException {
System.out.println("TEST");
try {
logger.log(LogService.LOG_INFO, "Preparing benchmark...");

Thread.currentThread().setContextClassLoader(
context.getBundle().adapt(BundleWiring.class).getClassLoader());

File outputDir = new File(OUTPUT_FOLDER);
if (!outputDir.exists()) {
logger.log(LogService.LOG_INFO,
"Creating output directory: " + outputDir.getAbsolutePath());

if (!outputDir.mkdirs()) {
throw new IllegalStateException(
"Could not create output directory, aborting...");
}
}

System.out.println("test");

manager.bindSchema().from(
context.getBundle().getResource("/META-INF/modabi/BenchmarkSchema.xml").openStream())
.resolve(500);

System.out.println("test2");

boolean createXml = false;
logger.log(LogService.LOG_INFO, "Will create XML files? " + createXml);
if (createXml) {
createXmlPortfolio();
}

System.gc();
System.gc();

for (int i = 0; i < 10; i++) {
readLargeXmlWithModabi(new File(
OUTPUT_FOLDER + File.separatorChar + "large-person-100.xml"));
readLargeXmlWithModabi(new File(
OUTPUT_FOLDER + File.separatorChar + "large-person-1000.xml"));
readLargeXmlWithModabi(new File(
OUTPUT_FOLDER + File.separatorChar + "large-person-10000.xml"));

readLargeXmlWithStax(new File(
OUTPUT_FOLDER + File.separatorChar + "large-person-100.xml"));
readLargeXmlWithStax(new File(
OUTPUT_FOLDER + File.separatorChar + "large-person-1000.xml"));
readLargeXmlWithStax(new File(
OUTPUT_FOLDER + File.separatorChar + "large-person-10000.xml"));

readLargeXmlWithFasterStax(new File(
OUTPUT_FOLDER + File.separatorChar + "large-person-100.xml"));
readLargeXmlWithFasterStax(new File(
OUTPUT_FOLDER + File.separatorChar + "large-person-1000.xml"));
readLargeXmlWithFasterStax(new File(
OUTPUT_FOLDER + File.separatorChar + "large-person-10000.xml"));
}
} catch (Exception e) {
e.printStackTrace();
}

new ContextClassLoaderRunner(
context.getBundle().adapt(BundleWiring.class).getClassLoader())
.run(() -> {
try {
logger.log(LogService.LOG_INFO, "Preparing benchmark...");

File outputDir = new File(OUTPUT_FOLDER);
if (!outputDir.exists()) {
logger.log(LogService.LOG_INFO, "Creating output directory: "
+ outputDir.getAbsolutePath());

if (!outputDir.mkdirs()) {
throw new IllegalStateException(
"Could not create output directory, aborting...");
}
}

System.out.println("test");
manager.bindSchema()
.from(context.getBundle()
.getResource("/META-INF/modabi/BenchmarkSchema.xml")
.openStream())
.resolve(500);

System.out.println("test2");

boolean createXml = false;
logger.log(LogService.LOG_INFO,
"Will create XML files? " + createXml);
if (createXml) {
createXmlPortfolio();
}

System.gc();
System.gc();

for (int i = 0; i < 10; i++) {
readLargeXmlWithModabi(new File(OUTPUT_FOLDER
+ File.separatorChar + "large-person-100.xml"));
readLargeXmlWithModabi(new File(OUTPUT_FOLDER
+ File.separatorChar + "large-person-1000.xml"));
readLargeXmlWithModabi(new File(OUTPUT_FOLDER
+ File.separatorChar + "large-person-10000.xml"));

readLargeXmlWithStax(new File(OUTPUT_FOLDER
+ File.separatorChar + "large-person-100.xml"));
readLargeXmlWithStax(new File(OUTPUT_FOLDER
+ File.separatorChar + "large-person-1000.xml"));
readLargeXmlWithStax(new File(OUTPUT_FOLDER
+ File.separatorChar + "large-person-10000.xml"));

readLargeXmlWithFasterStax(new File(OUTPUT_FOLDER
+ File.separatorChar + "large-person-100.xml"));
readLargeXmlWithFasterStax(new File(OUTPUT_FOLDER
+ File.separatorChar + "large-person-1000.xml"));
readLargeXmlWithFasterStax(new File(OUTPUT_FOLDER
+ File.separatorChar + "large-person-10000.xml"));
}
} catch (RuntimeException e) {
e.printStackTrace();
throw e;
} catch (Exception e) {
e.printStackTrace();
throw new RuntimeException(e);
}
});
context.getBundle(0).stop();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* You should have received a copy of the GNU Lesser General Public License
* along with uk.co.strangeskies.modabi.benchmarks. If not, see <http://www.gnu.org/licenses/>.
*/
package uk.co.strangeskies.modabi.run;
package uk.co.strangeskies.modabi.benchmark;

public class PersonType {
private String firstName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* You should have received a copy of the GNU Lesser General Public License
* along with uk.co.strangeskies.modabi.benchmarks. If not, see <http://www.gnu.org/licenses/>.
*/
package uk.co.strangeskies.modabi.run;
package uk.co.strangeskies.modabi.benchmark;

import java.util.ArrayList;
import java.util.Collection;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
@org.osgi.annotation.versioning.Version("1.0.0")
package uk.co.strangeskies.modabi.benchmark;
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
package uk.co.strangeskies.modabi.bnd;

import java.io.File;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.Map;

import aQute.bnd.osgi.Analyzer;
Expand All @@ -32,12 +30,9 @@
import uk.co.strangeskies.modabi.SchemaException;
import uk.co.strangeskies.modabi.SchemaManager;
import uk.co.strangeskies.modabi.io.structured.DataInterface;
import uk.co.strangeskies.utilities.ContextClassLoaderRunner;

public abstract class ModabiRegistration implements AnalyzerPlugin {
public interface ThrowingRunnable<T extends Exception> {
void run() throws T;
}

private final DataInterface handler;
private final SchemaManager manager;

Expand Down Expand Up @@ -73,8 +68,12 @@ private void registerSchemata(Jar jar, Analyzer analyzer) {

for (String resourceName : resources.keySet()) {
Schema schema;
schema = manager.bindSchema()
.from(resources.get(resourceName).openInputStream()).resolve();
try {
schema = manager.bindSchema()
.from(resources.get(resourceName).openInputStream()).resolve();
} catch (Exception e) {
throw new SchemaException(e);
}

String capability = "uk.co.strangeskies.modabi;schema:String=\""
+ schema.getQualifiedName() + "\"";
Expand All @@ -99,10 +98,7 @@ private void registerSchemata(Jar jar, Analyzer analyzer) {
}

private void withJarOnBuildPath(Analyzer analyzer, Jar jar, String jarName,
ThrowingRunnable<?> run) {
ClassLoader threadClassLoader = Thread.currentThread()
.getContextClassLoader();

Runnable run) {
try {
File tempJar = createDirs(
analyzer.getBase() + File.separator + "generated", "tmp", "jar");
Expand All @@ -116,14 +112,9 @@ private void withJarOnBuildPath(Analyzer analyzer, Jar jar, String jarName,
tempJar.getAbsolutePath() + File.separator + jarName + ".jar");

jar.write(tempJar);
Thread.currentThread().setContextClassLoader(new URLClassLoader(
new URL[] { tempJar.toURI().toURL() }, threadClassLoader));

run.run();
new ContextClassLoaderRunner(tempJar.toURI().toURL()).run(run);
} catch (Exception e) {
throw flattenMessage(e);
} finally {
Thread.currentThread().setContextClassLoader(threadClassLoader);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public class SchemaManagerImpl implements SchemaManager {

private final BindingProviders bindingProviders;

private final Set<DataInterface> fileLoaders;
private final Map<String, DataInterface> dataInterfaces;

public SchemaManagerImpl() {
this(new SchemaBuilderImpl(), new ModelBuilderImpl(),
Expand Down Expand Up @@ -134,7 +134,7 @@ public SchemaManagerImpl(SchemaBuilder schemaBuilder,

bindingProviders = new BindingProviders(this);

fileLoaders = new HashSet<>();
dataInterfaces = new HashMap<>();
}

SchemaBinder getSchemaBinder() {
Expand Down Expand Up @@ -417,22 +417,22 @@ public GeneratedSchema generateSchema(QualifiedName name,
@Override
@Reference(cardinality = ReferenceCardinality.MULTIPLE, policy = ReferencePolicy.DYNAMIC, unbind = "unregisterDataInterface")
public void registerDataInterface(DataInterface loader) {
fileLoaders.add(loader);
dataInterfaces.put(loader.getFormatId(), loader);
}

@Override
public void unregisterDataInterface(DataInterface loader) {
fileLoaders.remove(loader);
dataInterfaces.remove(loader.getFormatId(), loader);
}

@Override
public Set<DataInterface> getRegisteredDataInterfaces() {
return Collections.unmodifiableSet(fileLoaders);
return new HashSet<>(dataInterfaces.values());
}

@Override
public DataInterface getDataInterface(String id) {
return null;
return dataInterfaces.get(id);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,14 @@ public SchemaBinder(BindingContextImpl context) {

public <T> BindingFuture<T> bind(Model.Effective<T> model,
StructuredDataSource input) {
try {
Class.forName("uk.co.strangeskies.modabi.schema.SchemaNode");
Class.forName("uk.co.strangeskies.modabi.schema.SchemaNode", true,
Thread.currentThread().getContextClassLoader());
} catch (ClassNotFoundException e) {
throw new RuntimeException(e);
}

ClassLoader classLoader = Thread.currentThread().getContextClassLoader();

BindingContextImpl context = this.context.withInput(input);
Expand Down
Loading

0 comments on commit dbc19ee

Please sign in to comment.