repo_name stringlengths 7 104 | file_path stringlengths 13 198 | context stringlengths 67 7.15k | import_statement stringlengths 16 4.43k | code stringlengths 40 6.98k | prompt stringlengths 227 8.27k | next_line stringlengths 8 795 |
|---|---|---|---|---|---|---|
Haehnchen/idea-php-drupal-symfony2-bridge | src/de/espend/idea/php/drupal/linemarker/RouteFormLineMarkerProvider.java | // Path: src/de/espend/idea/php/drupal/DrupalProjectComponent.java
// public class DrupalProjectComponent {
//
// public static boolean isEnabled(Project project) {
// return Symfony2ProjectComponent.isEnabled(project);
// }
//
// public static boolean isEnabled(@Nullable PsiElement psiElement) {
// return psiElement != null && isEnabled(psiElement.getProject());
// }
//
// }
//
// Path: src/de/espend/idea/php/drupal/utils/IndexUtil.java
// public class IndexUtil {
//
// @NotNull
// public static Collection<PhpClass> getFormClassForId(@NotNull Project project, @NotNull String id) {
// Collection<PhpClass> phpClasses = new ArrayList<>();
//
// for (String key : SymfonyProcessors.createResult(project, ConfigEntityTypeAnnotationIndex.KEY)) {
// if(!id.equals(key)) {
// continue;
// }
//
// for (String value : FileBasedIndex.getInstance().getValues(ConfigEntityTypeAnnotationIndex.KEY, key, GlobalSearchScope.allScope(project))) {
// phpClasses.addAll(PhpElementsUtil.getClassesInterface(project, value));
// }
// }
//
// return phpClasses;
// }
//
// @NotNull
// public static Collection<PsiElement> getMenuForId(@NotNull Project project, @NotNull String text) {
// Collection<VirtualFile> virtualFiles = new ArrayList<>();
//
// FileBasedIndex.getInstance().getFilesWithKey(MenuIndex.KEY, new HashSet<>(Collections.singletonList(text)), virtualFile -> {
// virtualFiles.add(virtualFile);
// return true;
// }, GlobalSearchScope.allScope(project));
//
// Collection<PsiElement> targets = new ArrayList<>();
//
// for (VirtualFile virtualFile : virtualFiles) {
// PsiFile file = PsiManager.getInstance(project).findFile(virtualFile);
// if(!(file instanceof YAMLFile)) {
// continue;
// }
//
// ContainerUtil.addIfNotNull(targets, YAMLUtil.getQualifiedKeyInFile((YAMLFile) file, text));
// }
//
// return targets;
// }
//
// @NotNull
// public static Collection<LookupElement> getIndexedKeyLookup(@NotNull Project project, @NotNull ID<String, ?> var1) {
// Collection<LookupElement> lookupElements = new ArrayList<>();
//
// lookupElements.addAll(SymfonyProcessors.createResult(project, var1).stream().map(
// s -> LookupElementBuilder.create(s).withIcon(DrupalIcons.DRUPAL)).collect(Collectors.toList())
// );
//
// return lookupElements;
// }
//
// public static boolean isValidForIndex(@NotNull FileContent inputData, @NotNull PsiFile psiFile) {
//
// String fileName = psiFile.getName();
// if(fileName.startsWith(".") || fileName.endsWith("Test")) {
// return false;
// }
//
// VirtualFile baseDir = inputData.getProject().getBaseDir();
// if(baseDir == null) {
// return false;
// }
//
// // is Test file in path name
// String relativePath = VfsUtil.getRelativePath(inputData.getFile(), baseDir, '/');
// if(relativePath != null && (relativePath.contains("/Test/") || relativePath.contains("/Fixtures/"))) {
// return false;
// }
//
// return true;
// }
// }
| import com.intellij.codeInsight.daemon.LineMarkerInfo;
import com.intellij.codeInsight.daemon.LineMarkerProvider;
import com.intellij.codeInsight.navigation.NavigationGutterIconBuilder;
import com.intellij.openapi.project.Project;
import com.intellij.psi.PsiElement;
import com.jetbrains.php.lang.psi.elements.PhpClass;
import de.espend.idea.php.drupal.DrupalProjectComponent;
import de.espend.idea.php.drupal.utils.IndexUtil;
import fr.adrienbrault.idea.symfony2plugin.Symfony2Icons;
import fr.adrienbrault.idea.symfony2plugin.config.yaml.YamlElementPatternHelper;
import fr.adrienbrault.idea.symfony2plugin.util.PhpElementsUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.yaml.psi.YAMLKeyValue;
import org.jetbrains.yaml.psi.YAMLMapping;
import org.jetbrains.yaml.psi.YAMLScalar;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List; | if(psiElements.size() == 0) {
return;
}
Project project = psiElements.get(0).getProject();
if(!DrupalProjectComponent.isEnabled(project)) {
return;
}
for (PsiElement psiElement : psiElements) {
collectRouteInlineClasses(results, project, psiElement);
}
}
private void collectRouteInlineClasses(@NotNull Collection<LineMarkerInfo> results, @NotNull Project project, @NotNull PsiElement psiElement) {
if(!(YamlElementPatternHelper.getSingleLineScalarKey("_form").accepts(psiElement) ||
YamlElementPatternHelper.getSingleLineScalarKey("_entity_form").accepts(psiElement))
) {
return;
}
PsiElement yamlScalar = psiElement.getParent();
if(!(yamlScalar instanceof YAMLScalar)) {
return;
}
String textValue = ((YAMLScalar) yamlScalar).getTextValue();
Collection<PhpClass> classesInterface = new ArrayList<>(PhpElementsUtil.getClassesInterface(project, textValue)); | // Path: src/de/espend/idea/php/drupal/DrupalProjectComponent.java
// public class DrupalProjectComponent {
//
// public static boolean isEnabled(Project project) {
// return Symfony2ProjectComponent.isEnabled(project);
// }
//
// public static boolean isEnabled(@Nullable PsiElement psiElement) {
// return psiElement != null && isEnabled(psiElement.getProject());
// }
//
// }
//
// Path: src/de/espend/idea/php/drupal/utils/IndexUtil.java
// public class IndexUtil {
//
// @NotNull
// public static Collection<PhpClass> getFormClassForId(@NotNull Project project, @NotNull String id) {
// Collection<PhpClass> phpClasses = new ArrayList<>();
//
// for (String key : SymfonyProcessors.createResult(project, ConfigEntityTypeAnnotationIndex.KEY)) {
// if(!id.equals(key)) {
// continue;
// }
//
// for (String value : FileBasedIndex.getInstance().getValues(ConfigEntityTypeAnnotationIndex.KEY, key, GlobalSearchScope.allScope(project))) {
// phpClasses.addAll(PhpElementsUtil.getClassesInterface(project, value));
// }
// }
//
// return phpClasses;
// }
//
// @NotNull
// public static Collection<PsiElement> getMenuForId(@NotNull Project project, @NotNull String text) {
// Collection<VirtualFile> virtualFiles = new ArrayList<>();
//
// FileBasedIndex.getInstance().getFilesWithKey(MenuIndex.KEY, new HashSet<>(Collections.singletonList(text)), virtualFile -> {
// virtualFiles.add(virtualFile);
// return true;
// }, GlobalSearchScope.allScope(project));
//
// Collection<PsiElement> targets = new ArrayList<>();
//
// for (VirtualFile virtualFile : virtualFiles) {
// PsiFile file = PsiManager.getInstance(project).findFile(virtualFile);
// if(!(file instanceof YAMLFile)) {
// continue;
// }
//
// ContainerUtil.addIfNotNull(targets, YAMLUtil.getQualifiedKeyInFile((YAMLFile) file, text));
// }
//
// return targets;
// }
//
// @NotNull
// public static Collection<LookupElement> getIndexedKeyLookup(@NotNull Project project, @NotNull ID<String, ?> var1) {
// Collection<LookupElement> lookupElements = new ArrayList<>();
//
// lookupElements.addAll(SymfonyProcessors.createResult(project, var1).stream().map(
// s -> LookupElementBuilder.create(s).withIcon(DrupalIcons.DRUPAL)).collect(Collectors.toList())
// );
//
// return lookupElements;
// }
//
// public static boolean isValidForIndex(@NotNull FileContent inputData, @NotNull PsiFile psiFile) {
//
// String fileName = psiFile.getName();
// if(fileName.startsWith(".") || fileName.endsWith("Test")) {
// return false;
// }
//
// VirtualFile baseDir = inputData.getProject().getBaseDir();
// if(baseDir == null) {
// return false;
// }
//
// // is Test file in path name
// String relativePath = VfsUtil.getRelativePath(inputData.getFile(), baseDir, '/');
// if(relativePath != null && (relativePath.contains("/Test/") || relativePath.contains("/Fixtures/"))) {
// return false;
// }
//
// return true;
// }
// }
// Path: src/de/espend/idea/php/drupal/linemarker/RouteFormLineMarkerProvider.java
import com.intellij.codeInsight.daemon.LineMarkerInfo;
import com.intellij.codeInsight.daemon.LineMarkerProvider;
import com.intellij.codeInsight.navigation.NavigationGutterIconBuilder;
import com.intellij.openapi.project.Project;
import com.intellij.psi.PsiElement;
import com.jetbrains.php.lang.psi.elements.PhpClass;
import de.espend.idea.php.drupal.DrupalProjectComponent;
import de.espend.idea.php.drupal.utils.IndexUtil;
import fr.adrienbrault.idea.symfony2plugin.Symfony2Icons;
import fr.adrienbrault.idea.symfony2plugin.config.yaml.YamlElementPatternHelper;
import fr.adrienbrault.idea.symfony2plugin.util.PhpElementsUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.yaml.psi.YAMLKeyValue;
import org.jetbrains.yaml.psi.YAMLMapping;
import org.jetbrains.yaml.psi.YAMLScalar;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
if(psiElements.size() == 0) {
return;
}
Project project = psiElements.get(0).getProject();
if(!DrupalProjectComponent.isEnabled(project)) {
return;
}
for (PsiElement psiElement : psiElements) {
collectRouteInlineClasses(results, project, psiElement);
}
}
private void collectRouteInlineClasses(@NotNull Collection<LineMarkerInfo> results, @NotNull Project project, @NotNull PsiElement psiElement) {
if(!(YamlElementPatternHelper.getSingleLineScalarKey("_form").accepts(psiElement) ||
YamlElementPatternHelper.getSingleLineScalarKey("_entity_form").accepts(psiElement))
) {
return;
}
PsiElement yamlScalar = psiElement.getParent();
if(!(yamlScalar instanceof YAMLScalar)) {
return;
}
String textValue = ((YAMLScalar) yamlScalar).getTextValue();
Collection<PhpClass> classesInterface = new ArrayList<>(PhpElementsUtil.getClassesInterface(project, textValue)); | classesInterface.addAll(IndexUtil.getFormClassForId(project, textValue)); |
Haehnchen/idea-php-drupal-symfony2-bridge | src/de/espend/idea/php/drupal/registrar/YamlRouteKeyCompletion.java | // Path: src/de/espend/idea/php/drupal/DrupalIcons.java
// public class DrupalIcons {
// public static final Icon DRUPAL = IconLoader.getIcon("icons/drupal.png");
// }
//
// Path: src/de/espend/idea/php/drupal/DrupalProjectComponent.java
// public class DrupalProjectComponent {
//
// public static boolean isEnabled(Project project) {
// return Symfony2ProjectComponent.isEnabled(project);
// }
//
// public static boolean isEnabled(@Nullable PsiElement psiElement) {
// return psiElement != null && isEnabled(psiElement.getProject());
// }
//
// }
| import com.intellij.codeInsight.lookup.LookupElement;
import com.intellij.codeInsight.lookup.LookupElementBuilder;
import com.intellij.patterns.PlatformPatterns;
import com.intellij.patterns.PsiElementPattern;
import com.intellij.psi.PsiElement;
import de.espend.idea.php.drupal.DrupalIcons;
import de.espend.idea.php.drupal.DrupalProjectComponent;
import fr.adrienbrault.idea.symfony2plugin.codeInsight.GotoCompletionProvider;
import fr.adrienbrault.idea.symfony2plugin.codeInsight.GotoCompletionRegistrar;
import fr.adrienbrault.idea.symfony2plugin.codeInsight.GotoCompletionRegistrarParameter;
import fr.adrienbrault.idea.symfony2plugin.config.yaml.YamlElementPatternHelper;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections; | package de.espend.idea.php.drupal.registrar;
/**
* @author Daniel Espendiller <daniel@espendiller.net>
*/
public class YamlRouteKeyCompletion implements GotoCompletionRegistrar {
@Override
public void register(GotoCompletionRegistrarParameter registrar) {
PsiElementPattern.Capture<PsiElement> filePattern = PlatformPatterns.psiElement().inFile(PlatformPatterns.psiFile().withName(PlatformPatterns.string().endsWith(".routing.yml")));
registrar.register(PlatformPatterns.and(YamlElementPatternHelper.getParentKeyName("defaults"), filePattern), psiElement -> { | // Path: src/de/espend/idea/php/drupal/DrupalIcons.java
// public class DrupalIcons {
// public static final Icon DRUPAL = IconLoader.getIcon("icons/drupal.png");
// }
//
// Path: src/de/espend/idea/php/drupal/DrupalProjectComponent.java
// public class DrupalProjectComponent {
//
// public static boolean isEnabled(Project project) {
// return Symfony2ProjectComponent.isEnabled(project);
// }
//
// public static boolean isEnabled(@Nullable PsiElement psiElement) {
// return psiElement != null && isEnabled(psiElement.getProject());
// }
//
// }
// Path: src/de/espend/idea/php/drupal/registrar/YamlRouteKeyCompletion.java
import com.intellij.codeInsight.lookup.LookupElement;
import com.intellij.codeInsight.lookup.LookupElementBuilder;
import com.intellij.patterns.PlatformPatterns;
import com.intellij.patterns.PsiElementPattern;
import com.intellij.psi.PsiElement;
import de.espend.idea.php.drupal.DrupalIcons;
import de.espend.idea.php.drupal.DrupalProjectComponent;
import fr.adrienbrault.idea.symfony2plugin.codeInsight.GotoCompletionProvider;
import fr.adrienbrault.idea.symfony2plugin.codeInsight.GotoCompletionRegistrar;
import fr.adrienbrault.idea.symfony2plugin.codeInsight.GotoCompletionRegistrarParameter;
import fr.adrienbrault.idea.symfony2plugin.config.yaml.YamlElementPatternHelper;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
package de.espend.idea.php.drupal.registrar;
/**
* @author Daniel Espendiller <daniel@espendiller.net>
*/
public class YamlRouteKeyCompletion implements GotoCompletionRegistrar {
@Override
public void register(GotoCompletionRegistrarParameter registrar) {
PsiElementPattern.Capture<PsiElement> filePattern = PlatformPatterns.psiElement().inFile(PlatformPatterns.psiFile().withName(PlatformPatterns.string().endsWith(".routing.yml")));
registrar.register(PlatformPatterns.and(YamlElementPatternHelper.getParentKeyName("defaults"), filePattern), psiElement -> { | if(!DrupalProjectComponent.isEnabled(psiElement)) { |
Haehnchen/idea-php-drupal-symfony2-bridge | src/de/espend/idea/php/drupal/registrar/YamlRouteKeyCompletion.java | // Path: src/de/espend/idea/php/drupal/DrupalIcons.java
// public class DrupalIcons {
// public static final Icon DRUPAL = IconLoader.getIcon("icons/drupal.png");
// }
//
// Path: src/de/espend/idea/php/drupal/DrupalProjectComponent.java
// public class DrupalProjectComponent {
//
// public static boolean isEnabled(Project project) {
// return Symfony2ProjectComponent.isEnabled(project);
// }
//
// public static boolean isEnabled(@Nullable PsiElement psiElement) {
// return psiElement != null && isEnabled(psiElement.getProject());
// }
//
// }
| import com.intellij.codeInsight.lookup.LookupElement;
import com.intellij.codeInsight.lookup.LookupElementBuilder;
import com.intellij.patterns.PlatformPatterns;
import com.intellij.patterns.PsiElementPattern;
import com.intellij.psi.PsiElement;
import de.espend.idea.php.drupal.DrupalIcons;
import de.espend.idea.php.drupal.DrupalProjectComponent;
import fr.adrienbrault.idea.symfony2plugin.codeInsight.GotoCompletionProvider;
import fr.adrienbrault.idea.symfony2plugin.codeInsight.GotoCompletionRegistrar;
import fr.adrienbrault.idea.symfony2plugin.codeInsight.GotoCompletionRegistrarParameter;
import fr.adrienbrault.idea.symfony2plugin.config.yaml.YamlElementPatternHelper;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections; | package de.espend.idea.php.drupal.registrar;
/**
* @author Daniel Espendiller <daniel@espendiller.net>
*/
public class YamlRouteKeyCompletion implements GotoCompletionRegistrar {
@Override
public void register(GotoCompletionRegistrarParameter registrar) {
PsiElementPattern.Capture<PsiElement> filePattern = PlatformPatterns.psiElement().inFile(PlatformPatterns.psiFile().withName(PlatformPatterns.string().endsWith(".routing.yml")));
registrar.register(PlatformPatterns.and(YamlElementPatternHelper.getParentKeyName("defaults"), filePattern), psiElement -> {
if(!DrupalProjectComponent.isEnabled(psiElement)) {
return null;
}
return new DefaultRoutes(psiElement);
});
registrar.register(PlatformPatterns.and(YamlElementPatternHelper.getParentKeyName("requirements"), filePattern), psiElement -> {
if(!DrupalProjectComponent.isEnabled(psiElement)) {
return null;
}
return new EntityAccessRoutes(psiElement);
});
}
private static class DefaultRoutes extends GotoCompletionProvider {
DefaultRoutes(PsiElement psiElement) {
super(psiElement);
}
@NotNull
@Override
public Collection<LookupElement> getLookupElements() {
Collection<LookupElement> lookupElements = new ArrayList<>();
for (String s : new String[]{"_entity_form", "_title_callback", "op", "_entity_access", "_entity_list", "_controller"}) { | // Path: src/de/espend/idea/php/drupal/DrupalIcons.java
// public class DrupalIcons {
// public static final Icon DRUPAL = IconLoader.getIcon("icons/drupal.png");
// }
//
// Path: src/de/espend/idea/php/drupal/DrupalProjectComponent.java
// public class DrupalProjectComponent {
//
// public static boolean isEnabled(Project project) {
// return Symfony2ProjectComponent.isEnabled(project);
// }
//
// public static boolean isEnabled(@Nullable PsiElement psiElement) {
// return psiElement != null && isEnabled(psiElement.getProject());
// }
//
// }
// Path: src/de/espend/idea/php/drupal/registrar/YamlRouteKeyCompletion.java
import com.intellij.codeInsight.lookup.LookupElement;
import com.intellij.codeInsight.lookup.LookupElementBuilder;
import com.intellij.patterns.PlatformPatterns;
import com.intellij.patterns.PsiElementPattern;
import com.intellij.psi.PsiElement;
import de.espend.idea.php.drupal.DrupalIcons;
import de.espend.idea.php.drupal.DrupalProjectComponent;
import fr.adrienbrault.idea.symfony2plugin.codeInsight.GotoCompletionProvider;
import fr.adrienbrault.idea.symfony2plugin.codeInsight.GotoCompletionRegistrar;
import fr.adrienbrault.idea.symfony2plugin.codeInsight.GotoCompletionRegistrarParameter;
import fr.adrienbrault.idea.symfony2plugin.config.yaml.YamlElementPatternHelper;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
package de.espend.idea.php.drupal.registrar;
/**
* @author Daniel Espendiller <daniel@espendiller.net>
*/
public class YamlRouteKeyCompletion implements GotoCompletionRegistrar {
@Override
public void register(GotoCompletionRegistrarParameter registrar) {
PsiElementPattern.Capture<PsiElement> filePattern = PlatformPatterns.psiElement().inFile(PlatformPatterns.psiFile().withName(PlatformPatterns.string().endsWith(".routing.yml")));
registrar.register(PlatformPatterns.and(YamlElementPatternHelper.getParentKeyName("defaults"), filePattern), psiElement -> {
if(!DrupalProjectComponent.isEnabled(psiElement)) {
return null;
}
return new DefaultRoutes(psiElement);
});
registrar.register(PlatformPatterns.and(YamlElementPatternHelper.getParentKeyName("requirements"), filePattern), psiElement -> {
if(!DrupalProjectComponent.isEnabled(psiElement)) {
return null;
}
return new EntityAccessRoutes(psiElement);
});
}
private static class DefaultRoutes extends GotoCompletionProvider {
DefaultRoutes(PsiElement psiElement) {
super(psiElement);
}
@NotNull
@Override
public Collection<LookupElement> getLookupElements() {
Collection<LookupElement> lookupElements = new ArrayList<>();
for (String s : new String[]{"_entity_form", "_title_callback", "op", "_entity_access", "_entity_list", "_controller"}) { | lookupElements.add(LookupElementBuilder.create(s).withIcon(DrupalIcons.DRUPAL).withTypeText("Routing", true)); |
Haehnchen/idea-php-drupal-symfony2-bridge | src/de/espend/idea/php/drupal/references/PhpRouteReferenceContributor.java | // Path: src/de/espend/idea/php/drupal/DrupalProjectComponent.java
// public class DrupalProjectComponent {
//
// public static boolean isEnabled(Project project) {
// return Symfony2ProjectComponent.isEnabled(project);
// }
//
// public static boolean isEnabled(@Nullable PsiElement psiElement) {
// return psiElement != null && isEnabled(psiElement.getProject());
// }
//
// }
| import com.intellij.patterns.PlatformPatterns;
import com.intellij.psi.*;
import com.intellij.util.ProcessingContext;
import com.jetbrains.php.lang.PhpLanguage;
import com.jetbrains.php.lang.psi.elements.ClassReference;
import com.jetbrains.php.lang.psi.elements.NewExpression;
import com.jetbrains.php.lang.psi.elements.ParameterList;
import com.jetbrains.php.lang.psi.elements.StringLiteralExpression;
import de.espend.idea.php.drupal.DrupalProjectComponent;
import fr.adrienbrault.idea.symfony2plugin.Symfony2ProjectComponent;
import fr.adrienbrault.idea.symfony2plugin.routing.RouteParameterReference;
import fr.adrienbrault.idea.symfony2plugin.routing.RouteReference;
import fr.adrienbrault.idea.symfony2plugin.util.MethodMatcher;
import fr.adrienbrault.idea.symfony2plugin.util.PsiElementUtils;
import org.jetbrains.annotations.NotNull; | package de.espend.idea.php.drupal.references;
/**
* @author Daniel Espendiller <daniel@espendiller.net>
*/
public class PhpRouteReferenceContributor extends PsiReferenceContributor {
final private static MethodMatcher.CallToSignature[] GENERATOR_SIGNATURES = new MethodMatcher.CallToSignature[] {
new MethodMatcher.CallToSignature("\\Drupal\\Core\\Routing\\UrlGeneratorInterface", "getPathFromRoute"), // <- <@TODO: remove: pre Drupal8 beta
new MethodMatcher.CallToSignature("\\Drupal\\Core\\Routing\\UrlGeneratorInterface", "generateFromRoute"), // <- <@TODO: remove: pre Drupal8 beta
new MethodMatcher.CallToSignature("\\Drupal\\Core\\Routing\\UrlGenerator", "getPathFromRoute"),
new MethodMatcher.CallToSignature("\\Drupal\\Core\\Routing\\UrlGenerator", "generateFromRoute"),
new MethodMatcher.CallToSignature("\\Drupal\\Core\\Url", "fromRoute"),
new MethodMatcher.CallToSignature("\\Drupal\\Core\\Form\\FormStateInterface", "setRedirect"),
new MethodMatcher.CallToSignature("\\Drupal", "url"),
};
@Override
public void registerReferenceProviders(@NotNull PsiReferenceRegistrar psiReferenceRegistrar) {
psiReferenceRegistrar.registerReferenceProvider(
PlatformPatterns.psiElement(StringLiteralExpression.class).withLanguage(PhpLanguage.INSTANCE),
new PsiReferenceProvider() {
@NotNull
@Override
public PsiReference[] getReferencesByElement(@NotNull PsiElement psiElement, @NotNull ProcessingContext processingContext) {
| // Path: src/de/espend/idea/php/drupal/DrupalProjectComponent.java
// public class DrupalProjectComponent {
//
// public static boolean isEnabled(Project project) {
// return Symfony2ProjectComponent.isEnabled(project);
// }
//
// public static boolean isEnabled(@Nullable PsiElement psiElement) {
// return psiElement != null && isEnabled(psiElement.getProject());
// }
//
// }
// Path: src/de/espend/idea/php/drupal/references/PhpRouteReferenceContributor.java
import com.intellij.patterns.PlatformPatterns;
import com.intellij.psi.*;
import com.intellij.util.ProcessingContext;
import com.jetbrains.php.lang.PhpLanguage;
import com.jetbrains.php.lang.psi.elements.ClassReference;
import com.jetbrains.php.lang.psi.elements.NewExpression;
import com.jetbrains.php.lang.psi.elements.ParameterList;
import com.jetbrains.php.lang.psi.elements.StringLiteralExpression;
import de.espend.idea.php.drupal.DrupalProjectComponent;
import fr.adrienbrault.idea.symfony2plugin.Symfony2ProjectComponent;
import fr.adrienbrault.idea.symfony2plugin.routing.RouteParameterReference;
import fr.adrienbrault.idea.symfony2plugin.routing.RouteReference;
import fr.adrienbrault.idea.symfony2plugin.util.MethodMatcher;
import fr.adrienbrault.idea.symfony2plugin.util.PsiElementUtils;
import org.jetbrains.annotations.NotNull;
package de.espend.idea.php.drupal.references;
/**
* @author Daniel Espendiller <daniel@espendiller.net>
*/
public class PhpRouteReferenceContributor extends PsiReferenceContributor {
final private static MethodMatcher.CallToSignature[] GENERATOR_SIGNATURES = new MethodMatcher.CallToSignature[] {
new MethodMatcher.CallToSignature("\\Drupal\\Core\\Routing\\UrlGeneratorInterface", "getPathFromRoute"), // <- <@TODO: remove: pre Drupal8 beta
new MethodMatcher.CallToSignature("\\Drupal\\Core\\Routing\\UrlGeneratorInterface", "generateFromRoute"), // <- <@TODO: remove: pre Drupal8 beta
new MethodMatcher.CallToSignature("\\Drupal\\Core\\Routing\\UrlGenerator", "getPathFromRoute"),
new MethodMatcher.CallToSignature("\\Drupal\\Core\\Routing\\UrlGenerator", "generateFromRoute"),
new MethodMatcher.CallToSignature("\\Drupal\\Core\\Url", "fromRoute"),
new MethodMatcher.CallToSignature("\\Drupal\\Core\\Form\\FormStateInterface", "setRedirect"),
new MethodMatcher.CallToSignature("\\Drupal", "url"),
};
@Override
public void registerReferenceProviders(@NotNull PsiReferenceRegistrar psiReferenceRegistrar) {
psiReferenceRegistrar.registerReferenceProvider(
PlatformPatterns.psiElement(StringLiteralExpression.class).withLanguage(PhpLanguage.INSTANCE),
new PsiReferenceProvider() {
@NotNull
@Override
public PsiReference[] getReferencesByElement(@NotNull PsiElement psiElement, @NotNull ProcessingContext processingContext) {
| if(!DrupalProjectComponent.isEnabled(psiElement)) { |
bourgesl/marlin-fx | src/main/java/com/sun/marlin/Helpers.java | // Path: src/main/java/com/sun/marlin/stats/Histogram.java
// public final class Histogram extends StatLong {
//
// static final int BUCKET = 2;
// static final int MAX = 20;
// static final int LAST = MAX - 1;
// static final int[] STEPS = new int[MAX];
//
// static {
// STEPS[0] = 0;
// STEPS[1] = 1;
//
// for (int i = 2; i < MAX; i++) {
// STEPS[i] = STEPS[i - 1] * BUCKET;
// }
// }
//
// static int bucket(int val) {
// for (int i = 1; i < MAX; i++) {
// if (val < STEPS[i]) {
// return i - 1;
// }
// }
// return LAST;
// }
//
// private final StatLong[] stats = new StatLong[MAX];
//
// public Histogram(final String name) {
// super(name);
// for (int i = 0; i < MAX; i++) {
// stats[i] = new StatLong(String.format("%5s .. %5s", STEPS[i],
// ((i + 1 < MAX) ? STEPS[i + 1] : "~")));
// }
// }
//
// @Override
// public void reset() {
// super.reset();
// for (int i = 0; i < MAX; i++) {
// stats[i].reset();
// }
// }
//
// @Override
// public void add(int val) {
// super.add(val);
// stats[bucket(val)].add(val);
// }
//
// @Override
// public void add(long val) {
// add((int) val);
// }
//
// @Override
// public String toString() {
// final StringBuilder sb = new StringBuilder(2048);
// super.toString(sb).append(" { ");
//
// for (int i = 0; i < MAX; i++) {
// if (stats[i].count != 0l) {
// sb.append("\n ").append(stats[i].toString());
// }
// }
//
// return sb.append(" }").toString();
// }
// }
//
// Path: src/main/java/com/sun/marlin/stats/StatLong.java
// public class StatLong {
//
// public final String name;
// public long count = 0l;
// public long sum = 0l;
// public long min = Integer.MAX_VALUE;
// public long max = Integer.MIN_VALUE;
//
// public StatLong(final String name) {
// this.name = name;
// }
//
// public void reset() {
// count = 0l;
// sum = 0l;
// min = Integer.MAX_VALUE;
// max = Integer.MIN_VALUE;
// }
//
// public void add(final int val) {
// count++;
// sum += val;
// if (val < min) {
// min = val;
// }
// if (val > max) {
// max = val;
// }
// }
//
// public void add(final long val) {
// count++;
// sum += val;
// if (val < min) {
// min = val;
// }
// if (val > max) {
// max = val;
// }
// }
//
// @Override
// public String toString() {
// return toString(new StringBuilder(128)).toString();
// }
//
// public final StringBuilder toString(final StringBuilder sb) {
// sb.append(name).append('[').append(count);
// sb.append("] sum: ").append(sum).append(" avg: ");
// sb.append(trimTo3Digits(((double) sum) / count));
// sb.append(" [").append(min).append(" | ").append(max).append("]");
// return sb;
// }
//
// /**
// * Adjust the given double value to keep only 3 decimal digits
// *
// * @param value value to adjust
// * @return double value with only 3 decimal digits
// */
// public static double trimTo3Digits(final double value) {
// return ((long) (1e3d * value)) / 1e3d;
// }
// }
| import com.sun.javafx.geom.PathConsumer2D;
import java.util.Arrays;
import com.sun.marlin.stats.Histogram;
import com.sun.marlin.stats.StatLong; | return code;
}
// a stack of polynomial curves where each curve shares endpoints with
// adjacent ones.
static final class PolyStack {
private static final byte TYPE_LINETO = (byte) 0;
private static final byte TYPE_QUADTO = (byte) 1;
private static final byte TYPE_CUBICTO = (byte) 2;
// curves capacity = edges count (8192) = edges x 2 (coords)
private static final int INITIAL_CURVES_COUNT = INITIAL_EDGES_COUNT << 1;
// types capacity = edges count (4096)
private static final int INITIAL_TYPES_COUNT = INITIAL_EDGES_COUNT;
float[] curves;
int end;
byte[] curveTypes;
int numCurves;
// curves ref (dirty)
final FloatArrayCache.Reference curves_ref;
// curveTypes ref (dirty)
final ByteArrayCache.Reference curveTypes_ref;
// used marks (stats only)
int curveTypesUseMark;
int curvesUseMark;
| // Path: src/main/java/com/sun/marlin/stats/Histogram.java
// public final class Histogram extends StatLong {
//
// static final int BUCKET = 2;
// static final int MAX = 20;
// static final int LAST = MAX - 1;
// static final int[] STEPS = new int[MAX];
//
// static {
// STEPS[0] = 0;
// STEPS[1] = 1;
//
// for (int i = 2; i < MAX; i++) {
// STEPS[i] = STEPS[i - 1] * BUCKET;
// }
// }
//
// static int bucket(int val) {
// for (int i = 1; i < MAX; i++) {
// if (val < STEPS[i]) {
// return i - 1;
// }
// }
// return LAST;
// }
//
// private final StatLong[] stats = new StatLong[MAX];
//
// public Histogram(final String name) {
// super(name);
// for (int i = 0; i < MAX; i++) {
// stats[i] = new StatLong(String.format("%5s .. %5s", STEPS[i],
// ((i + 1 < MAX) ? STEPS[i + 1] : "~")));
// }
// }
//
// @Override
// public void reset() {
// super.reset();
// for (int i = 0; i < MAX; i++) {
// stats[i].reset();
// }
// }
//
// @Override
// public void add(int val) {
// super.add(val);
// stats[bucket(val)].add(val);
// }
//
// @Override
// public void add(long val) {
// add((int) val);
// }
//
// @Override
// public String toString() {
// final StringBuilder sb = new StringBuilder(2048);
// super.toString(sb).append(" { ");
//
// for (int i = 0; i < MAX; i++) {
// if (stats[i].count != 0l) {
// sb.append("\n ").append(stats[i].toString());
// }
// }
//
// return sb.append(" }").toString();
// }
// }
//
// Path: src/main/java/com/sun/marlin/stats/StatLong.java
// public class StatLong {
//
// public final String name;
// public long count = 0l;
// public long sum = 0l;
// public long min = Integer.MAX_VALUE;
// public long max = Integer.MIN_VALUE;
//
// public StatLong(final String name) {
// this.name = name;
// }
//
// public void reset() {
// count = 0l;
// sum = 0l;
// min = Integer.MAX_VALUE;
// max = Integer.MIN_VALUE;
// }
//
// public void add(final int val) {
// count++;
// sum += val;
// if (val < min) {
// min = val;
// }
// if (val > max) {
// max = val;
// }
// }
//
// public void add(final long val) {
// count++;
// sum += val;
// if (val < min) {
// min = val;
// }
// if (val > max) {
// max = val;
// }
// }
//
// @Override
// public String toString() {
// return toString(new StringBuilder(128)).toString();
// }
//
// public final StringBuilder toString(final StringBuilder sb) {
// sb.append(name).append('[').append(count);
// sb.append("] sum: ").append(sum).append(" avg: ");
// sb.append(trimTo3Digits(((double) sum) / count));
// sb.append(" [").append(min).append(" | ").append(max).append("]");
// return sb;
// }
//
// /**
// * Adjust the given double value to keep only 3 decimal digits
// *
// * @param value value to adjust
// * @return double value with only 3 decimal digits
// */
// public static double trimTo3Digits(final double value) {
// return ((long) (1e3d * value)) / 1e3d;
// }
// }
// Path: src/main/java/com/sun/marlin/Helpers.java
import com.sun.javafx.geom.PathConsumer2D;
import java.util.Arrays;
import com.sun.marlin.stats.Histogram;
import com.sun.marlin.stats.StatLong;
return code;
}
// a stack of polynomial curves where each curve shares endpoints with
// adjacent ones.
static final class PolyStack {
private static final byte TYPE_LINETO = (byte) 0;
private static final byte TYPE_QUADTO = (byte) 1;
private static final byte TYPE_CUBICTO = (byte) 2;
// curves capacity = edges count (8192) = edges x 2 (coords)
private static final int INITIAL_CURVES_COUNT = INITIAL_EDGES_COUNT << 1;
// types capacity = edges count (4096)
private static final int INITIAL_TYPES_COUNT = INITIAL_EDGES_COUNT;
float[] curves;
int end;
byte[] curveTypes;
int numCurves;
// curves ref (dirty)
final FloatArrayCache.Reference curves_ref;
// curveTypes ref (dirty)
final ByteArrayCache.Reference curveTypes_ref;
// used marks (stats only)
int curveTypesUseMark;
int curvesUseMark;
| private final StatLong stat_polystack_types; |
bourgesl/marlin-fx | src/main/java/com/sun/marlin/Helpers.java | // Path: src/main/java/com/sun/marlin/stats/Histogram.java
// public final class Histogram extends StatLong {
//
// static final int BUCKET = 2;
// static final int MAX = 20;
// static final int LAST = MAX - 1;
// static final int[] STEPS = new int[MAX];
//
// static {
// STEPS[0] = 0;
// STEPS[1] = 1;
//
// for (int i = 2; i < MAX; i++) {
// STEPS[i] = STEPS[i - 1] * BUCKET;
// }
// }
//
// static int bucket(int val) {
// for (int i = 1; i < MAX; i++) {
// if (val < STEPS[i]) {
// return i - 1;
// }
// }
// return LAST;
// }
//
// private final StatLong[] stats = new StatLong[MAX];
//
// public Histogram(final String name) {
// super(name);
// for (int i = 0; i < MAX; i++) {
// stats[i] = new StatLong(String.format("%5s .. %5s", STEPS[i],
// ((i + 1 < MAX) ? STEPS[i + 1] : "~")));
// }
// }
//
// @Override
// public void reset() {
// super.reset();
// for (int i = 0; i < MAX; i++) {
// stats[i].reset();
// }
// }
//
// @Override
// public void add(int val) {
// super.add(val);
// stats[bucket(val)].add(val);
// }
//
// @Override
// public void add(long val) {
// add((int) val);
// }
//
// @Override
// public String toString() {
// final StringBuilder sb = new StringBuilder(2048);
// super.toString(sb).append(" { ");
//
// for (int i = 0; i < MAX; i++) {
// if (stats[i].count != 0l) {
// sb.append("\n ").append(stats[i].toString());
// }
// }
//
// return sb.append(" }").toString();
// }
// }
//
// Path: src/main/java/com/sun/marlin/stats/StatLong.java
// public class StatLong {
//
// public final String name;
// public long count = 0l;
// public long sum = 0l;
// public long min = Integer.MAX_VALUE;
// public long max = Integer.MIN_VALUE;
//
// public StatLong(final String name) {
// this.name = name;
// }
//
// public void reset() {
// count = 0l;
// sum = 0l;
// min = Integer.MAX_VALUE;
// max = Integer.MIN_VALUE;
// }
//
// public void add(final int val) {
// count++;
// sum += val;
// if (val < min) {
// min = val;
// }
// if (val > max) {
// max = val;
// }
// }
//
// public void add(final long val) {
// count++;
// sum += val;
// if (val < min) {
// min = val;
// }
// if (val > max) {
// max = val;
// }
// }
//
// @Override
// public String toString() {
// return toString(new StringBuilder(128)).toString();
// }
//
// public final StringBuilder toString(final StringBuilder sb) {
// sb.append(name).append('[').append(count);
// sb.append("] sum: ").append(sum).append(" avg: ");
// sb.append(trimTo3Digits(((double) sum) / count));
// sb.append(" [").append(min).append(" | ").append(max).append("]");
// return sb;
// }
//
// /**
// * Adjust the given double value to keep only 3 decimal digits
// *
// * @param value value to adjust
// * @return double value with only 3 decimal digits
// */
// public static double trimTo3Digits(final double value) {
// return ((long) (1e3d * value)) / 1e3d;
// }
// }
| import com.sun.javafx.geom.PathConsumer2D;
import java.util.Arrays;
import com.sun.marlin.stats.Histogram;
import com.sun.marlin.stats.StatLong; |
// a stack of polynomial curves where each curve shares endpoints with
// adjacent ones.
static final class PolyStack {
private static final byte TYPE_LINETO = (byte) 0;
private static final byte TYPE_QUADTO = (byte) 1;
private static final byte TYPE_CUBICTO = (byte) 2;
// curves capacity = edges count (8192) = edges x 2 (coords)
private static final int INITIAL_CURVES_COUNT = INITIAL_EDGES_COUNT << 1;
// types capacity = edges count (4096)
private static final int INITIAL_TYPES_COUNT = INITIAL_EDGES_COUNT;
float[] curves;
int end;
byte[] curveTypes;
int numCurves;
// curves ref (dirty)
final FloatArrayCache.Reference curves_ref;
// curveTypes ref (dirty)
final ByteArrayCache.Reference curveTypes_ref;
// used marks (stats only)
int curveTypesUseMark;
int curvesUseMark;
private final StatLong stat_polystack_types;
private final StatLong stat_polystack_curves; | // Path: src/main/java/com/sun/marlin/stats/Histogram.java
// public final class Histogram extends StatLong {
//
// static final int BUCKET = 2;
// static final int MAX = 20;
// static final int LAST = MAX - 1;
// static final int[] STEPS = new int[MAX];
//
// static {
// STEPS[0] = 0;
// STEPS[1] = 1;
//
// for (int i = 2; i < MAX; i++) {
// STEPS[i] = STEPS[i - 1] * BUCKET;
// }
// }
//
// static int bucket(int val) {
// for (int i = 1; i < MAX; i++) {
// if (val < STEPS[i]) {
// return i - 1;
// }
// }
// return LAST;
// }
//
// private final StatLong[] stats = new StatLong[MAX];
//
// public Histogram(final String name) {
// super(name);
// for (int i = 0; i < MAX; i++) {
// stats[i] = new StatLong(String.format("%5s .. %5s", STEPS[i],
// ((i + 1 < MAX) ? STEPS[i + 1] : "~")));
// }
// }
//
// @Override
// public void reset() {
// super.reset();
// for (int i = 0; i < MAX; i++) {
// stats[i].reset();
// }
// }
//
// @Override
// public void add(int val) {
// super.add(val);
// stats[bucket(val)].add(val);
// }
//
// @Override
// public void add(long val) {
// add((int) val);
// }
//
// @Override
// public String toString() {
// final StringBuilder sb = new StringBuilder(2048);
// super.toString(sb).append(" { ");
//
// for (int i = 0; i < MAX; i++) {
// if (stats[i].count != 0l) {
// sb.append("\n ").append(stats[i].toString());
// }
// }
//
// return sb.append(" }").toString();
// }
// }
//
// Path: src/main/java/com/sun/marlin/stats/StatLong.java
// public class StatLong {
//
// public final String name;
// public long count = 0l;
// public long sum = 0l;
// public long min = Integer.MAX_VALUE;
// public long max = Integer.MIN_VALUE;
//
// public StatLong(final String name) {
// this.name = name;
// }
//
// public void reset() {
// count = 0l;
// sum = 0l;
// min = Integer.MAX_VALUE;
// max = Integer.MIN_VALUE;
// }
//
// public void add(final int val) {
// count++;
// sum += val;
// if (val < min) {
// min = val;
// }
// if (val > max) {
// max = val;
// }
// }
//
// public void add(final long val) {
// count++;
// sum += val;
// if (val < min) {
// min = val;
// }
// if (val > max) {
// max = val;
// }
// }
//
// @Override
// public String toString() {
// return toString(new StringBuilder(128)).toString();
// }
//
// public final StringBuilder toString(final StringBuilder sb) {
// sb.append(name).append('[').append(count);
// sb.append("] sum: ").append(sum).append(" avg: ");
// sb.append(trimTo3Digits(((double) sum) / count));
// sb.append(" [").append(min).append(" | ").append(max).append("]");
// return sb;
// }
//
// /**
// * Adjust the given double value to keep only 3 decimal digits
// *
// * @param value value to adjust
// * @return double value with only 3 decimal digits
// */
// public static double trimTo3Digits(final double value) {
// return ((long) (1e3d * value)) / 1e3d;
// }
// }
// Path: src/main/java/com/sun/marlin/Helpers.java
import com.sun.javafx.geom.PathConsumer2D;
import java.util.Arrays;
import com.sun.marlin.stats.Histogram;
import com.sun.marlin.stats.StatLong;
// a stack of polynomial curves where each curve shares endpoints with
// adjacent ones.
static final class PolyStack {
private static final byte TYPE_LINETO = (byte) 0;
private static final byte TYPE_QUADTO = (byte) 1;
private static final byte TYPE_CUBICTO = (byte) 2;
// curves capacity = edges count (8192) = edges x 2 (coords)
private static final int INITIAL_CURVES_COUNT = INITIAL_EDGES_COUNT << 1;
// types capacity = edges count (4096)
private static final int INITIAL_TYPES_COUNT = INITIAL_EDGES_COUNT;
float[] curves;
int end;
byte[] curveTypes;
int numCurves;
// curves ref (dirty)
final FloatArrayCache.Reference curves_ref;
// curveTypes ref (dirty)
final ByteArrayCache.Reference curveTypes_ref;
// used marks (stats only)
int curveTypesUseMark;
int curvesUseMark;
private final StatLong stat_polystack_types;
private final StatLong stat_polystack_curves; | private final Histogram hist_polystack_curves; |
bourgesl/marlin-fx | src/main/java/com/sun/marlin/DRenderer.java | // Path: src/main/java/com/sun/marlin/OffHeapArray.java
// static final int SIZE_INT;
| import static com.sun.marlin.OffHeapArray.SIZE_INT;
import sun.misc.Unsafe; | /*
* Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code 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 General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.marlin;
public final class DRenderer implements DMarlinRenderer, MarlinConst {
static final boolean DISABLE_RENDER = false;
private static final int ALL_BUT_LSB = 0xFFFFFFFE;
private static final int ERR_STEP_MAX = 0x7FFFFFFF; // = 2^31 - 1
private static final double POWER_2_TO_32 = 0x1.0p32d;
// use double to make tosubpix methods faster (no int to double conversion)
static final double SUBPIXEL_SCALE_X = SUBPIXEL_POSITIONS_X;
static final double SUBPIXEL_SCALE_Y = SUBPIXEL_POSITIONS_Y;
static final int SUBPIXEL_MASK_X = SUBPIXEL_POSITIONS_X - 1;
static final int SUBPIXEL_MASK_Y = SUBPIXEL_POSITIONS_Y - 1;
private static final double RDR_OFFSET_X = 0.5d / SUBPIXEL_SCALE_X;
private static final double RDR_OFFSET_Y = 0.5d / SUBPIXEL_SCALE_Y;
// common to all types of input path segments.
// OFFSET as bytes
// only integer values:
public static final long OFF_CURX_OR = 0; | // Path: src/main/java/com/sun/marlin/OffHeapArray.java
// static final int SIZE_INT;
// Path: src/main/java/com/sun/marlin/DRenderer.java
import static com.sun.marlin.OffHeapArray.SIZE_INT;
import sun.misc.Unsafe;
/*
* Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code 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 General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.marlin;
public final class DRenderer implements DMarlinRenderer, MarlinConst {
static final boolean DISABLE_RENDER = false;
private static final int ALL_BUT_LSB = 0xFFFFFFFE;
private static final int ERR_STEP_MAX = 0x7FFFFFFF; // = 2^31 - 1
private static final double POWER_2_TO_32 = 0x1.0p32d;
// use double to make tosubpix methods faster (no int to double conversion)
static final double SUBPIXEL_SCALE_X = SUBPIXEL_POSITIONS_X;
static final double SUBPIXEL_SCALE_Y = SUBPIXEL_POSITIONS_Y;
static final int SUBPIXEL_MASK_X = SUBPIXEL_POSITIONS_X - 1;
static final int SUBPIXEL_MASK_Y = SUBPIXEL_POSITIONS_Y - 1;
private static final double RDR_OFFSET_X = 0.5d / SUBPIXEL_SCALE_X;
private static final double RDR_OFFSET_Y = 0.5d / SUBPIXEL_SCALE_Y;
// common to all types of input path segments.
// OFFSET as bytes
// only integer values:
public static final long OFF_CURX_OR = 0; | public static final long OFF_ERROR = OFF_CURX_OR + SIZE_INT; |
bourgesl/marlin-fx | src/main/java/com/sun/marlin/RendererNoAA.java | // Path: src/main/java/com/sun/marlin/OffHeapArray.java
// static final int SIZE_INT;
| import static com.sun.marlin.OffHeapArray.SIZE_INT;
import sun.misc.Unsafe; | /*
* Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code 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 General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.marlin;
public final class RendererNoAA implements MarlinRenderer, MarlinConst {
static final boolean DISABLE_RENDER = false;
private static final int ALL_BUT_LSB = 0xFFFFFFFE;
private static final int ERR_STEP_MAX = 0x7FFFFFFF; // = 2^31 - 1
private static final double POWER_2_TO_32 = 0x1.0p32d;
private static final float RDR_OFFSET_X = 0.5f;
private static final float RDR_OFFSET_Y = 0.5f;
// common to all types of input path segments.
// OFFSET as bytes
// only integer values:
public static final long OFF_CURX_OR = 0; | // Path: src/main/java/com/sun/marlin/OffHeapArray.java
// static final int SIZE_INT;
// Path: src/main/java/com/sun/marlin/RendererNoAA.java
import static com.sun.marlin.OffHeapArray.SIZE_INT;
import sun.misc.Unsafe;
/*
* Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code 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 General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.marlin;
public final class RendererNoAA implements MarlinRenderer, MarlinConst {
static final boolean DISABLE_RENDER = false;
private static final int ALL_BUT_LSB = 0xFFFFFFFE;
private static final int ERR_STEP_MAX = 0x7FFFFFFF; // = 2^31 - 1
private static final double POWER_2_TO_32 = 0x1.0p32d;
private static final float RDR_OFFSET_X = 0.5f;
private static final float RDR_OFFSET_Y = 0.5f;
// common to all types of input path segments.
// OFFSET as bytes
// only integer values:
public static final long OFF_CURX_OR = 0; | public static final long OFF_ERROR = OFF_CURX_OR + SIZE_INT; |
bourgesl/marlin-fx | src/main/java/com/sun/marlin/Renderer.java | // Path: src/main/java/com/sun/marlin/OffHeapArray.java
// static final int SIZE_INT;
| import static com.sun.marlin.OffHeapArray.SIZE_INT;
import sun.misc.Unsafe; | /*
* Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code 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 General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.marlin;
public final class Renderer implements MarlinRenderer, MarlinConst {
static final boolean DISABLE_RENDER = false;
private static final int ALL_BUT_LSB = 0xFFFFFFFE;
private static final int ERR_STEP_MAX = 0x7FFFFFFF; // = 2^31 - 1
private static final double POWER_2_TO_32 = 0x1.0p32d;
// use float to make tosubpix methods faster (no int to float conversion)
static final float SUBPIXEL_SCALE_X = (float) SUBPIXEL_POSITIONS_X;
static final float SUBPIXEL_SCALE_Y = (float) SUBPIXEL_POSITIONS_Y;
static final int SUBPIXEL_MASK_X = SUBPIXEL_POSITIONS_X - 1;
static final int SUBPIXEL_MASK_Y = SUBPIXEL_POSITIONS_Y - 1;
private static final float RDR_OFFSET_X = 0.5f / SUBPIXEL_SCALE_X;
private static final float RDR_OFFSET_Y = 0.5f / SUBPIXEL_SCALE_Y;
// common to all types of input path segments.
// OFFSET as bytes
// only integer values:
public static final long OFF_CURX_OR = 0; | // Path: src/main/java/com/sun/marlin/OffHeapArray.java
// static final int SIZE_INT;
// Path: src/main/java/com/sun/marlin/Renderer.java
import static com.sun.marlin.OffHeapArray.SIZE_INT;
import sun.misc.Unsafe;
/*
* Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code 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 General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.marlin;
public final class Renderer implements MarlinRenderer, MarlinConst {
static final boolean DISABLE_RENDER = false;
private static final int ALL_BUT_LSB = 0xFFFFFFFE;
private static final int ERR_STEP_MAX = 0x7FFFFFFF; // = 2^31 - 1
private static final double POWER_2_TO_32 = 0x1.0p32d;
// use float to make tosubpix methods faster (no int to float conversion)
static final float SUBPIXEL_SCALE_X = (float) SUBPIXEL_POSITIONS_X;
static final float SUBPIXEL_SCALE_Y = (float) SUBPIXEL_POSITIONS_Y;
static final int SUBPIXEL_MASK_X = SUBPIXEL_POSITIONS_X - 1;
static final int SUBPIXEL_MASK_Y = SUBPIXEL_POSITIONS_Y - 1;
private static final float RDR_OFFSET_X = 0.5f / SUBPIXEL_SCALE_X;
private static final float RDR_OFFSET_Y = 0.5f / SUBPIXEL_SCALE_Y;
// common to all types of input path segments.
// OFFSET as bytes
// only integer values:
public static final long OFF_CURX_OR = 0; | public static final long OFF_ERROR = OFF_CURX_OR + SIZE_INT; |
bourgesl/marlin-fx | src/main/java/com/sun/marlin/ByteArrayCache.java | // Path: src/main/java/com/sun/marlin/ArrayCacheConst.java
// static final int[] ARRAY_SIZES = new int[BUCKETS];
//
// Path: src/main/java/com/sun/marlin/ArrayCacheConst.java
// static final int BUCKETS = 8;
//
// Path: src/main/java/com/sun/marlin/ArrayCacheConst.java
// static final int MAX_ARRAY_SIZE;
//
// Path: src/main/java/com/sun/marlin/MarlinUtils.java
// public static void logInfo(final String msg) {
// if (MarlinConst.USE_LOGGER) {
// LOG.info(msg);
// } else if (MarlinConst.ENABLE_LOGS) {
// System.out.print("INFO: ");
// System.out.println(msg);
// }
// }
//
// Path: src/main/java/com/sun/marlin/MarlinUtils.java
// public static void logException(final String msg, final Throwable th) {
// if (MarlinConst.USE_LOGGER) {
// LOG.log(java.util.logging.Level.WARNING, msg, th);
// } else if (MarlinConst.ENABLE_LOGS) {
// System.out.print("WARNING: ");
// System.out.println(msg);
// th.printStackTrace(System.err);
// }
// }
//
// Path: src/main/java/com/sun/marlin/ArrayCacheConst.java
// static final class BucketStats {
// int getOp = 0;
// int createOp = 0;
// int returnOp = 0;
// int maxSize = 0;
//
// void reset() {
// getOp = 0;
// createOp = 0;
// returnOp = 0;
// maxSize = 0;
// }
//
// void updateMaxSize(final int size) {
// if (size > maxSize) {
// maxSize = size;
// }
// }
// }
//
// Path: src/main/java/com/sun/marlin/ArrayCacheConst.java
// static final class CacheStats {
// final String name;
// final BucketStats[] bucketStats;
// int resize = 0;
// int oversize = 0;
// long totalInitial = 0L;
//
// CacheStats(final String name) {
// this.name = name;
//
// bucketStats = new BucketStats[BUCKETS];
// for (int i = 0; i < BUCKETS; i++) {
// bucketStats[i] = new BucketStats();
// }
// }
//
// void reset() {
// resize = 0;
// oversize = 0;
//
// for (int i = 0; i < BUCKETS; i++) {
// bucketStats[i].reset();
// }
// }
//
// long dumpStats() {
// long totalCacheBytes = 0L;
//
// if (DO_STATS) {
// for (int i = 0; i < BUCKETS; i++) {
// final BucketStats s = bucketStats[i];
//
// if (s.maxSize != 0) {
// totalCacheBytes += getByteFactor()
// * (s.maxSize * ARRAY_SIZES[i]);
// }
// }
//
// if (totalInitial != 0L || totalCacheBytes != 0L
// || resize != 0 || oversize != 0)
// {
// logInfo(name + ": resize: " + resize
// + " - oversize: " + oversize
// + " - initial: " + getTotalInitialBytes()
// + " bytes (" + totalInitial + " elements)"
// + " - cache: " + totalCacheBytes + " bytes"
// );
// }
//
// if (totalCacheBytes != 0L) {
// logInfo(name + ": usage stats:");
//
// for (int i = 0; i < BUCKETS; i++) {
// final BucketStats s = bucketStats[i];
//
// if (s.getOp != 0) {
// logInfo(" Bucket[" + ARRAY_SIZES[i] + "]: "
// + "get: " + s.getOp
// + " - put: " + s.returnOp
// + " - create: " + s.createOp
// + " :: max size: " + s.maxSize
// );
// }
// }
// }
// }
// return totalCacheBytes;
// }
//
// private int getByteFactor() {
// int factor = 1;
// if (name.contains("Int") || name.contains("Float")) {
// factor = 4;
// } else if (name.contains("Double")) {
// factor = 8;
// }
// return factor;
// }
//
// long getTotalInitialBytes() {
// return getByteFactor() * totalInitial;
// }
// }
| import java.lang.ref.WeakReference;
import java.util.Arrays;
import com.sun.marlin.ArrayCacheConst.BucketStats;
import com.sun.marlin.ArrayCacheConst.CacheStats;
import static com.sun.marlin.ArrayCacheConst.ARRAY_SIZES;
import static com.sun.marlin.ArrayCacheConst.BUCKETS;
import static com.sun.marlin.ArrayCacheConst.MAX_ARRAY_SIZE;
import static com.sun.marlin.MarlinUtils.logInfo;
import static com.sun.marlin.MarlinUtils.logException; | (DO_STATS) ? stats.bucketStats[i] : null);
}
// update weak reference:
refBuckets = new WeakReference<Bucket[]>(buckets);
}
return buckets;
}
Reference createRef(final int initialSize) {
return new Reference(this, initialSize);
}
static final class Reference {
// initial array reference (direct access)
final byte[] initial;
private final boolean clean;
private final ByteArrayCache cache;
Reference(final ByteArrayCache cache, final int initialSize) {
this.cache = cache;
this.clean = cache.clean;
this.initial = createArray(initialSize);
if (DO_STATS) {
cache.stats.totalInitial += initialSize;
}
}
byte[] getArray(final int length) { | // Path: src/main/java/com/sun/marlin/ArrayCacheConst.java
// static final int[] ARRAY_SIZES = new int[BUCKETS];
//
// Path: src/main/java/com/sun/marlin/ArrayCacheConst.java
// static final int BUCKETS = 8;
//
// Path: src/main/java/com/sun/marlin/ArrayCacheConst.java
// static final int MAX_ARRAY_SIZE;
//
// Path: src/main/java/com/sun/marlin/MarlinUtils.java
// public static void logInfo(final String msg) {
// if (MarlinConst.USE_LOGGER) {
// LOG.info(msg);
// } else if (MarlinConst.ENABLE_LOGS) {
// System.out.print("INFO: ");
// System.out.println(msg);
// }
// }
//
// Path: src/main/java/com/sun/marlin/MarlinUtils.java
// public static void logException(final String msg, final Throwable th) {
// if (MarlinConst.USE_LOGGER) {
// LOG.log(java.util.logging.Level.WARNING, msg, th);
// } else if (MarlinConst.ENABLE_LOGS) {
// System.out.print("WARNING: ");
// System.out.println(msg);
// th.printStackTrace(System.err);
// }
// }
//
// Path: src/main/java/com/sun/marlin/ArrayCacheConst.java
// static final class BucketStats {
// int getOp = 0;
// int createOp = 0;
// int returnOp = 0;
// int maxSize = 0;
//
// void reset() {
// getOp = 0;
// createOp = 0;
// returnOp = 0;
// maxSize = 0;
// }
//
// void updateMaxSize(final int size) {
// if (size > maxSize) {
// maxSize = size;
// }
// }
// }
//
// Path: src/main/java/com/sun/marlin/ArrayCacheConst.java
// static final class CacheStats {
// final String name;
// final BucketStats[] bucketStats;
// int resize = 0;
// int oversize = 0;
// long totalInitial = 0L;
//
// CacheStats(final String name) {
// this.name = name;
//
// bucketStats = new BucketStats[BUCKETS];
// for (int i = 0; i < BUCKETS; i++) {
// bucketStats[i] = new BucketStats();
// }
// }
//
// void reset() {
// resize = 0;
// oversize = 0;
//
// for (int i = 0; i < BUCKETS; i++) {
// bucketStats[i].reset();
// }
// }
//
// long dumpStats() {
// long totalCacheBytes = 0L;
//
// if (DO_STATS) {
// for (int i = 0; i < BUCKETS; i++) {
// final BucketStats s = bucketStats[i];
//
// if (s.maxSize != 0) {
// totalCacheBytes += getByteFactor()
// * (s.maxSize * ARRAY_SIZES[i]);
// }
// }
//
// if (totalInitial != 0L || totalCacheBytes != 0L
// || resize != 0 || oversize != 0)
// {
// logInfo(name + ": resize: " + resize
// + " - oversize: " + oversize
// + " - initial: " + getTotalInitialBytes()
// + " bytes (" + totalInitial + " elements)"
// + " - cache: " + totalCacheBytes + " bytes"
// );
// }
//
// if (totalCacheBytes != 0L) {
// logInfo(name + ": usage stats:");
//
// for (int i = 0; i < BUCKETS; i++) {
// final BucketStats s = bucketStats[i];
//
// if (s.getOp != 0) {
// logInfo(" Bucket[" + ARRAY_SIZES[i] + "]: "
// + "get: " + s.getOp
// + " - put: " + s.returnOp
// + " - create: " + s.createOp
// + " :: max size: " + s.maxSize
// );
// }
// }
// }
// }
// return totalCacheBytes;
// }
//
// private int getByteFactor() {
// int factor = 1;
// if (name.contains("Int") || name.contains("Float")) {
// factor = 4;
// } else if (name.contains("Double")) {
// factor = 8;
// }
// return factor;
// }
//
// long getTotalInitialBytes() {
// return getByteFactor() * totalInitial;
// }
// }
// Path: src/main/java/com/sun/marlin/ByteArrayCache.java
import java.lang.ref.WeakReference;
import java.util.Arrays;
import com.sun.marlin.ArrayCacheConst.BucketStats;
import com.sun.marlin.ArrayCacheConst.CacheStats;
import static com.sun.marlin.ArrayCacheConst.ARRAY_SIZES;
import static com.sun.marlin.ArrayCacheConst.BUCKETS;
import static com.sun.marlin.ArrayCacheConst.MAX_ARRAY_SIZE;
import static com.sun.marlin.MarlinUtils.logInfo;
import static com.sun.marlin.MarlinUtils.logException;
(DO_STATS) ? stats.bucketStats[i] : null);
}
// update weak reference:
refBuckets = new WeakReference<Bucket[]>(buckets);
}
return buckets;
}
Reference createRef(final int initialSize) {
return new Reference(this, initialSize);
}
static final class Reference {
// initial array reference (direct access)
final byte[] initial;
private final boolean clean;
private final ByteArrayCache cache;
Reference(final ByteArrayCache cache, final int initialSize) {
this.cache = cache;
this.clean = cache.clean;
this.initial = createArray(initialSize);
if (DO_STATS) {
cache.stats.totalInitial += initialSize;
}
}
byte[] getArray(final int length) { | if (length <= MAX_ARRAY_SIZE) { |
bourgesl/marlin-fx | src/main/java/com/sun/marlin/ByteArrayCache.java | // Path: src/main/java/com/sun/marlin/ArrayCacheConst.java
// static final int[] ARRAY_SIZES = new int[BUCKETS];
//
// Path: src/main/java/com/sun/marlin/ArrayCacheConst.java
// static final int BUCKETS = 8;
//
// Path: src/main/java/com/sun/marlin/ArrayCacheConst.java
// static final int MAX_ARRAY_SIZE;
//
// Path: src/main/java/com/sun/marlin/MarlinUtils.java
// public static void logInfo(final String msg) {
// if (MarlinConst.USE_LOGGER) {
// LOG.info(msg);
// } else if (MarlinConst.ENABLE_LOGS) {
// System.out.print("INFO: ");
// System.out.println(msg);
// }
// }
//
// Path: src/main/java/com/sun/marlin/MarlinUtils.java
// public static void logException(final String msg, final Throwable th) {
// if (MarlinConst.USE_LOGGER) {
// LOG.log(java.util.logging.Level.WARNING, msg, th);
// } else if (MarlinConst.ENABLE_LOGS) {
// System.out.print("WARNING: ");
// System.out.println(msg);
// th.printStackTrace(System.err);
// }
// }
//
// Path: src/main/java/com/sun/marlin/ArrayCacheConst.java
// static final class BucketStats {
// int getOp = 0;
// int createOp = 0;
// int returnOp = 0;
// int maxSize = 0;
//
// void reset() {
// getOp = 0;
// createOp = 0;
// returnOp = 0;
// maxSize = 0;
// }
//
// void updateMaxSize(final int size) {
// if (size > maxSize) {
// maxSize = size;
// }
// }
// }
//
// Path: src/main/java/com/sun/marlin/ArrayCacheConst.java
// static final class CacheStats {
// final String name;
// final BucketStats[] bucketStats;
// int resize = 0;
// int oversize = 0;
// long totalInitial = 0L;
//
// CacheStats(final String name) {
// this.name = name;
//
// bucketStats = new BucketStats[BUCKETS];
// for (int i = 0; i < BUCKETS; i++) {
// bucketStats[i] = new BucketStats();
// }
// }
//
// void reset() {
// resize = 0;
// oversize = 0;
//
// for (int i = 0; i < BUCKETS; i++) {
// bucketStats[i].reset();
// }
// }
//
// long dumpStats() {
// long totalCacheBytes = 0L;
//
// if (DO_STATS) {
// for (int i = 0; i < BUCKETS; i++) {
// final BucketStats s = bucketStats[i];
//
// if (s.maxSize != 0) {
// totalCacheBytes += getByteFactor()
// * (s.maxSize * ARRAY_SIZES[i]);
// }
// }
//
// if (totalInitial != 0L || totalCacheBytes != 0L
// || resize != 0 || oversize != 0)
// {
// logInfo(name + ": resize: " + resize
// + " - oversize: " + oversize
// + " - initial: " + getTotalInitialBytes()
// + " bytes (" + totalInitial + " elements)"
// + " - cache: " + totalCacheBytes + " bytes"
// );
// }
//
// if (totalCacheBytes != 0L) {
// logInfo(name + ": usage stats:");
//
// for (int i = 0; i < BUCKETS; i++) {
// final BucketStats s = bucketStats[i];
//
// if (s.getOp != 0) {
// logInfo(" Bucket[" + ARRAY_SIZES[i] + "]: "
// + "get: " + s.getOp
// + " - put: " + s.returnOp
// + " - create: " + s.createOp
// + " :: max size: " + s.maxSize
// );
// }
// }
// }
// }
// return totalCacheBytes;
// }
//
// private int getByteFactor() {
// int factor = 1;
// if (name.contains("Int") || name.contains("Float")) {
// factor = 4;
// } else if (name.contains("Double")) {
// factor = 8;
// }
// return factor;
// }
//
// long getTotalInitialBytes() {
// return getByteFactor() * totalInitial;
// }
// }
| import java.lang.ref.WeakReference;
import java.util.Arrays;
import com.sun.marlin.ArrayCacheConst.BucketStats;
import com.sun.marlin.ArrayCacheConst.CacheStats;
import static com.sun.marlin.ArrayCacheConst.ARRAY_SIZES;
import static com.sun.marlin.ArrayCacheConst.BUCKETS;
import static com.sun.marlin.ArrayCacheConst.MAX_ARRAY_SIZE;
import static com.sun.marlin.MarlinUtils.logInfo;
import static com.sun.marlin.MarlinUtils.logException; | }
Reference createRef(final int initialSize) {
return new Reference(this, initialSize);
}
static final class Reference {
// initial array reference (direct access)
final byte[] initial;
private final boolean clean;
private final ByteArrayCache cache;
Reference(final ByteArrayCache cache, final int initialSize) {
this.cache = cache;
this.clean = cache.clean;
this.initial = createArray(initialSize);
if (DO_STATS) {
cache.stats.totalInitial += initialSize;
}
}
byte[] getArray(final int length) {
if (length <= MAX_ARRAY_SIZE) {
return cache.getCacheBucket(length).getArray();
}
if (DO_STATS) {
cache.stats.oversize++;
}
if (DO_LOG_OVERSIZE) { | // Path: src/main/java/com/sun/marlin/ArrayCacheConst.java
// static final int[] ARRAY_SIZES = new int[BUCKETS];
//
// Path: src/main/java/com/sun/marlin/ArrayCacheConst.java
// static final int BUCKETS = 8;
//
// Path: src/main/java/com/sun/marlin/ArrayCacheConst.java
// static final int MAX_ARRAY_SIZE;
//
// Path: src/main/java/com/sun/marlin/MarlinUtils.java
// public static void logInfo(final String msg) {
// if (MarlinConst.USE_LOGGER) {
// LOG.info(msg);
// } else if (MarlinConst.ENABLE_LOGS) {
// System.out.print("INFO: ");
// System.out.println(msg);
// }
// }
//
// Path: src/main/java/com/sun/marlin/MarlinUtils.java
// public static void logException(final String msg, final Throwable th) {
// if (MarlinConst.USE_LOGGER) {
// LOG.log(java.util.logging.Level.WARNING, msg, th);
// } else if (MarlinConst.ENABLE_LOGS) {
// System.out.print("WARNING: ");
// System.out.println(msg);
// th.printStackTrace(System.err);
// }
// }
//
// Path: src/main/java/com/sun/marlin/ArrayCacheConst.java
// static final class BucketStats {
// int getOp = 0;
// int createOp = 0;
// int returnOp = 0;
// int maxSize = 0;
//
// void reset() {
// getOp = 0;
// createOp = 0;
// returnOp = 0;
// maxSize = 0;
// }
//
// void updateMaxSize(final int size) {
// if (size > maxSize) {
// maxSize = size;
// }
// }
// }
//
// Path: src/main/java/com/sun/marlin/ArrayCacheConst.java
// static final class CacheStats {
// final String name;
// final BucketStats[] bucketStats;
// int resize = 0;
// int oversize = 0;
// long totalInitial = 0L;
//
// CacheStats(final String name) {
// this.name = name;
//
// bucketStats = new BucketStats[BUCKETS];
// for (int i = 0; i < BUCKETS; i++) {
// bucketStats[i] = new BucketStats();
// }
// }
//
// void reset() {
// resize = 0;
// oversize = 0;
//
// for (int i = 0; i < BUCKETS; i++) {
// bucketStats[i].reset();
// }
// }
//
// long dumpStats() {
// long totalCacheBytes = 0L;
//
// if (DO_STATS) {
// for (int i = 0; i < BUCKETS; i++) {
// final BucketStats s = bucketStats[i];
//
// if (s.maxSize != 0) {
// totalCacheBytes += getByteFactor()
// * (s.maxSize * ARRAY_SIZES[i]);
// }
// }
//
// if (totalInitial != 0L || totalCacheBytes != 0L
// || resize != 0 || oversize != 0)
// {
// logInfo(name + ": resize: " + resize
// + " - oversize: " + oversize
// + " - initial: " + getTotalInitialBytes()
// + " bytes (" + totalInitial + " elements)"
// + " - cache: " + totalCacheBytes + " bytes"
// );
// }
//
// if (totalCacheBytes != 0L) {
// logInfo(name + ": usage stats:");
//
// for (int i = 0; i < BUCKETS; i++) {
// final BucketStats s = bucketStats[i];
//
// if (s.getOp != 0) {
// logInfo(" Bucket[" + ARRAY_SIZES[i] + "]: "
// + "get: " + s.getOp
// + " - put: " + s.returnOp
// + " - create: " + s.createOp
// + " :: max size: " + s.maxSize
// );
// }
// }
// }
// }
// return totalCacheBytes;
// }
//
// private int getByteFactor() {
// int factor = 1;
// if (name.contains("Int") || name.contains("Float")) {
// factor = 4;
// } else if (name.contains("Double")) {
// factor = 8;
// }
// return factor;
// }
//
// long getTotalInitialBytes() {
// return getByteFactor() * totalInitial;
// }
// }
// Path: src/main/java/com/sun/marlin/ByteArrayCache.java
import java.lang.ref.WeakReference;
import java.util.Arrays;
import com.sun.marlin.ArrayCacheConst.BucketStats;
import com.sun.marlin.ArrayCacheConst.CacheStats;
import static com.sun.marlin.ArrayCacheConst.ARRAY_SIZES;
import static com.sun.marlin.ArrayCacheConst.BUCKETS;
import static com.sun.marlin.ArrayCacheConst.MAX_ARRAY_SIZE;
import static com.sun.marlin.MarlinUtils.logInfo;
import static com.sun.marlin.MarlinUtils.logException;
}
Reference createRef(final int initialSize) {
return new Reference(this, initialSize);
}
static final class Reference {
// initial array reference (direct access)
final byte[] initial;
private final boolean clean;
private final ByteArrayCache cache;
Reference(final ByteArrayCache cache, final int initialSize) {
this.cache = cache;
this.clean = cache.clean;
this.initial = createArray(initialSize);
if (DO_STATS) {
cache.stats.totalInitial += initialSize;
}
}
byte[] getArray(final int length) {
if (length <= MAX_ARRAY_SIZE) {
return cache.getCacheBucket(length).getArray();
}
if (DO_STATS) {
cache.stats.oversize++;
}
if (DO_LOG_OVERSIZE) { | logInfo(getLogPrefix(clean) + "ByteArrayCache: " |
bourgesl/marlin-fx | src/main/java/com/sun/marlin/ByteArrayCache.java | // Path: src/main/java/com/sun/marlin/ArrayCacheConst.java
// static final int[] ARRAY_SIZES = new int[BUCKETS];
//
// Path: src/main/java/com/sun/marlin/ArrayCacheConst.java
// static final int BUCKETS = 8;
//
// Path: src/main/java/com/sun/marlin/ArrayCacheConst.java
// static final int MAX_ARRAY_SIZE;
//
// Path: src/main/java/com/sun/marlin/MarlinUtils.java
// public static void logInfo(final String msg) {
// if (MarlinConst.USE_LOGGER) {
// LOG.info(msg);
// } else if (MarlinConst.ENABLE_LOGS) {
// System.out.print("INFO: ");
// System.out.println(msg);
// }
// }
//
// Path: src/main/java/com/sun/marlin/MarlinUtils.java
// public static void logException(final String msg, final Throwable th) {
// if (MarlinConst.USE_LOGGER) {
// LOG.log(java.util.logging.Level.WARNING, msg, th);
// } else if (MarlinConst.ENABLE_LOGS) {
// System.out.print("WARNING: ");
// System.out.println(msg);
// th.printStackTrace(System.err);
// }
// }
//
// Path: src/main/java/com/sun/marlin/ArrayCacheConst.java
// static final class BucketStats {
// int getOp = 0;
// int createOp = 0;
// int returnOp = 0;
// int maxSize = 0;
//
// void reset() {
// getOp = 0;
// createOp = 0;
// returnOp = 0;
// maxSize = 0;
// }
//
// void updateMaxSize(final int size) {
// if (size > maxSize) {
// maxSize = size;
// }
// }
// }
//
// Path: src/main/java/com/sun/marlin/ArrayCacheConst.java
// static final class CacheStats {
// final String name;
// final BucketStats[] bucketStats;
// int resize = 0;
// int oversize = 0;
// long totalInitial = 0L;
//
// CacheStats(final String name) {
// this.name = name;
//
// bucketStats = new BucketStats[BUCKETS];
// for (int i = 0; i < BUCKETS; i++) {
// bucketStats[i] = new BucketStats();
// }
// }
//
// void reset() {
// resize = 0;
// oversize = 0;
//
// for (int i = 0; i < BUCKETS; i++) {
// bucketStats[i].reset();
// }
// }
//
// long dumpStats() {
// long totalCacheBytes = 0L;
//
// if (DO_STATS) {
// for (int i = 0; i < BUCKETS; i++) {
// final BucketStats s = bucketStats[i];
//
// if (s.maxSize != 0) {
// totalCacheBytes += getByteFactor()
// * (s.maxSize * ARRAY_SIZES[i]);
// }
// }
//
// if (totalInitial != 0L || totalCacheBytes != 0L
// || resize != 0 || oversize != 0)
// {
// logInfo(name + ": resize: " + resize
// + " - oversize: " + oversize
// + " - initial: " + getTotalInitialBytes()
// + " bytes (" + totalInitial + " elements)"
// + " - cache: " + totalCacheBytes + " bytes"
// );
// }
//
// if (totalCacheBytes != 0L) {
// logInfo(name + ": usage stats:");
//
// for (int i = 0; i < BUCKETS; i++) {
// final BucketStats s = bucketStats[i];
//
// if (s.getOp != 0) {
// logInfo(" Bucket[" + ARRAY_SIZES[i] + "]: "
// + "get: " + s.getOp
// + " - put: " + s.returnOp
// + " - create: " + s.createOp
// + " :: max size: " + s.maxSize
// );
// }
// }
// }
// }
// return totalCacheBytes;
// }
//
// private int getByteFactor() {
// int factor = 1;
// if (name.contains("Int") || name.contains("Float")) {
// factor = 4;
// } else if (name.contains("Double")) {
// factor = 8;
// }
// return factor;
// }
//
// long getTotalInitialBytes() {
// return getByteFactor() * totalInitial;
// }
// }
| import java.lang.ref.WeakReference;
import java.util.Arrays;
import com.sun.marlin.ArrayCacheConst.BucketStats;
import com.sun.marlin.ArrayCacheConst.CacheStats;
import static com.sun.marlin.ArrayCacheConst.ARRAY_SIZES;
import static com.sun.marlin.ArrayCacheConst.BUCKETS;
import static com.sun.marlin.ArrayCacheConst.MAX_ARRAY_SIZE;
import static com.sun.marlin.MarlinUtils.logInfo;
import static com.sun.marlin.MarlinUtils.logException; |
byte[] putArray(final byte[] array)
{
// dirty array helper:
return putArray(array, 0, array.length);
}
byte[] putArray(final byte[] array, final int fromIndex,
final int toIndex)
{
if (array.length <= MAX_ARRAY_SIZE) {
if ((clean || DO_CLEAN_DIRTY) && (toIndex != 0)) {
// clean-up array of dirty part[fromIndex; toIndex[
fill(array, fromIndex, toIndex, (byte)0);
}
// ensure to never store initial arrays in cache:
if (array != initial) {
cache.getCacheBucket(array.length).putArray(array);
}
}
return initial;
}
}
static final class Bucket {
private int tail = 0;
private final int arraySize;
private final boolean clean;
private final byte[][] arrays; | // Path: src/main/java/com/sun/marlin/ArrayCacheConst.java
// static final int[] ARRAY_SIZES = new int[BUCKETS];
//
// Path: src/main/java/com/sun/marlin/ArrayCacheConst.java
// static final int BUCKETS = 8;
//
// Path: src/main/java/com/sun/marlin/ArrayCacheConst.java
// static final int MAX_ARRAY_SIZE;
//
// Path: src/main/java/com/sun/marlin/MarlinUtils.java
// public static void logInfo(final String msg) {
// if (MarlinConst.USE_LOGGER) {
// LOG.info(msg);
// } else if (MarlinConst.ENABLE_LOGS) {
// System.out.print("INFO: ");
// System.out.println(msg);
// }
// }
//
// Path: src/main/java/com/sun/marlin/MarlinUtils.java
// public static void logException(final String msg, final Throwable th) {
// if (MarlinConst.USE_LOGGER) {
// LOG.log(java.util.logging.Level.WARNING, msg, th);
// } else if (MarlinConst.ENABLE_LOGS) {
// System.out.print("WARNING: ");
// System.out.println(msg);
// th.printStackTrace(System.err);
// }
// }
//
// Path: src/main/java/com/sun/marlin/ArrayCacheConst.java
// static final class BucketStats {
// int getOp = 0;
// int createOp = 0;
// int returnOp = 0;
// int maxSize = 0;
//
// void reset() {
// getOp = 0;
// createOp = 0;
// returnOp = 0;
// maxSize = 0;
// }
//
// void updateMaxSize(final int size) {
// if (size > maxSize) {
// maxSize = size;
// }
// }
// }
//
// Path: src/main/java/com/sun/marlin/ArrayCacheConst.java
// static final class CacheStats {
// final String name;
// final BucketStats[] bucketStats;
// int resize = 0;
// int oversize = 0;
// long totalInitial = 0L;
//
// CacheStats(final String name) {
// this.name = name;
//
// bucketStats = new BucketStats[BUCKETS];
// for (int i = 0; i < BUCKETS; i++) {
// bucketStats[i] = new BucketStats();
// }
// }
//
// void reset() {
// resize = 0;
// oversize = 0;
//
// for (int i = 0; i < BUCKETS; i++) {
// bucketStats[i].reset();
// }
// }
//
// long dumpStats() {
// long totalCacheBytes = 0L;
//
// if (DO_STATS) {
// for (int i = 0; i < BUCKETS; i++) {
// final BucketStats s = bucketStats[i];
//
// if (s.maxSize != 0) {
// totalCacheBytes += getByteFactor()
// * (s.maxSize * ARRAY_SIZES[i]);
// }
// }
//
// if (totalInitial != 0L || totalCacheBytes != 0L
// || resize != 0 || oversize != 0)
// {
// logInfo(name + ": resize: " + resize
// + " - oversize: " + oversize
// + " - initial: " + getTotalInitialBytes()
// + " bytes (" + totalInitial + " elements)"
// + " - cache: " + totalCacheBytes + " bytes"
// );
// }
//
// if (totalCacheBytes != 0L) {
// logInfo(name + ": usage stats:");
//
// for (int i = 0; i < BUCKETS; i++) {
// final BucketStats s = bucketStats[i];
//
// if (s.getOp != 0) {
// logInfo(" Bucket[" + ARRAY_SIZES[i] + "]: "
// + "get: " + s.getOp
// + " - put: " + s.returnOp
// + " - create: " + s.createOp
// + " :: max size: " + s.maxSize
// );
// }
// }
// }
// }
// return totalCacheBytes;
// }
//
// private int getByteFactor() {
// int factor = 1;
// if (name.contains("Int") || name.contains("Float")) {
// factor = 4;
// } else if (name.contains("Double")) {
// factor = 8;
// }
// return factor;
// }
//
// long getTotalInitialBytes() {
// return getByteFactor() * totalInitial;
// }
// }
// Path: src/main/java/com/sun/marlin/ByteArrayCache.java
import java.lang.ref.WeakReference;
import java.util.Arrays;
import com.sun.marlin.ArrayCacheConst.BucketStats;
import com.sun.marlin.ArrayCacheConst.CacheStats;
import static com.sun.marlin.ArrayCacheConst.ARRAY_SIZES;
import static com.sun.marlin.ArrayCacheConst.BUCKETS;
import static com.sun.marlin.ArrayCacheConst.MAX_ARRAY_SIZE;
import static com.sun.marlin.MarlinUtils.logInfo;
import static com.sun.marlin.MarlinUtils.logException;
byte[] putArray(final byte[] array)
{
// dirty array helper:
return putArray(array, 0, array.length);
}
byte[] putArray(final byte[] array, final int fromIndex,
final int toIndex)
{
if (array.length <= MAX_ARRAY_SIZE) {
if ((clean || DO_CLEAN_DIRTY) && (toIndex != 0)) {
// clean-up array of dirty part[fromIndex; toIndex[
fill(array, fromIndex, toIndex, (byte)0);
}
// ensure to never store initial arrays in cache:
if (array != initial) {
cache.getCacheBucket(array.length).putArray(array);
}
}
return initial;
}
}
static final class Bucket {
private int tail = 0;
private final int arraySize;
private final boolean clean;
private final byte[][] arrays; | private final BucketStats stats; |
bourgesl/marlin-fx | src/main/java/com/sun/marlin/ByteArrayCache.java | // Path: src/main/java/com/sun/marlin/ArrayCacheConst.java
// static final int[] ARRAY_SIZES = new int[BUCKETS];
//
// Path: src/main/java/com/sun/marlin/ArrayCacheConst.java
// static final int BUCKETS = 8;
//
// Path: src/main/java/com/sun/marlin/ArrayCacheConst.java
// static final int MAX_ARRAY_SIZE;
//
// Path: src/main/java/com/sun/marlin/MarlinUtils.java
// public static void logInfo(final String msg) {
// if (MarlinConst.USE_LOGGER) {
// LOG.info(msg);
// } else if (MarlinConst.ENABLE_LOGS) {
// System.out.print("INFO: ");
// System.out.println(msg);
// }
// }
//
// Path: src/main/java/com/sun/marlin/MarlinUtils.java
// public static void logException(final String msg, final Throwable th) {
// if (MarlinConst.USE_LOGGER) {
// LOG.log(java.util.logging.Level.WARNING, msg, th);
// } else if (MarlinConst.ENABLE_LOGS) {
// System.out.print("WARNING: ");
// System.out.println(msg);
// th.printStackTrace(System.err);
// }
// }
//
// Path: src/main/java/com/sun/marlin/ArrayCacheConst.java
// static final class BucketStats {
// int getOp = 0;
// int createOp = 0;
// int returnOp = 0;
// int maxSize = 0;
//
// void reset() {
// getOp = 0;
// createOp = 0;
// returnOp = 0;
// maxSize = 0;
// }
//
// void updateMaxSize(final int size) {
// if (size > maxSize) {
// maxSize = size;
// }
// }
// }
//
// Path: src/main/java/com/sun/marlin/ArrayCacheConst.java
// static final class CacheStats {
// final String name;
// final BucketStats[] bucketStats;
// int resize = 0;
// int oversize = 0;
// long totalInitial = 0L;
//
// CacheStats(final String name) {
// this.name = name;
//
// bucketStats = new BucketStats[BUCKETS];
// for (int i = 0; i < BUCKETS; i++) {
// bucketStats[i] = new BucketStats();
// }
// }
//
// void reset() {
// resize = 0;
// oversize = 0;
//
// for (int i = 0; i < BUCKETS; i++) {
// bucketStats[i].reset();
// }
// }
//
// long dumpStats() {
// long totalCacheBytes = 0L;
//
// if (DO_STATS) {
// for (int i = 0; i < BUCKETS; i++) {
// final BucketStats s = bucketStats[i];
//
// if (s.maxSize != 0) {
// totalCacheBytes += getByteFactor()
// * (s.maxSize * ARRAY_SIZES[i]);
// }
// }
//
// if (totalInitial != 0L || totalCacheBytes != 0L
// || resize != 0 || oversize != 0)
// {
// logInfo(name + ": resize: " + resize
// + " - oversize: " + oversize
// + " - initial: " + getTotalInitialBytes()
// + " bytes (" + totalInitial + " elements)"
// + " - cache: " + totalCacheBytes + " bytes"
// );
// }
//
// if (totalCacheBytes != 0L) {
// logInfo(name + ": usage stats:");
//
// for (int i = 0; i < BUCKETS; i++) {
// final BucketStats s = bucketStats[i];
//
// if (s.getOp != 0) {
// logInfo(" Bucket[" + ARRAY_SIZES[i] + "]: "
// + "get: " + s.getOp
// + " - put: " + s.returnOp
// + " - create: " + s.createOp
// + " :: max size: " + s.maxSize
// );
// }
// }
// }
// }
// return totalCacheBytes;
// }
//
// private int getByteFactor() {
// int factor = 1;
// if (name.contains("Int") || name.contains("Float")) {
// factor = 4;
// } else if (name.contains("Double")) {
// factor = 8;
// }
// return factor;
// }
//
// long getTotalInitialBytes() {
// return getByteFactor() * totalInitial;
// }
// }
| import java.lang.ref.WeakReference;
import java.util.Arrays;
import com.sun.marlin.ArrayCacheConst.BucketStats;
import com.sun.marlin.ArrayCacheConst.CacheStats;
import static com.sun.marlin.ArrayCacheConst.ARRAY_SIZES;
import static com.sun.marlin.ArrayCacheConst.BUCKETS;
import static com.sun.marlin.ArrayCacheConst.MAX_ARRAY_SIZE;
import static com.sun.marlin.MarlinUtils.logInfo;
import static com.sun.marlin.MarlinUtils.logException; | stats.updateMaxSize(tail);
}
} else if (DO_CHECKS) {
logInfo(getLogPrefix(clean) + "ByteArrayCache: "
+ "array capacity exceeded !");
}
}
}
static byte[] createArray(final int length) {
return new byte[length];
}
static void fill(final byte[] array, final int fromIndex,
final int toIndex, final byte value)
{
// clear array data:
Arrays.fill(array, fromIndex, toIndex, value);
if (DO_CHECKS) {
check(array, fromIndex, toIndex, value);
}
}
public static void check(final byte[] array, final int fromIndex,
final int toIndex, final byte value)
{
if (DO_CHECKS) {
// check zero on full array:
for (int i = 0; i < array.length; i++) {
if (array[i] != value) { | // Path: src/main/java/com/sun/marlin/ArrayCacheConst.java
// static final int[] ARRAY_SIZES = new int[BUCKETS];
//
// Path: src/main/java/com/sun/marlin/ArrayCacheConst.java
// static final int BUCKETS = 8;
//
// Path: src/main/java/com/sun/marlin/ArrayCacheConst.java
// static final int MAX_ARRAY_SIZE;
//
// Path: src/main/java/com/sun/marlin/MarlinUtils.java
// public static void logInfo(final String msg) {
// if (MarlinConst.USE_LOGGER) {
// LOG.info(msg);
// } else if (MarlinConst.ENABLE_LOGS) {
// System.out.print("INFO: ");
// System.out.println(msg);
// }
// }
//
// Path: src/main/java/com/sun/marlin/MarlinUtils.java
// public static void logException(final String msg, final Throwable th) {
// if (MarlinConst.USE_LOGGER) {
// LOG.log(java.util.logging.Level.WARNING, msg, th);
// } else if (MarlinConst.ENABLE_LOGS) {
// System.out.print("WARNING: ");
// System.out.println(msg);
// th.printStackTrace(System.err);
// }
// }
//
// Path: src/main/java/com/sun/marlin/ArrayCacheConst.java
// static final class BucketStats {
// int getOp = 0;
// int createOp = 0;
// int returnOp = 0;
// int maxSize = 0;
//
// void reset() {
// getOp = 0;
// createOp = 0;
// returnOp = 0;
// maxSize = 0;
// }
//
// void updateMaxSize(final int size) {
// if (size > maxSize) {
// maxSize = size;
// }
// }
// }
//
// Path: src/main/java/com/sun/marlin/ArrayCacheConst.java
// static final class CacheStats {
// final String name;
// final BucketStats[] bucketStats;
// int resize = 0;
// int oversize = 0;
// long totalInitial = 0L;
//
// CacheStats(final String name) {
// this.name = name;
//
// bucketStats = new BucketStats[BUCKETS];
// for (int i = 0; i < BUCKETS; i++) {
// bucketStats[i] = new BucketStats();
// }
// }
//
// void reset() {
// resize = 0;
// oversize = 0;
//
// for (int i = 0; i < BUCKETS; i++) {
// bucketStats[i].reset();
// }
// }
//
// long dumpStats() {
// long totalCacheBytes = 0L;
//
// if (DO_STATS) {
// for (int i = 0; i < BUCKETS; i++) {
// final BucketStats s = bucketStats[i];
//
// if (s.maxSize != 0) {
// totalCacheBytes += getByteFactor()
// * (s.maxSize * ARRAY_SIZES[i]);
// }
// }
//
// if (totalInitial != 0L || totalCacheBytes != 0L
// || resize != 0 || oversize != 0)
// {
// logInfo(name + ": resize: " + resize
// + " - oversize: " + oversize
// + " - initial: " + getTotalInitialBytes()
// + " bytes (" + totalInitial + " elements)"
// + " - cache: " + totalCacheBytes + " bytes"
// );
// }
//
// if (totalCacheBytes != 0L) {
// logInfo(name + ": usage stats:");
//
// for (int i = 0; i < BUCKETS; i++) {
// final BucketStats s = bucketStats[i];
//
// if (s.getOp != 0) {
// logInfo(" Bucket[" + ARRAY_SIZES[i] + "]: "
// + "get: " + s.getOp
// + " - put: " + s.returnOp
// + " - create: " + s.createOp
// + " :: max size: " + s.maxSize
// );
// }
// }
// }
// }
// return totalCacheBytes;
// }
//
// private int getByteFactor() {
// int factor = 1;
// if (name.contains("Int") || name.contains("Float")) {
// factor = 4;
// } else if (name.contains("Double")) {
// factor = 8;
// }
// return factor;
// }
//
// long getTotalInitialBytes() {
// return getByteFactor() * totalInitial;
// }
// }
// Path: src/main/java/com/sun/marlin/ByteArrayCache.java
import java.lang.ref.WeakReference;
import java.util.Arrays;
import com.sun.marlin.ArrayCacheConst.BucketStats;
import com.sun.marlin.ArrayCacheConst.CacheStats;
import static com.sun.marlin.ArrayCacheConst.ARRAY_SIZES;
import static com.sun.marlin.ArrayCacheConst.BUCKETS;
import static com.sun.marlin.ArrayCacheConst.MAX_ARRAY_SIZE;
import static com.sun.marlin.MarlinUtils.logInfo;
import static com.sun.marlin.MarlinUtils.logException;
stats.updateMaxSize(tail);
}
} else if (DO_CHECKS) {
logInfo(getLogPrefix(clean) + "ByteArrayCache: "
+ "array capacity exceeded !");
}
}
}
static byte[] createArray(final int length) {
return new byte[length];
}
static void fill(final byte[] array, final int fromIndex,
final int toIndex, final byte value)
{
// clear array data:
Arrays.fill(array, fromIndex, toIndex, value);
if (DO_CHECKS) {
check(array, fromIndex, toIndex, value);
}
}
public static void check(final byte[] array, final int fromIndex,
final int toIndex, final byte value)
{
if (DO_CHECKS) {
// check zero on full array:
for (int i = 0; i < array.length; i++) {
if (array[i] != value) { | logException("Invalid value at: " + i + " = " + array[i] |
bourgesl/marlin-fx | src/main/java/com/sun/marlin/FloatArrayCache.java | // Path: src/main/java/com/sun/marlin/ArrayCacheConst.java
// static final int[] ARRAY_SIZES = new int[BUCKETS];
//
// Path: src/main/java/com/sun/marlin/ArrayCacheConst.java
// static final int BUCKETS = 8;
//
// Path: src/main/java/com/sun/marlin/ArrayCacheConst.java
// static final int MAX_ARRAY_SIZE;
//
// Path: src/main/java/com/sun/marlin/MarlinUtils.java
// public static void logInfo(final String msg) {
// if (MarlinConst.USE_LOGGER) {
// LOG.info(msg);
// } else if (MarlinConst.ENABLE_LOGS) {
// System.out.print("INFO: ");
// System.out.println(msg);
// }
// }
//
// Path: src/main/java/com/sun/marlin/MarlinUtils.java
// public static void logException(final String msg, final Throwable th) {
// if (MarlinConst.USE_LOGGER) {
// LOG.log(java.util.logging.Level.WARNING, msg, th);
// } else if (MarlinConst.ENABLE_LOGS) {
// System.out.print("WARNING: ");
// System.out.println(msg);
// th.printStackTrace(System.err);
// }
// }
//
// Path: src/main/java/com/sun/marlin/ArrayCacheConst.java
// static final class BucketStats {
// int getOp = 0;
// int createOp = 0;
// int returnOp = 0;
// int maxSize = 0;
//
// void reset() {
// getOp = 0;
// createOp = 0;
// returnOp = 0;
// maxSize = 0;
// }
//
// void updateMaxSize(final int size) {
// if (size > maxSize) {
// maxSize = size;
// }
// }
// }
//
// Path: src/main/java/com/sun/marlin/ArrayCacheConst.java
// static final class CacheStats {
// final String name;
// final BucketStats[] bucketStats;
// int resize = 0;
// int oversize = 0;
// long totalInitial = 0L;
//
// CacheStats(final String name) {
// this.name = name;
//
// bucketStats = new BucketStats[BUCKETS];
// for (int i = 0; i < BUCKETS; i++) {
// bucketStats[i] = new BucketStats();
// }
// }
//
// void reset() {
// resize = 0;
// oversize = 0;
//
// for (int i = 0; i < BUCKETS; i++) {
// bucketStats[i].reset();
// }
// }
//
// long dumpStats() {
// long totalCacheBytes = 0L;
//
// if (DO_STATS) {
// for (int i = 0; i < BUCKETS; i++) {
// final BucketStats s = bucketStats[i];
//
// if (s.maxSize != 0) {
// totalCacheBytes += getByteFactor()
// * (s.maxSize * ARRAY_SIZES[i]);
// }
// }
//
// if (totalInitial != 0L || totalCacheBytes != 0L
// || resize != 0 || oversize != 0)
// {
// logInfo(name + ": resize: " + resize
// + " - oversize: " + oversize
// + " - initial: " + getTotalInitialBytes()
// + " bytes (" + totalInitial + " elements)"
// + " - cache: " + totalCacheBytes + " bytes"
// );
// }
//
// if (totalCacheBytes != 0L) {
// logInfo(name + ": usage stats:");
//
// for (int i = 0; i < BUCKETS; i++) {
// final BucketStats s = bucketStats[i];
//
// if (s.getOp != 0) {
// logInfo(" Bucket[" + ARRAY_SIZES[i] + "]: "
// + "get: " + s.getOp
// + " - put: " + s.returnOp
// + " - create: " + s.createOp
// + " :: max size: " + s.maxSize
// );
// }
// }
// }
// }
// return totalCacheBytes;
// }
//
// private int getByteFactor() {
// int factor = 1;
// if (name.contains("Int") || name.contains("Float")) {
// factor = 4;
// } else if (name.contains("Double")) {
// factor = 8;
// }
// return factor;
// }
//
// long getTotalInitialBytes() {
// return getByteFactor() * totalInitial;
// }
// }
| import java.lang.ref.WeakReference;
import java.util.Arrays;
import com.sun.marlin.ArrayCacheConst.BucketStats;
import com.sun.marlin.ArrayCacheConst.CacheStats;
import static com.sun.marlin.ArrayCacheConst.ARRAY_SIZES;
import static com.sun.marlin.ArrayCacheConst.BUCKETS;
import static com.sun.marlin.ArrayCacheConst.MAX_ARRAY_SIZE;
import static com.sun.marlin.MarlinUtils.logInfo;
import static com.sun.marlin.MarlinUtils.logException; | (DO_STATS) ? stats.bucketStats[i] : null);
}
// update weak reference:
refBuckets = new WeakReference<Bucket[]>(buckets);
}
return buckets;
}
Reference createRef(final int initialSize) {
return new Reference(this, initialSize);
}
static final class Reference {
// initial array reference (direct access)
final float[] initial;
private final boolean clean;
private final FloatArrayCache cache;
Reference(final FloatArrayCache cache, final int initialSize) {
this.cache = cache;
this.clean = cache.clean;
this.initial = createArray(initialSize);
if (DO_STATS) {
cache.stats.totalInitial += initialSize;
}
}
float[] getArray(final int length) { | // Path: src/main/java/com/sun/marlin/ArrayCacheConst.java
// static final int[] ARRAY_SIZES = new int[BUCKETS];
//
// Path: src/main/java/com/sun/marlin/ArrayCacheConst.java
// static final int BUCKETS = 8;
//
// Path: src/main/java/com/sun/marlin/ArrayCacheConst.java
// static final int MAX_ARRAY_SIZE;
//
// Path: src/main/java/com/sun/marlin/MarlinUtils.java
// public static void logInfo(final String msg) {
// if (MarlinConst.USE_LOGGER) {
// LOG.info(msg);
// } else if (MarlinConst.ENABLE_LOGS) {
// System.out.print("INFO: ");
// System.out.println(msg);
// }
// }
//
// Path: src/main/java/com/sun/marlin/MarlinUtils.java
// public static void logException(final String msg, final Throwable th) {
// if (MarlinConst.USE_LOGGER) {
// LOG.log(java.util.logging.Level.WARNING, msg, th);
// } else if (MarlinConst.ENABLE_LOGS) {
// System.out.print("WARNING: ");
// System.out.println(msg);
// th.printStackTrace(System.err);
// }
// }
//
// Path: src/main/java/com/sun/marlin/ArrayCacheConst.java
// static final class BucketStats {
// int getOp = 0;
// int createOp = 0;
// int returnOp = 0;
// int maxSize = 0;
//
// void reset() {
// getOp = 0;
// createOp = 0;
// returnOp = 0;
// maxSize = 0;
// }
//
// void updateMaxSize(final int size) {
// if (size > maxSize) {
// maxSize = size;
// }
// }
// }
//
// Path: src/main/java/com/sun/marlin/ArrayCacheConst.java
// static final class CacheStats {
// final String name;
// final BucketStats[] bucketStats;
// int resize = 0;
// int oversize = 0;
// long totalInitial = 0L;
//
// CacheStats(final String name) {
// this.name = name;
//
// bucketStats = new BucketStats[BUCKETS];
// for (int i = 0; i < BUCKETS; i++) {
// bucketStats[i] = new BucketStats();
// }
// }
//
// void reset() {
// resize = 0;
// oversize = 0;
//
// for (int i = 0; i < BUCKETS; i++) {
// bucketStats[i].reset();
// }
// }
//
// long dumpStats() {
// long totalCacheBytes = 0L;
//
// if (DO_STATS) {
// for (int i = 0; i < BUCKETS; i++) {
// final BucketStats s = bucketStats[i];
//
// if (s.maxSize != 0) {
// totalCacheBytes += getByteFactor()
// * (s.maxSize * ARRAY_SIZES[i]);
// }
// }
//
// if (totalInitial != 0L || totalCacheBytes != 0L
// || resize != 0 || oversize != 0)
// {
// logInfo(name + ": resize: " + resize
// + " - oversize: " + oversize
// + " - initial: " + getTotalInitialBytes()
// + " bytes (" + totalInitial + " elements)"
// + " - cache: " + totalCacheBytes + " bytes"
// );
// }
//
// if (totalCacheBytes != 0L) {
// logInfo(name + ": usage stats:");
//
// for (int i = 0; i < BUCKETS; i++) {
// final BucketStats s = bucketStats[i];
//
// if (s.getOp != 0) {
// logInfo(" Bucket[" + ARRAY_SIZES[i] + "]: "
// + "get: " + s.getOp
// + " - put: " + s.returnOp
// + " - create: " + s.createOp
// + " :: max size: " + s.maxSize
// );
// }
// }
// }
// }
// return totalCacheBytes;
// }
//
// private int getByteFactor() {
// int factor = 1;
// if (name.contains("Int") || name.contains("Float")) {
// factor = 4;
// } else if (name.contains("Double")) {
// factor = 8;
// }
// return factor;
// }
//
// long getTotalInitialBytes() {
// return getByteFactor() * totalInitial;
// }
// }
// Path: src/main/java/com/sun/marlin/FloatArrayCache.java
import java.lang.ref.WeakReference;
import java.util.Arrays;
import com.sun.marlin.ArrayCacheConst.BucketStats;
import com.sun.marlin.ArrayCacheConst.CacheStats;
import static com.sun.marlin.ArrayCacheConst.ARRAY_SIZES;
import static com.sun.marlin.ArrayCacheConst.BUCKETS;
import static com.sun.marlin.ArrayCacheConst.MAX_ARRAY_SIZE;
import static com.sun.marlin.MarlinUtils.logInfo;
import static com.sun.marlin.MarlinUtils.logException;
(DO_STATS) ? stats.bucketStats[i] : null);
}
// update weak reference:
refBuckets = new WeakReference<Bucket[]>(buckets);
}
return buckets;
}
Reference createRef(final int initialSize) {
return new Reference(this, initialSize);
}
static final class Reference {
// initial array reference (direct access)
final float[] initial;
private final boolean clean;
private final FloatArrayCache cache;
Reference(final FloatArrayCache cache, final int initialSize) {
this.cache = cache;
this.clean = cache.clean;
this.initial = createArray(initialSize);
if (DO_STATS) {
cache.stats.totalInitial += initialSize;
}
}
float[] getArray(final int length) { | if (length <= MAX_ARRAY_SIZE) { |
bourgesl/marlin-fx | src/main/java/com/sun/marlin/FloatArrayCache.java | // Path: src/main/java/com/sun/marlin/ArrayCacheConst.java
// static final int[] ARRAY_SIZES = new int[BUCKETS];
//
// Path: src/main/java/com/sun/marlin/ArrayCacheConst.java
// static final int BUCKETS = 8;
//
// Path: src/main/java/com/sun/marlin/ArrayCacheConst.java
// static final int MAX_ARRAY_SIZE;
//
// Path: src/main/java/com/sun/marlin/MarlinUtils.java
// public static void logInfo(final String msg) {
// if (MarlinConst.USE_LOGGER) {
// LOG.info(msg);
// } else if (MarlinConst.ENABLE_LOGS) {
// System.out.print("INFO: ");
// System.out.println(msg);
// }
// }
//
// Path: src/main/java/com/sun/marlin/MarlinUtils.java
// public static void logException(final String msg, final Throwable th) {
// if (MarlinConst.USE_LOGGER) {
// LOG.log(java.util.logging.Level.WARNING, msg, th);
// } else if (MarlinConst.ENABLE_LOGS) {
// System.out.print("WARNING: ");
// System.out.println(msg);
// th.printStackTrace(System.err);
// }
// }
//
// Path: src/main/java/com/sun/marlin/ArrayCacheConst.java
// static final class BucketStats {
// int getOp = 0;
// int createOp = 0;
// int returnOp = 0;
// int maxSize = 0;
//
// void reset() {
// getOp = 0;
// createOp = 0;
// returnOp = 0;
// maxSize = 0;
// }
//
// void updateMaxSize(final int size) {
// if (size > maxSize) {
// maxSize = size;
// }
// }
// }
//
// Path: src/main/java/com/sun/marlin/ArrayCacheConst.java
// static final class CacheStats {
// final String name;
// final BucketStats[] bucketStats;
// int resize = 0;
// int oversize = 0;
// long totalInitial = 0L;
//
// CacheStats(final String name) {
// this.name = name;
//
// bucketStats = new BucketStats[BUCKETS];
// for (int i = 0; i < BUCKETS; i++) {
// bucketStats[i] = new BucketStats();
// }
// }
//
// void reset() {
// resize = 0;
// oversize = 0;
//
// for (int i = 0; i < BUCKETS; i++) {
// bucketStats[i].reset();
// }
// }
//
// long dumpStats() {
// long totalCacheBytes = 0L;
//
// if (DO_STATS) {
// for (int i = 0; i < BUCKETS; i++) {
// final BucketStats s = bucketStats[i];
//
// if (s.maxSize != 0) {
// totalCacheBytes += getByteFactor()
// * (s.maxSize * ARRAY_SIZES[i]);
// }
// }
//
// if (totalInitial != 0L || totalCacheBytes != 0L
// || resize != 0 || oversize != 0)
// {
// logInfo(name + ": resize: " + resize
// + " - oversize: " + oversize
// + " - initial: " + getTotalInitialBytes()
// + " bytes (" + totalInitial + " elements)"
// + " - cache: " + totalCacheBytes + " bytes"
// );
// }
//
// if (totalCacheBytes != 0L) {
// logInfo(name + ": usage stats:");
//
// for (int i = 0; i < BUCKETS; i++) {
// final BucketStats s = bucketStats[i];
//
// if (s.getOp != 0) {
// logInfo(" Bucket[" + ARRAY_SIZES[i] + "]: "
// + "get: " + s.getOp
// + " - put: " + s.returnOp
// + " - create: " + s.createOp
// + " :: max size: " + s.maxSize
// );
// }
// }
// }
// }
// return totalCacheBytes;
// }
//
// private int getByteFactor() {
// int factor = 1;
// if (name.contains("Int") || name.contains("Float")) {
// factor = 4;
// } else if (name.contains("Double")) {
// factor = 8;
// }
// return factor;
// }
//
// long getTotalInitialBytes() {
// return getByteFactor() * totalInitial;
// }
// }
| import java.lang.ref.WeakReference;
import java.util.Arrays;
import com.sun.marlin.ArrayCacheConst.BucketStats;
import com.sun.marlin.ArrayCacheConst.CacheStats;
import static com.sun.marlin.ArrayCacheConst.ARRAY_SIZES;
import static com.sun.marlin.ArrayCacheConst.BUCKETS;
import static com.sun.marlin.ArrayCacheConst.MAX_ARRAY_SIZE;
import static com.sun.marlin.MarlinUtils.logInfo;
import static com.sun.marlin.MarlinUtils.logException; | }
Reference createRef(final int initialSize) {
return new Reference(this, initialSize);
}
static final class Reference {
// initial array reference (direct access)
final float[] initial;
private final boolean clean;
private final FloatArrayCache cache;
Reference(final FloatArrayCache cache, final int initialSize) {
this.cache = cache;
this.clean = cache.clean;
this.initial = createArray(initialSize);
if (DO_STATS) {
cache.stats.totalInitial += initialSize;
}
}
float[] getArray(final int length) {
if (length <= MAX_ARRAY_SIZE) {
return cache.getCacheBucket(length).getArray();
}
if (DO_STATS) {
cache.stats.oversize++;
}
if (DO_LOG_OVERSIZE) { | // Path: src/main/java/com/sun/marlin/ArrayCacheConst.java
// static final int[] ARRAY_SIZES = new int[BUCKETS];
//
// Path: src/main/java/com/sun/marlin/ArrayCacheConst.java
// static final int BUCKETS = 8;
//
// Path: src/main/java/com/sun/marlin/ArrayCacheConst.java
// static final int MAX_ARRAY_SIZE;
//
// Path: src/main/java/com/sun/marlin/MarlinUtils.java
// public static void logInfo(final String msg) {
// if (MarlinConst.USE_LOGGER) {
// LOG.info(msg);
// } else if (MarlinConst.ENABLE_LOGS) {
// System.out.print("INFO: ");
// System.out.println(msg);
// }
// }
//
// Path: src/main/java/com/sun/marlin/MarlinUtils.java
// public static void logException(final String msg, final Throwable th) {
// if (MarlinConst.USE_LOGGER) {
// LOG.log(java.util.logging.Level.WARNING, msg, th);
// } else if (MarlinConst.ENABLE_LOGS) {
// System.out.print("WARNING: ");
// System.out.println(msg);
// th.printStackTrace(System.err);
// }
// }
//
// Path: src/main/java/com/sun/marlin/ArrayCacheConst.java
// static final class BucketStats {
// int getOp = 0;
// int createOp = 0;
// int returnOp = 0;
// int maxSize = 0;
//
// void reset() {
// getOp = 0;
// createOp = 0;
// returnOp = 0;
// maxSize = 0;
// }
//
// void updateMaxSize(final int size) {
// if (size > maxSize) {
// maxSize = size;
// }
// }
// }
//
// Path: src/main/java/com/sun/marlin/ArrayCacheConst.java
// static final class CacheStats {
// final String name;
// final BucketStats[] bucketStats;
// int resize = 0;
// int oversize = 0;
// long totalInitial = 0L;
//
// CacheStats(final String name) {
// this.name = name;
//
// bucketStats = new BucketStats[BUCKETS];
// for (int i = 0; i < BUCKETS; i++) {
// bucketStats[i] = new BucketStats();
// }
// }
//
// void reset() {
// resize = 0;
// oversize = 0;
//
// for (int i = 0; i < BUCKETS; i++) {
// bucketStats[i].reset();
// }
// }
//
// long dumpStats() {
// long totalCacheBytes = 0L;
//
// if (DO_STATS) {
// for (int i = 0; i < BUCKETS; i++) {
// final BucketStats s = bucketStats[i];
//
// if (s.maxSize != 0) {
// totalCacheBytes += getByteFactor()
// * (s.maxSize * ARRAY_SIZES[i]);
// }
// }
//
// if (totalInitial != 0L || totalCacheBytes != 0L
// || resize != 0 || oversize != 0)
// {
// logInfo(name + ": resize: " + resize
// + " - oversize: " + oversize
// + " - initial: " + getTotalInitialBytes()
// + " bytes (" + totalInitial + " elements)"
// + " - cache: " + totalCacheBytes + " bytes"
// );
// }
//
// if (totalCacheBytes != 0L) {
// logInfo(name + ": usage stats:");
//
// for (int i = 0; i < BUCKETS; i++) {
// final BucketStats s = bucketStats[i];
//
// if (s.getOp != 0) {
// logInfo(" Bucket[" + ARRAY_SIZES[i] + "]: "
// + "get: " + s.getOp
// + " - put: " + s.returnOp
// + " - create: " + s.createOp
// + " :: max size: " + s.maxSize
// );
// }
// }
// }
// }
// return totalCacheBytes;
// }
//
// private int getByteFactor() {
// int factor = 1;
// if (name.contains("Int") || name.contains("Float")) {
// factor = 4;
// } else if (name.contains("Double")) {
// factor = 8;
// }
// return factor;
// }
//
// long getTotalInitialBytes() {
// return getByteFactor() * totalInitial;
// }
// }
// Path: src/main/java/com/sun/marlin/FloatArrayCache.java
import java.lang.ref.WeakReference;
import java.util.Arrays;
import com.sun.marlin.ArrayCacheConst.BucketStats;
import com.sun.marlin.ArrayCacheConst.CacheStats;
import static com.sun.marlin.ArrayCacheConst.ARRAY_SIZES;
import static com.sun.marlin.ArrayCacheConst.BUCKETS;
import static com.sun.marlin.ArrayCacheConst.MAX_ARRAY_SIZE;
import static com.sun.marlin.MarlinUtils.logInfo;
import static com.sun.marlin.MarlinUtils.logException;
}
Reference createRef(final int initialSize) {
return new Reference(this, initialSize);
}
static final class Reference {
// initial array reference (direct access)
final float[] initial;
private final boolean clean;
private final FloatArrayCache cache;
Reference(final FloatArrayCache cache, final int initialSize) {
this.cache = cache;
this.clean = cache.clean;
this.initial = createArray(initialSize);
if (DO_STATS) {
cache.stats.totalInitial += initialSize;
}
}
float[] getArray(final int length) {
if (length <= MAX_ARRAY_SIZE) {
return cache.getCacheBucket(length).getArray();
}
if (DO_STATS) {
cache.stats.oversize++;
}
if (DO_LOG_OVERSIZE) { | logInfo(getLogPrefix(clean) + "FloatArrayCache: " |
bourgesl/marlin-fx | src/main/java/com/sun/marlin/FloatArrayCache.java | // Path: src/main/java/com/sun/marlin/ArrayCacheConst.java
// static final int[] ARRAY_SIZES = new int[BUCKETS];
//
// Path: src/main/java/com/sun/marlin/ArrayCacheConst.java
// static final int BUCKETS = 8;
//
// Path: src/main/java/com/sun/marlin/ArrayCacheConst.java
// static final int MAX_ARRAY_SIZE;
//
// Path: src/main/java/com/sun/marlin/MarlinUtils.java
// public static void logInfo(final String msg) {
// if (MarlinConst.USE_LOGGER) {
// LOG.info(msg);
// } else if (MarlinConst.ENABLE_LOGS) {
// System.out.print("INFO: ");
// System.out.println(msg);
// }
// }
//
// Path: src/main/java/com/sun/marlin/MarlinUtils.java
// public static void logException(final String msg, final Throwable th) {
// if (MarlinConst.USE_LOGGER) {
// LOG.log(java.util.logging.Level.WARNING, msg, th);
// } else if (MarlinConst.ENABLE_LOGS) {
// System.out.print("WARNING: ");
// System.out.println(msg);
// th.printStackTrace(System.err);
// }
// }
//
// Path: src/main/java/com/sun/marlin/ArrayCacheConst.java
// static final class BucketStats {
// int getOp = 0;
// int createOp = 0;
// int returnOp = 0;
// int maxSize = 0;
//
// void reset() {
// getOp = 0;
// createOp = 0;
// returnOp = 0;
// maxSize = 0;
// }
//
// void updateMaxSize(final int size) {
// if (size > maxSize) {
// maxSize = size;
// }
// }
// }
//
// Path: src/main/java/com/sun/marlin/ArrayCacheConst.java
// static final class CacheStats {
// final String name;
// final BucketStats[] bucketStats;
// int resize = 0;
// int oversize = 0;
// long totalInitial = 0L;
//
// CacheStats(final String name) {
// this.name = name;
//
// bucketStats = new BucketStats[BUCKETS];
// for (int i = 0; i < BUCKETS; i++) {
// bucketStats[i] = new BucketStats();
// }
// }
//
// void reset() {
// resize = 0;
// oversize = 0;
//
// for (int i = 0; i < BUCKETS; i++) {
// bucketStats[i].reset();
// }
// }
//
// long dumpStats() {
// long totalCacheBytes = 0L;
//
// if (DO_STATS) {
// for (int i = 0; i < BUCKETS; i++) {
// final BucketStats s = bucketStats[i];
//
// if (s.maxSize != 0) {
// totalCacheBytes += getByteFactor()
// * (s.maxSize * ARRAY_SIZES[i]);
// }
// }
//
// if (totalInitial != 0L || totalCacheBytes != 0L
// || resize != 0 || oversize != 0)
// {
// logInfo(name + ": resize: " + resize
// + " - oversize: " + oversize
// + " - initial: " + getTotalInitialBytes()
// + " bytes (" + totalInitial + " elements)"
// + " - cache: " + totalCacheBytes + " bytes"
// );
// }
//
// if (totalCacheBytes != 0L) {
// logInfo(name + ": usage stats:");
//
// for (int i = 0; i < BUCKETS; i++) {
// final BucketStats s = bucketStats[i];
//
// if (s.getOp != 0) {
// logInfo(" Bucket[" + ARRAY_SIZES[i] + "]: "
// + "get: " + s.getOp
// + " - put: " + s.returnOp
// + " - create: " + s.createOp
// + " :: max size: " + s.maxSize
// );
// }
// }
// }
// }
// return totalCacheBytes;
// }
//
// private int getByteFactor() {
// int factor = 1;
// if (name.contains("Int") || name.contains("Float")) {
// factor = 4;
// } else if (name.contains("Double")) {
// factor = 8;
// }
// return factor;
// }
//
// long getTotalInitialBytes() {
// return getByteFactor() * totalInitial;
// }
// }
| import java.lang.ref.WeakReference;
import java.util.Arrays;
import com.sun.marlin.ArrayCacheConst.BucketStats;
import com.sun.marlin.ArrayCacheConst.CacheStats;
import static com.sun.marlin.ArrayCacheConst.ARRAY_SIZES;
import static com.sun.marlin.ArrayCacheConst.BUCKETS;
import static com.sun.marlin.ArrayCacheConst.MAX_ARRAY_SIZE;
import static com.sun.marlin.MarlinUtils.logInfo;
import static com.sun.marlin.MarlinUtils.logException; |
float[] putArray(final float[] array)
{
// dirty array helper:
return putArray(array, 0, array.length);
}
float[] putArray(final float[] array, final int fromIndex,
final int toIndex)
{
if (array.length <= MAX_ARRAY_SIZE) {
if ((clean || DO_CLEAN_DIRTY) && (toIndex != 0)) {
// clean-up array of dirty part[fromIndex; toIndex[
fill(array, fromIndex, toIndex, 0.0f);
}
// ensure to never store initial arrays in cache:
if (array != initial) {
cache.getCacheBucket(array.length).putArray(array);
}
}
return initial;
}
}
static final class Bucket {
private int tail = 0;
private final int arraySize;
private final boolean clean;
private final float[][] arrays; | // Path: src/main/java/com/sun/marlin/ArrayCacheConst.java
// static final int[] ARRAY_SIZES = new int[BUCKETS];
//
// Path: src/main/java/com/sun/marlin/ArrayCacheConst.java
// static final int BUCKETS = 8;
//
// Path: src/main/java/com/sun/marlin/ArrayCacheConst.java
// static final int MAX_ARRAY_SIZE;
//
// Path: src/main/java/com/sun/marlin/MarlinUtils.java
// public static void logInfo(final String msg) {
// if (MarlinConst.USE_LOGGER) {
// LOG.info(msg);
// } else if (MarlinConst.ENABLE_LOGS) {
// System.out.print("INFO: ");
// System.out.println(msg);
// }
// }
//
// Path: src/main/java/com/sun/marlin/MarlinUtils.java
// public static void logException(final String msg, final Throwable th) {
// if (MarlinConst.USE_LOGGER) {
// LOG.log(java.util.logging.Level.WARNING, msg, th);
// } else if (MarlinConst.ENABLE_LOGS) {
// System.out.print("WARNING: ");
// System.out.println(msg);
// th.printStackTrace(System.err);
// }
// }
//
// Path: src/main/java/com/sun/marlin/ArrayCacheConst.java
// static final class BucketStats {
// int getOp = 0;
// int createOp = 0;
// int returnOp = 0;
// int maxSize = 0;
//
// void reset() {
// getOp = 0;
// createOp = 0;
// returnOp = 0;
// maxSize = 0;
// }
//
// void updateMaxSize(final int size) {
// if (size > maxSize) {
// maxSize = size;
// }
// }
// }
//
// Path: src/main/java/com/sun/marlin/ArrayCacheConst.java
// static final class CacheStats {
// final String name;
// final BucketStats[] bucketStats;
// int resize = 0;
// int oversize = 0;
// long totalInitial = 0L;
//
// CacheStats(final String name) {
// this.name = name;
//
// bucketStats = new BucketStats[BUCKETS];
// for (int i = 0; i < BUCKETS; i++) {
// bucketStats[i] = new BucketStats();
// }
// }
//
// void reset() {
// resize = 0;
// oversize = 0;
//
// for (int i = 0; i < BUCKETS; i++) {
// bucketStats[i].reset();
// }
// }
//
// long dumpStats() {
// long totalCacheBytes = 0L;
//
// if (DO_STATS) {
// for (int i = 0; i < BUCKETS; i++) {
// final BucketStats s = bucketStats[i];
//
// if (s.maxSize != 0) {
// totalCacheBytes += getByteFactor()
// * (s.maxSize * ARRAY_SIZES[i]);
// }
// }
//
// if (totalInitial != 0L || totalCacheBytes != 0L
// || resize != 0 || oversize != 0)
// {
// logInfo(name + ": resize: " + resize
// + " - oversize: " + oversize
// + " - initial: " + getTotalInitialBytes()
// + " bytes (" + totalInitial + " elements)"
// + " - cache: " + totalCacheBytes + " bytes"
// );
// }
//
// if (totalCacheBytes != 0L) {
// logInfo(name + ": usage stats:");
//
// for (int i = 0; i < BUCKETS; i++) {
// final BucketStats s = bucketStats[i];
//
// if (s.getOp != 0) {
// logInfo(" Bucket[" + ARRAY_SIZES[i] + "]: "
// + "get: " + s.getOp
// + " - put: " + s.returnOp
// + " - create: " + s.createOp
// + " :: max size: " + s.maxSize
// );
// }
// }
// }
// }
// return totalCacheBytes;
// }
//
// private int getByteFactor() {
// int factor = 1;
// if (name.contains("Int") || name.contains("Float")) {
// factor = 4;
// } else if (name.contains("Double")) {
// factor = 8;
// }
// return factor;
// }
//
// long getTotalInitialBytes() {
// return getByteFactor() * totalInitial;
// }
// }
// Path: src/main/java/com/sun/marlin/FloatArrayCache.java
import java.lang.ref.WeakReference;
import java.util.Arrays;
import com.sun.marlin.ArrayCacheConst.BucketStats;
import com.sun.marlin.ArrayCacheConst.CacheStats;
import static com.sun.marlin.ArrayCacheConst.ARRAY_SIZES;
import static com.sun.marlin.ArrayCacheConst.BUCKETS;
import static com.sun.marlin.ArrayCacheConst.MAX_ARRAY_SIZE;
import static com.sun.marlin.MarlinUtils.logInfo;
import static com.sun.marlin.MarlinUtils.logException;
float[] putArray(final float[] array)
{
// dirty array helper:
return putArray(array, 0, array.length);
}
float[] putArray(final float[] array, final int fromIndex,
final int toIndex)
{
if (array.length <= MAX_ARRAY_SIZE) {
if ((clean || DO_CLEAN_DIRTY) && (toIndex != 0)) {
// clean-up array of dirty part[fromIndex; toIndex[
fill(array, fromIndex, toIndex, 0.0f);
}
// ensure to never store initial arrays in cache:
if (array != initial) {
cache.getCacheBucket(array.length).putArray(array);
}
}
return initial;
}
}
static final class Bucket {
private int tail = 0;
private final int arraySize;
private final boolean clean;
private final float[][] arrays; | private final BucketStats stats; |
bourgesl/marlin-fx | src/main/java/com/sun/marlin/FloatArrayCache.java | // Path: src/main/java/com/sun/marlin/ArrayCacheConst.java
// static final int[] ARRAY_SIZES = new int[BUCKETS];
//
// Path: src/main/java/com/sun/marlin/ArrayCacheConst.java
// static final int BUCKETS = 8;
//
// Path: src/main/java/com/sun/marlin/ArrayCacheConst.java
// static final int MAX_ARRAY_SIZE;
//
// Path: src/main/java/com/sun/marlin/MarlinUtils.java
// public static void logInfo(final String msg) {
// if (MarlinConst.USE_LOGGER) {
// LOG.info(msg);
// } else if (MarlinConst.ENABLE_LOGS) {
// System.out.print("INFO: ");
// System.out.println(msg);
// }
// }
//
// Path: src/main/java/com/sun/marlin/MarlinUtils.java
// public static void logException(final String msg, final Throwable th) {
// if (MarlinConst.USE_LOGGER) {
// LOG.log(java.util.logging.Level.WARNING, msg, th);
// } else if (MarlinConst.ENABLE_LOGS) {
// System.out.print("WARNING: ");
// System.out.println(msg);
// th.printStackTrace(System.err);
// }
// }
//
// Path: src/main/java/com/sun/marlin/ArrayCacheConst.java
// static final class BucketStats {
// int getOp = 0;
// int createOp = 0;
// int returnOp = 0;
// int maxSize = 0;
//
// void reset() {
// getOp = 0;
// createOp = 0;
// returnOp = 0;
// maxSize = 0;
// }
//
// void updateMaxSize(final int size) {
// if (size > maxSize) {
// maxSize = size;
// }
// }
// }
//
// Path: src/main/java/com/sun/marlin/ArrayCacheConst.java
// static final class CacheStats {
// final String name;
// final BucketStats[] bucketStats;
// int resize = 0;
// int oversize = 0;
// long totalInitial = 0L;
//
// CacheStats(final String name) {
// this.name = name;
//
// bucketStats = new BucketStats[BUCKETS];
// for (int i = 0; i < BUCKETS; i++) {
// bucketStats[i] = new BucketStats();
// }
// }
//
// void reset() {
// resize = 0;
// oversize = 0;
//
// for (int i = 0; i < BUCKETS; i++) {
// bucketStats[i].reset();
// }
// }
//
// long dumpStats() {
// long totalCacheBytes = 0L;
//
// if (DO_STATS) {
// for (int i = 0; i < BUCKETS; i++) {
// final BucketStats s = bucketStats[i];
//
// if (s.maxSize != 0) {
// totalCacheBytes += getByteFactor()
// * (s.maxSize * ARRAY_SIZES[i]);
// }
// }
//
// if (totalInitial != 0L || totalCacheBytes != 0L
// || resize != 0 || oversize != 0)
// {
// logInfo(name + ": resize: " + resize
// + " - oversize: " + oversize
// + " - initial: " + getTotalInitialBytes()
// + " bytes (" + totalInitial + " elements)"
// + " - cache: " + totalCacheBytes + " bytes"
// );
// }
//
// if (totalCacheBytes != 0L) {
// logInfo(name + ": usage stats:");
//
// for (int i = 0; i < BUCKETS; i++) {
// final BucketStats s = bucketStats[i];
//
// if (s.getOp != 0) {
// logInfo(" Bucket[" + ARRAY_SIZES[i] + "]: "
// + "get: " + s.getOp
// + " - put: " + s.returnOp
// + " - create: " + s.createOp
// + " :: max size: " + s.maxSize
// );
// }
// }
// }
// }
// return totalCacheBytes;
// }
//
// private int getByteFactor() {
// int factor = 1;
// if (name.contains("Int") || name.contains("Float")) {
// factor = 4;
// } else if (name.contains("Double")) {
// factor = 8;
// }
// return factor;
// }
//
// long getTotalInitialBytes() {
// return getByteFactor() * totalInitial;
// }
// }
| import java.lang.ref.WeakReference;
import java.util.Arrays;
import com.sun.marlin.ArrayCacheConst.BucketStats;
import com.sun.marlin.ArrayCacheConst.CacheStats;
import static com.sun.marlin.ArrayCacheConst.ARRAY_SIZES;
import static com.sun.marlin.ArrayCacheConst.BUCKETS;
import static com.sun.marlin.ArrayCacheConst.MAX_ARRAY_SIZE;
import static com.sun.marlin.MarlinUtils.logInfo;
import static com.sun.marlin.MarlinUtils.logException; | stats.updateMaxSize(tail);
}
} else if (DO_CHECKS) {
logInfo(getLogPrefix(clean) + "FloatArrayCache: "
+ "array capacity exceeded !");
}
}
}
static float[] createArray(final int length) {
return new float[length];
}
static void fill(final float[] array, final int fromIndex,
final int toIndex, final float value)
{
// clear array data:
Arrays.fill(array, fromIndex, toIndex, value);
if (DO_CHECKS) {
check(array, fromIndex, toIndex, value);
}
}
public static void check(final float[] array, final int fromIndex,
final int toIndex, final float value)
{
if (DO_CHECKS) {
// check zero on full array:
for (int i = 0; i < array.length; i++) {
if (array[i] != value) { | // Path: src/main/java/com/sun/marlin/ArrayCacheConst.java
// static final int[] ARRAY_SIZES = new int[BUCKETS];
//
// Path: src/main/java/com/sun/marlin/ArrayCacheConst.java
// static final int BUCKETS = 8;
//
// Path: src/main/java/com/sun/marlin/ArrayCacheConst.java
// static final int MAX_ARRAY_SIZE;
//
// Path: src/main/java/com/sun/marlin/MarlinUtils.java
// public static void logInfo(final String msg) {
// if (MarlinConst.USE_LOGGER) {
// LOG.info(msg);
// } else if (MarlinConst.ENABLE_LOGS) {
// System.out.print("INFO: ");
// System.out.println(msg);
// }
// }
//
// Path: src/main/java/com/sun/marlin/MarlinUtils.java
// public static void logException(final String msg, final Throwable th) {
// if (MarlinConst.USE_LOGGER) {
// LOG.log(java.util.logging.Level.WARNING, msg, th);
// } else if (MarlinConst.ENABLE_LOGS) {
// System.out.print("WARNING: ");
// System.out.println(msg);
// th.printStackTrace(System.err);
// }
// }
//
// Path: src/main/java/com/sun/marlin/ArrayCacheConst.java
// static final class BucketStats {
// int getOp = 0;
// int createOp = 0;
// int returnOp = 0;
// int maxSize = 0;
//
// void reset() {
// getOp = 0;
// createOp = 0;
// returnOp = 0;
// maxSize = 0;
// }
//
// void updateMaxSize(final int size) {
// if (size > maxSize) {
// maxSize = size;
// }
// }
// }
//
// Path: src/main/java/com/sun/marlin/ArrayCacheConst.java
// static final class CacheStats {
// final String name;
// final BucketStats[] bucketStats;
// int resize = 0;
// int oversize = 0;
// long totalInitial = 0L;
//
// CacheStats(final String name) {
// this.name = name;
//
// bucketStats = new BucketStats[BUCKETS];
// for (int i = 0; i < BUCKETS; i++) {
// bucketStats[i] = new BucketStats();
// }
// }
//
// void reset() {
// resize = 0;
// oversize = 0;
//
// for (int i = 0; i < BUCKETS; i++) {
// bucketStats[i].reset();
// }
// }
//
// long dumpStats() {
// long totalCacheBytes = 0L;
//
// if (DO_STATS) {
// for (int i = 0; i < BUCKETS; i++) {
// final BucketStats s = bucketStats[i];
//
// if (s.maxSize != 0) {
// totalCacheBytes += getByteFactor()
// * (s.maxSize * ARRAY_SIZES[i]);
// }
// }
//
// if (totalInitial != 0L || totalCacheBytes != 0L
// || resize != 0 || oversize != 0)
// {
// logInfo(name + ": resize: " + resize
// + " - oversize: " + oversize
// + " - initial: " + getTotalInitialBytes()
// + " bytes (" + totalInitial + " elements)"
// + " - cache: " + totalCacheBytes + " bytes"
// );
// }
//
// if (totalCacheBytes != 0L) {
// logInfo(name + ": usage stats:");
//
// for (int i = 0; i < BUCKETS; i++) {
// final BucketStats s = bucketStats[i];
//
// if (s.getOp != 0) {
// logInfo(" Bucket[" + ARRAY_SIZES[i] + "]: "
// + "get: " + s.getOp
// + " - put: " + s.returnOp
// + " - create: " + s.createOp
// + " :: max size: " + s.maxSize
// );
// }
// }
// }
// }
// return totalCacheBytes;
// }
//
// private int getByteFactor() {
// int factor = 1;
// if (name.contains("Int") || name.contains("Float")) {
// factor = 4;
// } else if (name.contains("Double")) {
// factor = 8;
// }
// return factor;
// }
//
// long getTotalInitialBytes() {
// return getByteFactor() * totalInitial;
// }
// }
// Path: src/main/java/com/sun/marlin/FloatArrayCache.java
import java.lang.ref.WeakReference;
import java.util.Arrays;
import com.sun.marlin.ArrayCacheConst.BucketStats;
import com.sun.marlin.ArrayCacheConst.CacheStats;
import static com.sun.marlin.ArrayCacheConst.ARRAY_SIZES;
import static com.sun.marlin.ArrayCacheConst.BUCKETS;
import static com.sun.marlin.ArrayCacheConst.MAX_ARRAY_SIZE;
import static com.sun.marlin.MarlinUtils.logInfo;
import static com.sun.marlin.MarlinUtils.logException;
stats.updateMaxSize(tail);
}
} else if (DO_CHECKS) {
logInfo(getLogPrefix(clean) + "FloatArrayCache: "
+ "array capacity exceeded !");
}
}
}
static float[] createArray(final int length) {
return new float[length];
}
static void fill(final float[] array, final int fromIndex,
final int toIndex, final float value)
{
// clear array data:
Arrays.fill(array, fromIndex, toIndex, value);
if (DO_CHECKS) {
check(array, fromIndex, toIndex, value);
}
}
public static void check(final float[] array, final int fromIndex,
final int toIndex, final float value)
{
if (DO_CHECKS) {
// check zero on full array:
for (int i = 0; i < array.length; i++) {
if (array[i] != value) { | logException("Invalid value at: " + i + " = " + array[i] |
bourgesl/marlin-fx | src/main/java/com/sun/marlin/DRendererNoAA.java | // Path: src/main/java/com/sun/marlin/OffHeapArray.java
// static final int SIZE_INT;
| import static com.sun.marlin.OffHeapArray.SIZE_INT;
import sun.misc.Unsafe; | /*
* Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code 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 General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.marlin;
public final class DRendererNoAA implements DMarlinRenderer, MarlinConst {
static final boolean DISABLE_RENDER = false;
private static final int ALL_BUT_LSB = 0xFFFFFFFE;
private static final int ERR_STEP_MAX = 0x7FFFFFFF; // = 2^31 - 1
private static final double POWER_2_TO_32 = 0x1.0p32d;
private static final double RDR_OFFSET_X = 0.5d;
private static final double RDR_OFFSET_Y = 0.5d;
// common to all types of input path segments.
// OFFSET as bytes
// only integer values:
public static final long OFF_CURX_OR = 0; | // Path: src/main/java/com/sun/marlin/OffHeapArray.java
// static final int SIZE_INT;
// Path: src/main/java/com/sun/marlin/DRendererNoAA.java
import static com.sun.marlin.OffHeapArray.SIZE_INT;
import sun.misc.Unsafe;
/*
* Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code 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 General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.marlin;
public final class DRendererNoAA implements DMarlinRenderer, MarlinConst {
static final boolean DISABLE_RENDER = false;
private static final int ALL_BUT_LSB = 0xFFFFFFFE;
private static final int ERR_STEP_MAX = 0x7FFFFFFF; // = 2^31 - 1
private static final double POWER_2_TO_32 = 0x1.0p32d;
private static final double RDR_OFFSET_X = 0.5d;
private static final double RDR_OFFSET_Y = 0.5d;
// common to all types of input path segments.
// OFFSET as bytes
// only integer values:
public static final long OFF_CURX_OR = 0; | public static final long OFF_ERROR = OFF_CURX_OR + SIZE_INT; |
bourgesl/marlin-fx | src/main/java/com/sun/marlin/IntArrayCache.java | // Path: src/main/java/com/sun/marlin/ArrayCacheConst.java
// static final int[] ARRAY_SIZES = new int[BUCKETS];
//
// Path: src/main/java/com/sun/marlin/ArrayCacheConst.java
// static final int BUCKETS = 8;
//
// Path: src/main/java/com/sun/marlin/ArrayCacheConst.java
// static final int MAX_ARRAY_SIZE;
//
// Path: src/main/java/com/sun/marlin/MarlinUtils.java
// public static void logInfo(final String msg) {
// if (MarlinConst.USE_LOGGER) {
// LOG.info(msg);
// } else if (MarlinConst.ENABLE_LOGS) {
// System.out.print("INFO: ");
// System.out.println(msg);
// }
// }
//
// Path: src/main/java/com/sun/marlin/MarlinUtils.java
// public static void logException(final String msg, final Throwable th) {
// if (MarlinConst.USE_LOGGER) {
// LOG.log(java.util.logging.Level.WARNING, msg, th);
// } else if (MarlinConst.ENABLE_LOGS) {
// System.out.print("WARNING: ");
// System.out.println(msg);
// th.printStackTrace(System.err);
// }
// }
//
// Path: src/main/java/com/sun/marlin/ArrayCacheConst.java
// static final class BucketStats {
// int getOp = 0;
// int createOp = 0;
// int returnOp = 0;
// int maxSize = 0;
//
// void reset() {
// getOp = 0;
// createOp = 0;
// returnOp = 0;
// maxSize = 0;
// }
//
// void updateMaxSize(final int size) {
// if (size > maxSize) {
// maxSize = size;
// }
// }
// }
//
// Path: src/main/java/com/sun/marlin/ArrayCacheConst.java
// static final class CacheStats {
// final String name;
// final BucketStats[] bucketStats;
// int resize = 0;
// int oversize = 0;
// long totalInitial = 0L;
//
// CacheStats(final String name) {
// this.name = name;
//
// bucketStats = new BucketStats[BUCKETS];
// for (int i = 0; i < BUCKETS; i++) {
// bucketStats[i] = new BucketStats();
// }
// }
//
// void reset() {
// resize = 0;
// oversize = 0;
//
// for (int i = 0; i < BUCKETS; i++) {
// bucketStats[i].reset();
// }
// }
//
// long dumpStats() {
// long totalCacheBytes = 0L;
//
// if (DO_STATS) {
// for (int i = 0; i < BUCKETS; i++) {
// final BucketStats s = bucketStats[i];
//
// if (s.maxSize != 0) {
// totalCacheBytes += getByteFactor()
// * (s.maxSize * ARRAY_SIZES[i]);
// }
// }
//
// if (totalInitial != 0L || totalCacheBytes != 0L
// || resize != 0 || oversize != 0)
// {
// logInfo(name + ": resize: " + resize
// + " - oversize: " + oversize
// + " - initial: " + getTotalInitialBytes()
// + " bytes (" + totalInitial + " elements)"
// + " - cache: " + totalCacheBytes + " bytes"
// );
// }
//
// if (totalCacheBytes != 0L) {
// logInfo(name + ": usage stats:");
//
// for (int i = 0; i < BUCKETS; i++) {
// final BucketStats s = bucketStats[i];
//
// if (s.getOp != 0) {
// logInfo(" Bucket[" + ARRAY_SIZES[i] + "]: "
// + "get: " + s.getOp
// + " - put: " + s.returnOp
// + " - create: " + s.createOp
// + " :: max size: " + s.maxSize
// );
// }
// }
// }
// }
// return totalCacheBytes;
// }
//
// private int getByteFactor() {
// int factor = 1;
// if (name.contains("Int") || name.contains("Float")) {
// factor = 4;
// } else if (name.contains("Double")) {
// factor = 8;
// }
// return factor;
// }
//
// long getTotalInitialBytes() {
// return getByteFactor() * totalInitial;
// }
// }
| import java.lang.ref.WeakReference;
import java.util.Arrays;
import com.sun.marlin.ArrayCacheConst.BucketStats;
import com.sun.marlin.ArrayCacheConst.CacheStats;
import static com.sun.marlin.ArrayCacheConst.ARRAY_SIZES;
import static com.sun.marlin.ArrayCacheConst.BUCKETS;
import static com.sun.marlin.ArrayCacheConst.MAX_ARRAY_SIZE;
import static com.sun.marlin.MarlinUtils.logInfo;
import static com.sun.marlin.MarlinUtils.logException; | (DO_STATS) ? stats.bucketStats[i] : null);
}
// update weak reference:
refBuckets = new WeakReference<Bucket[]>(buckets);
}
return buckets;
}
Reference createRef(final int initialSize) {
return new Reference(this, initialSize);
}
static final class Reference {
// initial array reference (direct access)
final int[] initial;
private final boolean clean;
private final IntArrayCache cache;
Reference(final IntArrayCache cache, final int initialSize) {
this.cache = cache;
this.clean = cache.clean;
this.initial = createArray(initialSize);
if (DO_STATS) {
cache.stats.totalInitial += initialSize;
}
}
int[] getArray(final int length) { | // Path: src/main/java/com/sun/marlin/ArrayCacheConst.java
// static final int[] ARRAY_SIZES = new int[BUCKETS];
//
// Path: src/main/java/com/sun/marlin/ArrayCacheConst.java
// static final int BUCKETS = 8;
//
// Path: src/main/java/com/sun/marlin/ArrayCacheConst.java
// static final int MAX_ARRAY_SIZE;
//
// Path: src/main/java/com/sun/marlin/MarlinUtils.java
// public static void logInfo(final String msg) {
// if (MarlinConst.USE_LOGGER) {
// LOG.info(msg);
// } else if (MarlinConst.ENABLE_LOGS) {
// System.out.print("INFO: ");
// System.out.println(msg);
// }
// }
//
// Path: src/main/java/com/sun/marlin/MarlinUtils.java
// public static void logException(final String msg, final Throwable th) {
// if (MarlinConst.USE_LOGGER) {
// LOG.log(java.util.logging.Level.WARNING, msg, th);
// } else if (MarlinConst.ENABLE_LOGS) {
// System.out.print("WARNING: ");
// System.out.println(msg);
// th.printStackTrace(System.err);
// }
// }
//
// Path: src/main/java/com/sun/marlin/ArrayCacheConst.java
// static final class BucketStats {
// int getOp = 0;
// int createOp = 0;
// int returnOp = 0;
// int maxSize = 0;
//
// void reset() {
// getOp = 0;
// createOp = 0;
// returnOp = 0;
// maxSize = 0;
// }
//
// void updateMaxSize(final int size) {
// if (size > maxSize) {
// maxSize = size;
// }
// }
// }
//
// Path: src/main/java/com/sun/marlin/ArrayCacheConst.java
// static final class CacheStats {
// final String name;
// final BucketStats[] bucketStats;
// int resize = 0;
// int oversize = 0;
// long totalInitial = 0L;
//
// CacheStats(final String name) {
// this.name = name;
//
// bucketStats = new BucketStats[BUCKETS];
// for (int i = 0; i < BUCKETS; i++) {
// bucketStats[i] = new BucketStats();
// }
// }
//
// void reset() {
// resize = 0;
// oversize = 0;
//
// for (int i = 0; i < BUCKETS; i++) {
// bucketStats[i].reset();
// }
// }
//
// long dumpStats() {
// long totalCacheBytes = 0L;
//
// if (DO_STATS) {
// for (int i = 0; i < BUCKETS; i++) {
// final BucketStats s = bucketStats[i];
//
// if (s.maxSize != 0) {
// totalCacheBytes += getByteFactor()
// * (s.maxSize * ARRAY_SIZES[i]);
// }
// }
//
// if (totalInitial != 0L || totalCacheBytes != 0L
// || resize != 0 || oversize != 0)
// {
// logInfo(name + ": resize: " + resize
// + " - oversize: " + oversize
// + " - initial: " + getTotalInitialBytes()
// + " bytes (" + totalInitial + " elements)"
// + " - cache: " + totalCacheBytes + " bytes"
// );
// }
//
// if (totalCacheBytes != 0L) {
// logInfo(name + ": usage stats:");
//
// for (int i = 0; i < BUCKETS; i++) {
// final BucketStats s = bucketStats[i];
//
// if (s.getOp != 0) {
// logInfo(" Bucket[" + ARRAY_SIZES[i] + "]: "
// + "get: " + s.getOp
// + " - put: " + s.returnOp
// + " - create: " + s.createOp
// + " :: max size: " + s.maxSize
// );
// }
// }
// }
// }
// return totalCacheBytes;
// }
//
// private int getByteFactor() {
// int factor = 1;
// if (name.contains("Int") || name.contains("Float")) {
// factor = 4;
// } else if (name.contains("Double")) {
// factor = 8;
// }
// return factor;
// }
//
// long getTotalInitialBytes() {
// return getByteFactor() * totalInitial;
// }
// }
// Path: src/main/java/com/sun/marlin/IntArrayCache.java
import java.lang.ref.WeakReference;
import java.util.Arrays;
import com.sun.marlin.ArrayCacheConst.BucketStats;
import com.sun.marlin.ArrayCacheConst.CacheStats;
import static com.sun.marlin.ArrayCacheConst.ARRAY_SIZES;
import static com.sun.marlin.ArrayCacheConst.BUCKETS;
import static com.sun.marlin.ArrayCacheConst.MAX_ARRAY_SIZE;
import static com.sun.marlin.MarlinUtils.logInfo;
import static com.sun.marlin.MarlinUtils.logException;
(DO_STATS) ? stats.bucketStats[i] : null);
}
// update weak reference:
refBuckets = new WeakReference<Bucket[]>(buckets);
}
return buckets;
}
Reference createRef(final int initialSize) {
return new Reference(this, initialSize);
}
static final class Reference {
// initial array reference (direct access)
final int[] initial;
private final boolean clean;
private final IntArrayCache cache;
Reference(final IntArrayCache cache, final int initialSize) {
this.cache = cache;
this.clean = cache.clean;
this.initial = createArray(initialSize);
if (DO_STATS) {
cache.stats.totalInitial += initialSize;
}
}
int[] getArray(final int length) { | if (length <= MAX_ARRAY_SIZE) { |
bourgesl/marlin-fx | src/main/java/com/sun/marlin/IntArrayCache.java | // Path: src/main/java/com/sun/marlin/ArrayCacheConst.java
// static final int[] ARRAY_SIZES = new int[BUCKETS];
//
// Path: src/main/java/com/sun/marlin/ArrayCacheConst.java
// static final int BUCKETS = 8;
//
// Path: src/main/java/com/sun/marlin/ArrayCacheConst.java
// static final int MAX_ARRAY_SIZE;
//
// Path: src/main/java/com/sun/marlin/MarlinUtils.java
// public static void logInfo(final String msg) {
// if (MarlinConst.USE_LOGGER) {
// LOG.info(msg);
// } else if (MarlinConst.ENABLE_LOGS) {
// System.out.print("INFO: ");
// System.out.println(msg);
// }
// }
//
// Path: src/main/java/com/sun/marlin/MarlinUtils.java
// public static void logException(final String msg, final Throwable th) {
// if (MarlinConst.USE_LOGGER) {
// LOG.log(java.util.logging.Level.WARNING, msg, th);
// } else if (MarlinConst.ENABLE_LOGS) {
// System.out.print("WARNING: ");
// System.out.println(msg);
// th.printStackTrace(System.err);
// }
// }
//
// Path: src/main/java/com/sun/marlin/ArrayCacheConst.java
// static final class BucketStats {
// int getOp = 0;
// int createOp = 0;
// int returnOp = 0;
// int maxSize = 0;
//
// void reset() {
// getOp = 0;
// createOp = 0;
// returnOp = 0;
// maxSize = 0;
// }
//
// void updateMaxSize(final int size) {
// if (size > maxSize) {
// maxSize = size;
// }
// }
// }
//
// Path: src/main/java/com/sun/marlin/ArrayCacheConst.java
// static final class CacheStats {
// final String name;
// final BucketStats[] bucketStats;
// int resize = 0;
// int oversize = 0;
// long totalInitial = 0L;
//
// CacheStats(final String name) {
// this.name = name;
//
// bucketStats = new BucketStats[BUCKETS];
// for (int i = 0; i < BUCKETS; i++) {
// bucketStats[i] = new BucketStats();
// }
// }
//
// void reset() {
// resize = 0;
// oversize = 0;
//
// for (int i = 0; i < BUCKETS; i++) {
// bucketStats[i].reset();
// }
// }
//
// long dumpStats() {
// long totalCacheBytes = 0L;
//
// if (DO_STATS) {
// for (int i = 0; i < BUCKETS; i++) {
// final BucketStats s = bucketStats[i];
//
// if (s.maxSize != 0) {
// totalCacheBytes += getByteFactor()
// * (s.maxSize * ARRAY_SIZES[i]);
// }
// }
//
// if (totalInitial != 0L || totalCacheBytes != 0L
// || resize != 0 || oversize != 0)
// {
// logInfo(name + ": resize: " + resize
// + " - oversize: " + oversize
// + " - initial: " + getTotalInitialBytes()
// + " bytes (" + totalInitial + " elements)"
// + " - cache: " + totalCacheBytes + " bytes"
// );
// }
//
// if (totalCacheBytes != 0L) {
// logInfo(name + ": usage stats:");
//
// for (int i = 0; i < BUCKETS; i++) {
// final BucketStats s = bucketStats[i];
//
// if (s.getOp != 0) {
// logInfo(" Bucket[" + ARRAY_SIZES[i] + "]: "
// + "get: " + s.getOp
// + " - put: " + s.returnOp
// + " - create: " + s.createOp
// + " :: max size: " + s.maxSize
// );
// }
// }
// }
// }
// return totalCacheBytes;
// }
//
// private int getByteFactor() {
// int factor = 1;
// if (name.contains("Int") || name.contains("Float")) {
// factor = 4;
// } else if (name.contains("Double")) {
// factor = 8;
// }
// return factor;
// }
//
// long getTotalInitialBytes() {
// return getByteFactor() * totalInitial;
// }
// }
| import java.lang.ref.WeakReference;
import java.util.Arrays;
import com.sun.marlin.ArrayCacheConst.BucketStats;
import com.sun.marlin.ArrayCacheConst.CacheStats;
import static com.sun.marlin.ArrayCacheConst.ARRAY_SIZES;
import static com.sun.marlin.ArrayCacheConst.BUCKETS;
import static com.sun.marlin.ArrayCacheConst.MAX_ARRAY_SIZE;
import static com.sun.marlin.MarlinUtils.logInfo;
import static com.sun.marlin.MarlinUtils.logException; | }
Reference createRef(final int initialSize) {
return new Reference(this, initialSize);
}
static final class Reference {
// initial array reference (direct access)
final int[] initial;
private final boolean clean;
private final IntArrayCache cache;
Reference(final IntArrayCache cache, final int initialSize) {
this.cache = cache;
this.clean = cache.clean;
this.initial = createArray(initialSize);
if (DO_STATS) {
cache.stats.totalInitial += initialSize;
}
}
int[] getArray(final int length) {
if (length <= MAX_ARRAY_SIZE) {
return cache.getCacheBucket(length).getArray();
}
if (DO_STATS) {
cache.stats.oversize++;
}
if (DO_LOG_OVERSIZE) { | // Path: src/main/java/com/sun/marlin/ArrayCacheConst.java
// static final int[] ARRAY_SIZES = new int[BUCKETS];
//
// Path: src/main/java/com/sun/marlin/ArrayCacheConst.java
// static final int BUCKETS = 8;
//
// Path: src/main/java/com/sun/marlin/ArrayCacheConst.java
// static final int MAX_ARRAY_SIZE;
//
// Path: src/main/java/com/sun/marlin/MarlinUtils.java
// public static void logInfo(final String msg) {
// if (MarlinConst.USE_LOGGER) {
// LOG.info(msg);
// } else if (MarlinConst.ENABLE_LOGS) {
// System.out.print("INFO: ");
// System.out.println(msg);
// }
// }
//
// Path: src/main/java/com/sun/marlin/MarlinUtils.java
// public static void logException(final String msg, final Throwable th) {
// if (MarlinConst.USE_LOGGER) {
// LOG.log(java.util.logging.Level.WARNING, msg, th);
// } else if (MarlinConst.ENABLE_LOGS) {
// System.out.print("WARNING: ");
// System.out.println(msg);
// th.printStackTrace(System.err);
// }
// }
//
// Path: src/main/java/com/sun/marlin/ArrayCacheConst.java
// static final class BucketStats {
// int getOp = 0;
// int createOp = 0;
// int returnOp = 0;
// int maxSize = 0;
//
// void reset() {
// getOp = 0;
// createOp = 0;
// returnOp = 0;
// maxSize = 0;
// }
//
// void updateMaxSize(final int size) {
// if (size > maxSize) {
// maxSize = size;
// }
// }
// }
//
// Path: src/main/java/com/sun/marlin/ArrayCacheConst.java
// static final class CacheStats {
// final String name;
// final BucketStats[] bucketStats;
// int resize = 0;
// int oversize = 0;
// long totalInitial = 0L;
//
// CacheStats(final String name) {
// this.name = name;
//
// bucketStats = new BucketStats[BUCKETS];
// for (int i = 0; i < BUCKETS; i++) {
// bucketStats[i] = new BucketStats();
// }
// }
//
// void reset() {
// resize = 0;
// oversize = 0;
//
// for (int i = 0; i < BUCKETS; i++) {
// bucketStats[i].reset();
// }
// }
//
// long dumpStats() {
// long totalCacheBytes = 0L;
//
// if (DO_STATS) {
// for (int i = 0; i < BUCKETS; i++) {
// final BucketStats s = bucketStats[i];
//
// if (s.maxSize != 0) {
// totalCacheBytes += getByteFactor()
// * (s.maxSize * ARRAY_SIZES[i]);
// }
// }
//
// if (totalInitial != 0L || totalCacheBytes != 0L
// || resize != 0 || oversize != 0)
// {
// logInfo(name + ": resize: " + resize
// + " - oversize: " + oversize
// + " - initial: " + getTotalInitialBytes()
// + " bytes (" + totalInitial + " elements)"
// + " - cache: " + totalCacheBytes + " bytes"
// );
// }
//
// if (totalCacheBytes != 0L) {
// logInfo(name + ": usage stats:");
//
// for (int i = 0; i < BUCKETS; i++) {
// final BucketStats s = bucketStats[i];
//
// if (s.getOp != 0) {
// logInfo(" Bucket[" + ARRAY_SIZES[i] + "]: "
// + "get: " + s.getOp
// + " - put: " + s.returnOp
// + " - create: " + s.createOp
// + " :: max size: " + s.maxSize
// );
// }
// }
// }
// }
// return totalCacheBytes;
// }
//
// private int getByteFactor() {
// int factor = 1;
// if (name.contains("Int") || name.contains("Float")) {
// factor = 4;
// } else if (name.contains("Double")) {
// factor = 8;
// }
// return factor;
// }
//
// long getTotalInitialBytes() {
// return getByteFactor() * totalInitial;
// }
// }
// Path: src/main/java/com/sun/marlin/IntArrayCache.java
import java.lang.ref.WeakReference;
import java.util.Arrays;
import com.sun.marlin.ArrayCacheConst.BucketStats;
import com.sun.marlin.ArrayCacheConst.CacheStats;
import static com.sun.marlin.ArrayCacheConst.ARRAY_SIZES;
import static com.sun.marlin.ArrayCacheConst.BUCKETS;
import static com.sun.marlin.ArrayCacheConst.MAX_ARRAY_SIZE;
import static com.sun.marlin.MarlinUtils.logInfo;
import static com.sun.marlin.MarlinUtils.logException;
}
Reference createRef(final int initialSize) {
return new Reference(this, initialSize);
}
static final class Reference {
// initial array reference (direct access)
final int[] initial;
private final boolean clean;
private final IntArrayCache cache;
Reference(final IntArrayCache cache, final int initialSize) {
this.cache = cache;
this.clean = cache.clean;
this.initial = createArray(initialSize);
if (DO_STATS) {
cache.stats.totalInitial += initialSize;
}
}
int[] getArray(final int length) {
if (length <= MAX_ARRAY_SIZE) {
return cache.getCacheBucket(length).getArray();
}
if (DO_STATS) {
cache.stats.oversize++;
}
if (DO_LOG_OVERSIZE) { | logInfo(getLogPrefix(clean) + "IntArrayCache: " |
bourgesl/marlin-fx | src/main/java/com/sun/marlin/IntArrayCache.java | // Path: src/main/java/com/sun/marlin/ArrayCacheConst.java
// static final int[] ARRAY_SIZES = new int[BUCKETS];
//
// Path: src/main/java/com/sun/marlin/ArrayCacheConst.java
// static final int BUCKETS = 8;
//
// Path: src/main/java/com/sun/marlin/ArrayCacheConst.java
// static final int MAX_ARRAY_SIZE;
//
// Path: src/main/java/com/sun/marlin/MarlinUtils.java
// public static void logInfo(final String msg) {
// if (MarlinConst.USE_LOGGER) {
// LOG.info(msg);
// } else if (MarlinConst.ENABLE_LOGS) {
// System.out.print("INFO: ");
// System.out.println(msg);
// }
// }
//
// Path: src/main/java/com/sun/marlin/MarlinUtils.java
// public static void logException(final String msg, final Throwable th) {
// if (MarlinConst.USE_LOGGER) {
// LOG.log(java.util.logging.Level.WARNING, msg, th);
// } else if (MarlinConst.ENABLE_LOGS) {
// System.out.print("WARNING: ");
// System.out.println(msg);
// th.printStackTrace(System.err);
// }
// }
//
// Path: src/main/java/com/sun/marlin/ArrayCacheConst.java
// static final class BucketStats {
// int getOp = 0;
// int createOp = 0;
// int returnOp = 0;
// int maxSize = 0;
//
// void reset() {
// getOp = 0;
// createOp = 0;
// returnOp = 0;
// maxSize = 0;
// }
//
// void updateMaxSize(final int size) {
// if (size > maxSize) {
// maxSize = size;
// }
// }
// }
//
// Path: src/main/java/com/sun/marlin/ArrayCacheConst.java
// static final class CacheStats {
// final String name;
// final BucketStats[] bucketStats;
// int resize = 0;
// int oversize = 0;
// long totalInitial = 0L;
//
// CacheStats(final String name) {
// this.name = name;
//
// bucketStats = new BucketStats[BUCKETS];
// for (int i = 0; i < BUCKETS; i++) {
// bucketStats[i] = new BucketStats();
// }
// }
//
// void reset() {
// resize = 0;
// oversize = 0;
//
// for (int i = 0; i < BUCKETS; i++) {
// bucketStats[i].reset();
// }
// }
//
// long dumpStats() {
// long totalCacheBytes = 0L;
//
// if (DO_STATS) {
// for (int i = 0; i < BUCKETS; i++) {
// final BucketStats s = bucketStats[i];
//
// if (s.maxSize != 0) {
// totalCacheBytes += getByteFactor()
// * (s.maxSize * ARRAY_SIZES[i]);
// }
// }
//
// if (totalInitial != 0L || totalCacheBytes != 0L
// || resize != 0 || oversize != 0)
// {
// logInfo(name + ": resize: " + resize
// + " - oversize: " + oversize
// + " - initial: " + getTotalInitialBytes()
// + " bytes (" + totalInitial + " elements)"
// + " - cache: " + totalCacheBytes + " bytes"
// );
// }
//
// if (totalCacheBytes != 0L) {
// logInfo(name + ": usage stats:");
//
// for (int i = 0; i < BUCKETS; i++) {
// final BucketStats s = bucketStats[i];
//
// if (s.getOp != 0) {
// logInfo(" Bucket[" + ARRAY_SIZES[i] + "]: "
// + "get: " + s.getOp
// + " - put: " + s.returnOp
// + " - create: " + s.createOp
// + " :: max size: " + s.maxSize
// );
// }
// }
// }
// }
// return totalCacheBytes;
// }
//
// private int getByteFactor() {
// int factor = 1;
// if (name.contains("Int") || name.contains("Float")) {
// factor = 4;
// } else if (name.contains("Double")) {
// factor = 8;
// }
// return factor;
// }
//
// long getTotalInitialBytes() {
// return getByteFactor() * totalInitial;
// }
// }
| import java.lang.ref.WeakReference;
import java.util.Arrays;
import com.sun.marlin.ArrayCacheConst.BucketStats;
import com.sun.marlin.ArrayCacheConst.CacheStats;
import static com.sun.marlin.ArrayCacheConst.ARRAY_SIZES;
import static com.sun.marlin.ArrayCacheConst.BUCKETS;
import static com.sun.marlin.ArrayCacheConst.MAX_ARRAY_SIZE;
import static com.sun.marlin.MarlinUtils.logInfo;
import static com.sun.marlin.MarlinUtils.logException; |
int[] putArray(final int[] array)
{
// dirty array helper:
return putArray(array, 0, array.length);
}
int[] putArray(final int[] array, final int fromIndex,
final int toIndex)
{
if (array.length <= MAX_ARRAY_SIZE) {
if ((clean || DO_CLEAN_DIRTY) && (toIndex != 0)) {
// clean-up array of dirty part[fromIndex; toIndex[
fill(array, fromIndex, toIndex, 0);
}
// ensure to never store initial arrays in cache:
if (array != initial) {
cache.getCacheBucket(array.length).putArray(array);
}
}
return initial;
}
}
static final class Bucket {
private int tail = 0;
private final int arraySize;
private final boolean clean;
private final int[][] arrays; | // Path: src/main/java/com/sun/marlin/ArrayCacheConst.java
// static final int[] ARRAY_SIZES = new int[BUCKETS];
//
// Path: src/main/java/com/sun/marlin/ArrayCacheConst.java
// static final int BUCKETS = 8;
//
// Path: src/main/java/com/sun/marlin/ArrayCacheConst.java
// static final int MAX_ARRAY_SIZE;
//
// Path: src/main/java/com/sun/marlin/MarlinUtils.java
// public static void logInfo(final String msg) {
// if (MarlinConst.USE_LOGGER) {
// LOG.info(msg);
// } else if (MarlinConst.ENABLE_LOGS) {
// System.out.print("INFO: ");
// System.out.println(msg);
// }
// }
//
// Path: src/main/java/com/sun/marlin/MarlinUtils.java
// public static void logException(final String msg, final Throwable th) {
// if (MarlinConst.USE_LOGGER) {
// LOG.log(java.util.logging.Level.WARNING, msg, th);
// } else if (MarlinConst.ENABLE_LOGS) {
// System.out.print("WARNING: ");
// System.out.println(msg);
// th.printStackTrace(System.err);
// }
// }
//
// Path: src/main/java/com/sun/marlin/ArrayCacheConst.java
// static final class BucketStats {
// int getOp = 0;
// int createOp = 0;
// int returnOp = 0;
// int maxSize = 0;
//
// void reset() {
// getOp = 0;
// createOp = 0;
// returnOp = 0;
// maxSize = 0;
// }
//
// void updateMaxSize(final int size) {
// if (size > maxSize) {
// maxSize = size;
// }
// }
// }
//
// Path: src/main/java/com/sun/marlin/ArrayCacheConst.java
// static final class CacheStats {
// final String name;
// final BucketStats[] bucketStats;
// int resize = 0;
// int oversize = 0;
// long totalInitial = 0L;
//
// CacheStats(final String name) {
// this.name = name;
//
// bucketStats = new BucketStats[BUCKETS];
// for (int i = 0; i < BUCKETS; i++) {
// bucketStats[i] = new BucketStats();
// }
// }
//
// void reset() {
// resize = 0;
// oversize = 0;
//
// for (int i = 0; i < BUCKETS; i++) {
// bucketStats[i].reset();
// }
// }
//
// long dumpStats() {
// long totalCacheBytes = 0L;
//
// if (DO_STATS) {
// for (int i = 0; i < BUCKETS; i++) {
// final BucketStats s = bucketStats[i];
//
// if (s.maxSize != 0) {
// totalCacheBytes += getByteFactor()
// * (s.maxSize * ARRAY_SIZES[i]);
// }
// }
//
// if (totalInitial != 0L || totalCacheBytes != 0L
// || resize != 0 || oversize != 0)
// {
// logInfo(name + ": resize: " + resize
// + " - oversize: " + oversize
// + " - initial: " + getTotalInitialBytes()
// + " bytes (" + totalInitial + " elements)"
// + " - cache: " + totalCacheBytes + " bytes"
// );
// }
//
// if (totalCacheBytes != 0L) {
// logInfo(name + ": usage stats:");
//
// for (int i = 0; i < BUCKETS; i++) {
// final BucketStats s = bucketStats[i];
//
// if (s.getOp != 0) {
// logInfo(" Bucket[" + ARRAY_SIZES[i] + "]: "
// + "get: " + s.getOp
// + " - put: " + s.returnOp
// + " - create: " + s.createOp
// + " :: max size: " + s.maxSize
// );
// }
// }
// }
// }
// return totalCacheBytes;
// }
//
// private int getByteFactor() {
// int factor = 1;
// if (name.contains("Int") || name.contains("Float")) {
// factor = 4;
// } else if (name.contains("Double")) {
// factor = 8;
// }
// return factor;
// }
//
// long getTotalInitialBytes() {
// return getByteFactor() * totalInitial;
// }
// }
// Path: src/main/java/com/sun/marlin/IntArrayCache.java
import java.lang.ref.WeakReference;
import java.util.Arrays;
import com.sun.marlin.ArrayCacheConst.BucketStats;
import com.sun.marlin.ArrayCacheConst.CacheStats;
import static com.sun.marlin.ArrayCacheConst.ARRAY_SIZES;
import static com.sun.marlin.ArrayCacheConst.BUCKETS;
import static com.sun.marlin.ArrayCacheConst.MAX_ARRAY_SIZE;
import static com.sun.marlin.MarlinUtils.logInfo;
import static com.sun.marlin.MarlinUtils.logException;
int[] putArray(final int[] array)
{
// dirty array helper:
return putArray(array, 0, array.length);
}
int[] putArray(final int[] array, final int fromIndex,
final int toIndex)
{
if (array.length <= MAX_ARRAY_SIZE) {
if ((clean || DO_CLEAN_DIRTY) && (toIndex != 0)) {
// clean-up array of dirty part[fromIndex; toIndex[
fill(array, fromIndex, toIndex, 0);
}
// ensure to never store initial arrays in cache:
if (array != initial) {
cache.getCacheBucket(array.length).putArray(array);
}
}
return initial;
}
}
static final class Bucket {
private int tail = 0;
private final int arraySize;
private final boolean clean;
private final int[][] arrays; | private final BucketStats stats; |
bourgesl/marlin-fx | src/main/java/com/sun/marlin/IntArrayCache.java | // Path: src/main/java/com/sun/marlin/ArrayCacheConst.java
// static final int[] ARRAY_SIZES = new int[BUCKETS];
//
// Path: src/main/java/com/sun/marlin/ArrayCacheConst.java
// static final int BUCKETS = 8;
//
// Path: src/main/java/com/sun/marlin/ArrayCacheConst.java
// static final int MAX_ARRAY_SIZE;
//
// Path: src/main/java/com/sun/marlin/MarlinUtils.java
// public static void logInfo(final String msg) {
// if (MarlinConst.USE_LOGGER) {
// LOG.info(msg);
// } else if (MarlinConst.ENABLE_LOGS) {
// System.out.print("INFO: ");
// System.out.println(msg);
// }
// }
//
// Path: src/main/java/com/sun/marlin/MarlinUtils.java
// public static void logException(final String msg, final Throwable th) {
// if (MarlinConst.USE_LOGGER) {
// LOG.log(java.util.logging.Level.WARNING, msg, th);
// } else if (MarlinConst.ENABLE_LOGS) {
// System.out.print("WARNING: ");
// System.out.println(msg);
// th.printStackTrace(System.err);
// }
// }
//
// Path: src/main/java/com/sun/marlin/ArrayCacheConst.java
// static final class BucketStats {
// int getOp = 0;
// int createOp = 0;
// int returnOp = 0;
// int maxSize = 0;
//
// void reset() {
// getOp = 0;
// createOp = 0;
// returnOp = 0;
// maxSize = 0;
// }
//
// void updateMaxSize(final int size) {
// if (size > maxSize) {
// maxSize = size;
// }
// }
// }
//
// Path: src/main/java/com/sun/marlin/ArrayCacheConst.java
// static final class CacheStats {
// final String name;
// final BucketStats[] bucketStats;
// int resize = 0;
// int oversize = 0;
// long totalInitial = 0L;
//
// CacheStats(final String name) {
// this.name = name;
//
// bucketStats = new BucketStats[BUCKETS];
// for (int i = 0; i < BUCKETS; i++) {
// bucketStats[i] = new BucketStats();
// }
// }
//
// void reset() {
// resize = 0;
// oversize = 0;
//
// for (int i = 0; i < BUCKETS; i++) {
// bucketStats[i].reset();
// }
// }
//
// long dumpStats() {
// long totalCacheBytes = 0L;
//
// if (DO_STATS) {
// for (int i = 0; i < BUCKETS; i++) {
// final BucketStats s = bucketStats[i];
//
// if (s.maxSize != 0) {
// totalCacheBytes += getByteFactor()
// * (s.maxSize * ARRAY_SIZES[i]);
// }
// }
//
// if (totalInitial != 0L || totalCacheBytes != 0L
// || resize != 0 || oversize != 0)
// {
// logInfo(name + ": resize: " + resize
// + " - oversize: " + oversize
// + " - initial: " + getTotalInitialBytes()
// + " bytes (" + totalInitial + " elements)"
// + " - cache: " + totalCacheBytes + " bytes"
// );
// }
//
// if (totalCacheBytes != 0L) {
// logInfo(name + ": usage stats:");
//
// for (int i = 0; i < BUCKETS; i++) {
// final BucketStats s = bucketStats[i];
//
// if (s.getOp != 0) {
// logInfo(" Bucket[" + ARRAY_SIZES[i] + "]: "
// + "get: " + s.getOp
// + " - put: " + s.returnOp
// + " - create: " + s.createOp
// + " :: max size: " + s.maxSize
// );
// }
// }
// }
// }
// return totalCacheBytes;
// }
//
// private int getByteFactor() {
// int factor = 1;
// if (name.contains("Int") || name.contains("Float")) {
// factor = 4;
// } else if (name.contains("Double")) {
// factor = 8;
// }
// return factor;
// }
//
// long getTotalInitialBytes() {
// return getByteFactor() * totalInitial;
// }
// }
| import java.lang.ref.WeakReference;
import java.util.Arrays;
import com.sun.marlin.ArrayCacheConst.BucketStats;
import com.sun.marlin.ArrayCacheConst.CacheStats;
import static com.sun.marlin.ArrayCacheConst.ARRAY_SIZES;
import static com.sun.marlin.ArrayCacheConst.BUCKETS;
import static com.sun.marlin.ArrayCacheConst.MAX_ARRAY_SIZE;
import static com.sun.marlin.MarlinUtils.logInfo;
import static com.sun.marlin.MarlinUtils.logException; | stats.updateMaxSize(tail);
}
} else if (DO_CHECKS) {
logInfo(getLogPrefix(clean) + "IntArrayCache: "
+ "array capacity exceeded !");
}
}
}
static int[] createArray(final int length) {
return new int[length];
}
static void fill(final int[] array, final int fromIndex,
final int toIndex, final int value)
{
// clear array data:
Arrays.fill(array, fromIndex, toIndex, value);
if (DO_CHECKS) {
check(array, fromIndex, toIndex, value);
}
}
public static void check(final int[] array, final int fromIndex,
final int toIndex, final int value)
{
if (DO_CHECKS) {
// check zero on full array:
for (int i = 0; i < array.length; i++) {
if (array[i] != value) { | // Path: src/main/java/com/sun/marlin/ArrayCacheConst.java
// static final int[] ARRAY_SIZES = new int[BUCKETS];
//
// Path: src/main/java/com/sun/marlin/ArrayCacheConst.java
// static final int BUCKETS = 8;
//
// Path: src/main/java/com/sun/marlin/ArrayCacheConst.java
// static final int MAX_ARRAY_SIZE;
//
// Path: src/main/java/com/sun/marlin/MarlinUtils.java
// public static void logInfo(final String msg) {
// if (MarlinConst.USE_LOGGER) {
// LOG.info(msg);
// } else if (MarlinConst.ENABLE_LOGS) {
// System.out.print("INFO: ");
// System.out.println(msg);
// }
// }
//
// Path: src/main/java/com/sun/marlin/MarlinUtils.java
// public static void logException(final String msg, final Throwable th) {
// if (MarlinConst.USE_LOGGER) {
// LOG.log(java.util.logging.Level.WARNING, msg, th);
// } else if (MarlinConst.ENABLE_LOGS) {
// System.out.print("WARNING: ");
// System.out.println(msg);
// th.printStackTrace(System.err);
// }
// }
//
// Path: src/main/java/com/sun/marlin/ArrayCacheConst.java
// static final class BucketStats {
// int getOp = 0;
// int createOp = 0;
// int returnOp = 0;
// int maxSize = 0;
//
// void reset() {
// getOp = 0;
// createOp = 0;
// returnOp = 0;
// maxSize = 0;
// }
//
// void updateMaxSize(final int size) {
// if (size > maxSize) {
// maxSize = size;
// }
// }
// }
//
// Path: src/main/java/com/sun/marlin/ArrayCacheConst.java
// static final class CacheStats {
// final String name;
// final BucketStats[] bucketStats;
// int resize = 0;
// int oversize = 0;
// long totalInitial = 0L;
//
// CacheStats(final String name) {
// this.name = name;
//
// bucketStats = new BucketStats[BUCKETS];
// for (int i = 0; i < BUCKETS; i++) {
// bucketStats[i] = new BucketStats();
// }
// }
//
// void reset() {
// resize = 0;
// oversize = 0;
//
// for (int i = 0; i < BUCKETS; i++) {
// bucketStats[i].reset();
// }
// }
//
// long dumpStats() {
// long totalCacheBytes = 0L;
//
// if (DO_STATS) {
// for (int i = 0; i < BUCKETS; i++) {
// final BucketStats s = bucketStats[i];
//
// if (s.maxSize != 0) {
// totalCacheBytes += getByteFactor()
// * (s.maxSize * ARRAY_SIZES[i]);
// }
// }
//
// if (totalInitial != 0L || totalCacheBytes != 0L
// || resize != 0 || oversize != 0)
// {
// logInfo(name + ": resize: " + resize
// + " - oversize: " + oversize
// + " - initial: " + getTotalInitialBytes()
// + " bytes (" + totalInitial + " elements)"
// + " - cache: " + totalCacheBytes + " bytes"
// );
// }
//
// if (totalCacheBytes != 0L) {
// logInfo(name + ": usage stats:");
//
// for (int i = 0; i < BUCKETS; i++) {
// final BucketStats s = bucketStats[i];
//
// if (s.getOp != 0) {
// logInfo(" Bucket[" + ARRAY_SIZES[i] + "]: "
// + "get: " + s.getOp
// + " - put: " + s.returnOp
// + " - create: " + s.createOp
// + " :: max size: " + s.maxSize
// );
// }
// }
// }
// }
// return totalCacheBytes;
// }
//
// private int getByteFactor() {
// int factor = 1;
// if (name.contains("Int") || name.contains("Float")) {
// factor = 4;
// } else if (name.contains("Double")) {
// factor = 8;
// }
// return factor;
// }
//
// long getTotalInitialBytes() {
// return getByteFactor() * totalInitial;
// }
// }
// Path: src/main/java/com/sun/marlin/IntArrayCache.java
import java.lang.ref.WeakReference;
import java.util.Arrays;
import com.sun.marlin.ArrayCacheConst.BucketStats;
import com.sun.marlin.ArrayCacheConst.CacheStats;
import static com.sun.marlin.ArrayCacheConst.ARRAY_SIZES;
import static com.sun.marlin.ArrayCacheConst.BUCKETS;
import static com.sun.marlin.ArrayCacheConst.MAX_ARRAY_SIZE;
import static com.sun.marlin.MarlinUtils.logInfo;
import static com.sun.marlin.MarlinUtils.logException;
stats.updateMaxSize(tail);
}
} else if (DO_CHECKS) {
logInfo(getLogPrefix(clean) + "IntArrayCache: "
+ "array capacity exceeded !");
}
}
}
static int[] createArray(final int length) {
return new int[length];
}
static void fill(final int[] array, final int fromIndex,
final int toIndex, final int value)
{
// clear array data:
Arrays.fill(array, fromIndex, toIndex, value);
if (DO_CHECKS) {
check(array, fromIndex, toIndex, value);
}
}
public static void check(final int[] array, final int fromIndex,
final int toIndex, final int value)
{
if (DO_CHECKS) {
// check zero on full array:
for (int i = 0; i < array.length; i++) {
if (array[i] != value) { | logException("Invalid value at: " + i + " = " + array[i] |
bourgesl/marlin-fx | src/main/java/com/sun/marlin/ArrayCacheConst.java | // Path: src/main/java/com/sun/marlin/MarlinUtils.java
// public static void logInfo(final String msg) {
// if (MarlinConst.USE_LOGGER) {
// LOG.info(msg);
// } else if (MarlinConst.ENABLE_LOGS) {
// System.out.print("INFO: ");
// System.out.println(msg);
// }
// }
| import java.util.Arrays;
import static com.sun.marlin.MarlinUtils.logInfo; | /*
* Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code 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 General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.marlin;
public final class ArrayCacheConst implements MarlinConst {
static final int BUCKETS = 8;
static final int MIN_ARRAY_SIZE = 4096;
// maximum array size
static final int MAX_ARRAY_SIZE;
// threshold below to grow arrays by 4
static final int THRESHOLD_SMALL_ARRAY_SIZE = 4 * 1024 * 1024;
// threshold to grow arrays only by (3/2) instead of 2
static final int THRESHOLD_ARRAY_SIZE;
// threshold to grow arrays only by (5/4) instead of (3/2)
static final long THRESHOLD_HUGE_ARRAY_SIZE;
static final int[] ARRAY_SIZES = new int[BUCKETS];
static {
// initialize buckets for int/float arrays
int arraySize = MIN_ARRAY_SIZE;
int inc_lg = 2; // x4
for (int i = 0; i < BUCKETS; i++, arraySize <<= inc_lg) {
ARRAY_SIZES[i] = arraySize;
if (DO_TRACE) { | // Path: src/main/java/com/sun/marlin/MarlinUtils.java
// public static void logInfo(final String msg) {
// if (MarlinConst.USE_LOGGER) {
// LOG.info(msg);
// } else if (MarlinConst.ENABLE_LOGS) {
// System.out.print("INFO: ");
// System.out.println(msg);
// }
// }
// Path: src/main/java/com/sun/marlin/ArrayCacheConst.java
import java.util.Arrays;
import static com.sun.marlin.MarlinUtils.logInfo;
/*
* Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code 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 General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.marlin;
public final class ArrayCacheConst implements MarlinConst {
static final int BUCKETS = 8;
static final int MIN_ARRAY_SIZE = 4096;
// maximum array size
static final int MAX_ARRAY_SIZE;
// threshold below to grow arrays by 4
static final int THRESHOLD_SMALL_ARRAY_SIZE = 4 * 1024 * 1024;
// threshold to grow arrays only by (3/2) instead of 2
static final int THRESHOLD_ARRAY_SIZE;
// threshold to grow arrays only by (5/4) instead of (3/2)
static final long THRESHOLD_HUGE_ARRAY_SIZE;
static final int[] ARRAY_SIZES = new int[BUCKETS];
static {
// initialize buckets for int/float arrays
int arraySize = MIN_ARRAY_SIZE;
int inc_lg = 2; // x4
for (int i = 0; i < BUCKETS; i++, arraySize <<= inc_lg) {
ARRAY_SIZES[i] = arraySize;
if (DO_TRACE) { | logInfo("arraySize[" + i + "]: " + arraySize); |
bourgesl/marlin-fx | src/main/java/com/sun/marlin/MarlinProperties.java | // Path: src/main/java/com/sun/marlin/MarlinUtils.java
// public static void logInfo(final String msg) {
// if (MarlinConst.USE_LOGGER) {
// LOG.info(msg);
// } else if (MarlinConst.ENABLE_LOGS) {
// System.out.print("INFO: ");
// System.out.println(msg);
// }
// }
| import java.security.AccessController;
import static com.sun.marlin.MarlinUtils.logInfo;
import java.security.PrivilegedAction; | getInteger("prism.marlin.pixelWidth", 4096, 64, 32 * 1024),
64);
}
/**
* Return the initial pixel height used to define initial arrays
* (buckets)
*
* @return 64 < initial pixel size < 32768 (2176 by default)
*/
public static int getInitialPixelHeight() {
return align(
getInteger("prism.marlin.pixelHeight", 2176, 64, 32 * 1024),
64);
}
/**
* Return true if the profile is 'quality' (default) over 'speed'
*
* @return true if the profile is 'quality' (default), false otherwise
*/
public static boolean isProfileQuality() {
final String key = "prism.marlin.profile";
final String profile = getString(key, "quality");
if ("quality".equals(profile)) {
return true;
}
if ("speed".equals(profile)) {
return false;
} | // Path: src/main/java/com/sun/marlin/MarlinUtils.java
// public static void logInfo(final String msg) {
// if (MarlinConst.USE_LOGGER) {
// LOG.info(msg);
// } else if (MarlinConst.ENABLE_LOGS) {
// System.out.print("INFO: ");
// System.out.println(msg);
// }
// }
// Path: src/main/java/com/sun/marlin/MarlinProperties.java
import java.security.AccessController;
import static com.sun.marlin.MarlinUtils.logInfo;
import java.security.PrivilegedAction;
getInteger("prism.marlin.pixelWidth", 4096, 64, 32 * 1024),
64);
}
/**
* Return the initial pixel height used to define initial arrays
* (buckets)
*
* @return 64 < initial pixel size < 32768 (2176 by default)
*/
public static int getInitialPixelHeight() {
return align(
getInteger("prism.marlin.pixelHeight", 2176, 64, 32 * 1024),
64);
}
/**
* Return true if the profile is 'quality' (default) over 'speed'
*
* @return true if the profile is 'quality' (default), false otherwise
*/
public static boolean isProfileQuality() {
final String key = "prism.marlin.profile";
final String profile = getString(key, "quality");
if ("quality".equals(profile)) {
return true;
}
if ("speed".equals(profile)) {
return false;
} | logInfo("Invalid value for " + key + " = " + profile |
bourgesl/marlin-fx | src/test/java/test/com/sun/marlin/ClipShapeTest.java | // Path: src/test/java/test/util/Util.java
// public static final int TIMEOUT = 5000;
| import java.awt.BasicStroke;
import java.awt.Shape;
import java.awt.geom.CubicCurve2D;
import java.awt.geom.Path2D;
import java.awt.geom.PathIterator;
import java.awt.geom.QuadCurve2D;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Arrays;
import java.util.Iterator;
import java.util.Locale;
import java.util.Random;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.logging.Handler;
import java.util.logging.LogRecord;
import java.util.logging.Logger;
import javafx.application.Application;
import javafx.application.Platform;
import javafx.collections.ObservableList;
import javafx.embed.swing.SwingFXUtils;
import javafx.geometry.Rectangle2D;
import javafx.scene.Scene;
import javafx.scene.SnapshotParameters;
import javafx.scene.image.PixelReader;
import javafx.scene.image.PixelWriter;
import javafx.scene.image.WritableImage;
import javafx.scene.layout.BorderPane;
import javafx.scene.paint.Color;
import javafx.scene.shape.ClosePath;
import javafx.scene.shape.CubicCurveTo;
import javafx.scene.shape.FillRule;
import javafx.scene.shape.LineTo;
import javafx.scene.shape.MoveTo;
import javafx.scene.shape.Path;
import javafx.scene.shape.PathElement;
import javafx.scene.shape.QuadCurveTo;
import javafx.scene.shape.StrokeLineCap;
import javafx.scene.shape.StrokeLineJoin;
import javafx.scene.text.Text;
import javafx.stage.Stage;
import javax.imageio.IIOImage;
import javax.imageio.ImageIO;
import javax.imageio.ImageWriteParam;
import javax.imageio.ImageWriter;
import javax.imageio.stream.ImageOutputStream;
import junit.framework.AssertionFailedError;
import org.junit.AfterClass;
import org.junit.Assert;
import static org.junit.Assert.assertEquals;
import org.junit.BeforeClass;
import org.junit.Test;
import static test.util.Util.TIMEOUT; | if (TRACE_SUBDIVIDE_CURVE) {
len += curvelen(src[i + 0], src[i + 1], src[i + 2], src[i + 3], src[i + 4], src[i + 5], src[i + 6], src[i + 7]);
}
p2d.curveTo(src[i + 2], src[i + 3], src[i + 4], src[i + 5], src[i + 6], src[i + 7]);
} else {
if (TRACE_SUBDIVIDE_CURVE) {
len += quadlen(src[i + 0], src[i + 1], src[i + 2], src[i + 3], src[i + 4], src[i + 5]);
}
p2d.quadTo(src[i + 2], src[i + 3], src[i + 4], src[i + 5]);
}
}
if (TRACE_SUBDIVIDE_CURVE) {
System.out.println("curveLen (final) = " + len);
}
} else {
if (type == 8) {
p2d.curveTo(in[2], in[3], in[4], in[5], in[6], in[7]);
} else {
p2d.quadTo(in[2], in[3], in[4], in[5]);
}
}
}
@BeforeClass
public static void setupOnce() {
// Start the Application
new Thread(() -> Application.launch(MyApp.class, (String[]) null)).start();
try { | // Path: src/test/java/test/util/Util.java
// public static final int TIMEOUT = 5000;
// Path: src/test/java/test/com/sun/marlin/ClipShapeTest.java
import java.awt.BasicStroke;
import java.awt.Shape;
import java.awt.geom.CubicCurve2D;
import java.awt.geom.Path2D;
import java.awt.geom.PathIterator;
import java.awt.geom.QuadCurve2D;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Arrays;
import java.util.Iterator;
import java.util.Locale;
import java.util.Random;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.logging.Handler;
import java.util.logging.LogRecord;
import java.util.logging.Logger;
import javafx.application.Application;
import javafx.application.Platform;
import javafx.collections.ObservableList;
import javafx.embed.swing.SwingFXUtils;
import javafx.geometry.Rectangle2D;
import javafx.scene.Scene;
import javafx.scene.SnapshotParameters;
import javafx.scene.image.PixelReader;
import javafx.scene.image.PixelWriter;
import javafx.scene.image.WritableImage;
import javafx.scene.layout.BorderPane;
import javafx.scene.paint.Color;
import javafx.scene.shape.ClosePath;
import javafx.scene.shape.CubicCurveTo;
import javafx.scene.shape.FillRule;
import javafx.scene.shape.LineTo;
import javafx.scene.shape.MoveTo;
import javafx.scene.shape.Path;
import javafx.scene.shape.PathElement;
import javafx.scene.shape.QuadCurveTo;
import javafx.scene.shape.StrokeLineCap;
import javafx.scene.shape.StrokeLineJoin;
import javafx.scene.text.Text;
import javafx.stage.Stage;
import javax.imageio.IIOImage;
import javax.imageio.ImageIO;
import javax.imageio.ImageWriteParam;
import javax.imageio.ImageWriter;
import javax.imageio.stream.ImageOutputStream;
import junit.framework.AssertionFailedError;
import org.junit.AfterClass;
import org.junit.Assert;
import static org.junit.Assert.assertEquals;
import org.junit.BeforeClass;
import org.junit.Test;
import static test.util.Util.TIMEOUT;
if (TRACE_SUBDIVIDE_CURVE) {
len += curvelen(src[i + 0], src[i + 1], src[i + 2], src[i + 3], src[i + 4], src[i + 5], src[i + 6], src[i + 7]);
}
p2d.curveTo(src[i + 2], src[i + 3], src[i + 4], src[i + 5], src[i + 6], src[i + 7]);
} else {
if (TRACE_SUBDIVIDE_CURVE) {
len += quadlen(src[i + 0], src[i + 1], src[i + 2], src[i + 3], src[i + 4], src[i + 5]);
}
p2d.quadTo(src[i + 2], src[i + 3], src[i + 4], src[i + 5]);
}
}
if (TRACE_SUBDIVIDE_CURVE) {
System.out.println("curveLen (final) = " + len);
}
} else {
if (type == 8) {
p2d.curveTo(in[2], in[3], in[4], in[5], in[6], in[7]);
} else {
p2d.quadTo(in[2], in[3], in[4], in[5]);
}
}
}
@BeforeClass
public static void setupOnce() {
// Start the Application
new Thread(() -> Application.launch(MyApp.class, (String[]) null)).start();
try { | if (!launchLatch.await(TIMEOUT, TimeUnit.MILLISECONDS)) { |
bourgesl/marlin-fx | src/main/java/com/sun/marlin/DHelpers.java | // Path: src/main/java/com/sun/marlin/stats/Histogram.java
// public final class Histogram extends StatLong {
//
// static final int BUCKET = 2;
// static final int MAX = 20;
// static final int LAST = MAX - 1;
// static final int[] STEPS = new int[MAX];
//
// static {
// STEPS[0] = 0;
// STEPS[1] = 1;
//
// for (int i = 2; i < MAX; i++) {
// STEPS[i] = STEPS[i - 1] * BUCKET;
// }
// }
//
// static int bucket(int val) {
// for (int i = 1; i < MAX; i++) {
// if (val < STEPS[i]) {
// return i - 1;
// }
// }
// return LAST;
// }
//
// private final StatLong[] stats = new StatLong[MAX];
//
// public Histogram(final String name) {
// super(name);
// for (int i = 0; i < MAX; i++) {
// stats[i] = new StatLong(String.format("%5s .. %5s", STEPS[i],
// ((i + 1 < MAX) ? STEPS[i + 1] : "~")));
// }
// }
//
// @Override
// public void reset() {
// super.reset();
// for (int i = 0; i < MAX; i++) {
// stats[i].reset();
// }
// }
//
// @Override
// public void add(int val) {
// super.add(val);
// stats[bucket(val)].add(val);
// }
//
// @Override
// public void add(long val) {
// add((int) val);
// }
//
// @Override
// public String toString() {
// final StringBuilder sb = new StringBuilder(2048);
// super.toString(sb).append(" { ");
//
// for (int i = 0; i < MAX; i++) {
// if (stats[i].count != 0l) {
// sb.append("\n ").append(stats[i].toString());
// }
// }
//
// return sb.append(" }").toString();
// }
// }
//
// Path: src/main/java/com/sun/marlin/stats/StatLong.java
// public class StatLong {
//
// public final String name;
// public long count = 0l;
// public long sum = 0l;
// public long min = Integer.MAX_VALUE;
// public long max = Integer.MIN_VALUE;
//
// public StatLong(final String name) {
// this.name = name;
// }
//
// public void reset() {
// count = 0l;
// sum = 0l;
// min = Integer.MAX_VALUE;
// max = Integer.MIN_VALUE;
// }
//
// public void add(final int val) {
// count++;
// sum += val;
// if (val < min) {
// min = val;
// }
// if (val > max) {
// max = val;
// }
// }
//
// public void add(final long val) {
// count++;
// sum += val;
// if (val < min) {
// min = val;
// }
// if (val > max) {
// max = val;
// }
// }
//
// @Override
// public String toString() {
// return toString(new StringBuilder(128)).toString();
// }
//
// public final StringBuilder toString(final StringBuilder sb) {
// sb.append(name).append('[').append(count);
// sb.append("] sum: ").append(sum).append(" avg: ");
// sb.append(trimTo3Digits(((double) sum) / count));
// sb.append(" [").append(min).append(" | ").append(max).append("]");
// return sb;
// }
//
// /**
// * Adjust the given double value to keep only 3 decimal digits
// *
// * @param value value to adjust
// * @return double value with only 3 decimal digits
// */
// public static double trimTo3Digits(final double value) {
// return ((long) (1e3d * value)) / 1e3d;
// }
// }
| import java.util.Arrays;
import com.sun.marlin.stats.Histogram;
import com.sun.marlin.stats.StatLong; | return code;
}
// a stack of polynomial curves where each curve shares endpoints with
// adjacent ones.
static final class PolyStack {
private static final byte TYPE_LINETO = (byte) 0;
private static final byte TYPE_QUADTO = (byte) 1;
private static final byte TYPE_CUBICTO = (byte) 2;
// curves capacity = edges count (8192) = edges x 2 (coords)
private static final int INITIAL_CURVES_COUNT = INITIAL_EDGES_COUNT << 1;
// types capacity = edges count (4096)
private static final int INITIAL_TYPES_COUNT = INITIAL_EDGES_COUNT;
double[] curves;
int end;
byte[] curveTypes;
int numCurves;
// curves ref (dirty)
final DoubleArrayCache.Reference curves_ref;
// curveTypes ref (dirty)
final ByteArrayCache.Reference curveTypes_ref;
// used marks (stats only)
int curveTypesUseMark;
int curvesUseMark;
| // Path: src/main/java/com/sun/marlin/stats/Histogram.java
// public final class Histogram extends StatLong {
//
// static final int BUCKET = 2;
// static final int MAX = 20;
// static final int LAST = MAX - 1;
// static final int[] STEPS = new int[MAX];
//
// static {
// STEPS[0] = 0;
// STEPS[1] = 1;
//
// for (int i = 2; i < MAX; i++) {
// STEPS[i] = STEPS[i - 1] * BUCKET;
// }
// }
//
// static int bucket(int val) {
// for (int i = 1; i < MAX; i++) {
// if (val < STEPS[i]) {
// return i - 1;
// }
// }
// return LAST;
// }
//
// private final StatLong[] stats = new StatLong[MAX];
//
// public Histogram(final String name) {
// super(name);
// for (int i = 0; i < MAX; i++) {
// stats[i] = new StatLong(String.format("%5s .. %5s", STEPS[i],
// ((i + 1 < MAX) ? STEPS[i + 1] : "~")));
// }
// }
//
// @Override
// public void reset() {
// super.reset();
// for (int i = 0; i < MAX; i++) {
// stats[i].reset();
// }
// }
//
// @Override
// public void add(int val) {
// super.add(val);
// stats[bucket(val)].add(val);
// }
//
// @Override
// public void add(long val) {
// add((int) val);
// }
//
// @Override
// public String toString() {
// final StringBuilder sb = new StringBuilder(2048);
// super.toString(sb).append(" { ");
//
// for (int i = 0; i < MAX; i++) {
// if (stats[i].count != 0l) {
// sb.append("\n ").append(stats[i].toString());
// }
// }
//
// return sb.append(" }").toString();
// }
// }
//
// Path: src/main/java/com/sun/marlin/stats/StatLong.java
// public class StatLong {
//
// public final String name;
// public long count = 0l;
// public long sum = 0l;
// public long min = Integer.MAX_VALUE;
// public long max = Integer.MIN_VALUE;
//
// public StatLong(final String name) {
// this.name = name;
// }
//
// public void reset() {
// count = 0l;
// sum = 0l;
// min = Integer.MAX_VALUE;
// max = Integer.MIN_VALUE;
// }
//
// public void add(final int val) {
// count++;
// sum += val;
// if (val < min) {
// min = val;
// }
// if (val > max) {
// max = val;
// }
// }
//
// public void add(final long val) {
// count++;
// sum += val;
// if (val < min) {
// min = val;
// }
// if (val > max) {
// max = val;
// }
// }
//
// @Override
// public String toString() {
// return toString(new StringBuilder(128)).toString();
// }
//
// public final StringBuilder toString(final StringBuilder sb) {
// sb.append(name).append('[').append(count);
// sb.append("] sum: ").append(sum).append(" avg: ");
// sb.append(trimTo3Digits(((double) sum) / count));
// sb.append(" [").append(min).append(" | ").append(max).append("]");
// return sb;
// }
//
// /**
// * Adjust the given double value to keep only 3 decimal digits
// *
// * @param value value to adjust
// * @return double value with only 3 decimal digits
// */
// public static double trimTo3Digits(final double value) {
// return ((long) (1e3d * value)) / 1e3d;
// }
// }
// Path: src/main/java/com/sun/marlin/DHelpers.java
import java.util.Arrays;
import com.sun.marlin.stats.Histogram;
import com.sun.marlin.stats.StatLong;
return code;
}
// a stack of polynomial curves where each curve shares endpoints with
// adjacent ones.
static final class PolyStack {
private static final byte TYPE_LINETO = (byte) 0;
private static final byte TYPE_QUADTO = (byte) 1;
private static final byte TYPE_CUBICTO = (byte) 2;
// curves capacity = edges count (8192) = edges x 2 (coords)
private static final int INITIAL_CURVES_COUNT = INITIAL_EDGES_COUNT << 1;
// types capacity = edges count (4096)
private static final int INITIAL_TYPES_COUNT = INITIAL_EDGES_COUNT;
double[] curves;
int end;
byte[] curveTypes;
int numCurves;
// curves ref (dirty)
final DoubleArrayCache.Reference curves_ref;
// curveTypes ref (dirty)
final ByteArrayCache.Reference curveTypes_ref;
// used marks (stats only)
int curveTypesUseMark;
int curvesUseMark;
| private final StatLong stat_polystack_types; |
bourgesl/marlin-fx | src/main/java/com/sun/marlin/DHelpers.java | // Path: src/main/java/com/sun/marlin/stats/Histogram.java
// public final class Histogram extends StatLong {
//
// static final int BUCKET = 2;
// static final int MAX = 20;
// static final int LAST = MAX - 1;
// static final int[] STEPS = new int[MAX];
//
// static {
// STEPS[0] = 0;
// STEPS[1] = 1;
//
// for (int i = 2; i < MAX; i++) {
// STEPS[i] = STEPS[i - 1] * BUCKET;
// }
// }
//
// static int bucket(int val) {
// for (int i = 1; i < MAX; i++) {
// if (val < STEPS[i]) {
// return i - 1;
// }
// }
// return LAST;
// }
//
// private final StatLong[] stats = new StatLong[MAX];
//
// public Histogram(final String name) {
// super(name);
// for (int i = 0; i < MAX; i++) {
// stats[i] = new StatLong(String.format("%5s .. %5s", STEPS[i],
// ((i + 1 < MAX) ? STEPS[i + 1] : "~")));
// }
// }
//
// @Override
// public void reset() {
// super.reset();
// for (int i = 0; i < MAX; i++) {
// stats[i].reset();
// }
// }
//
// @Override
// public void add(int val) {
// super.add(val);
// stats[bucket(val)].add(val);
// }
//
// @Override
// public void add(long val) {
// add((int) val);
// }
//
// @Override
// public String toString() {
// final StringBuilder sb = new StringBuilder(2048);
// super.toString(sb).append(" { ");
//
// for (int i = 0; i < MAX; i++) {
// if (stats[i].count != 0l) {
// sb.append("\n ").append(stats[i].toString());
// }
// }
//
// return sb.append(" }").toString();
// }
// }
//
// Path: src/main/java/com/sun/marlin/stats/StatLong.java
// public class StatLong {
//
// public final String name;
// public long count = 0l;
// public long sum = 0l;
// public long min = Integer.MAX_VALUE;
// public long max = Integer.MIN_VALUE;
//
// public StatLong(final String name) {
// this.name = name;
// }
//
// public void reset() {
// count = 0l;
// sum = 0l;
// min = Integer.MAX_VALUE;
// max = Integer.MIN_VALUE;
// }
//
// public void add(final int val) {
// count++;
// sum += val;
// if (val < min) {
// min = val;
// }
// if (val > max) {
// max = val;
// }
// }
//
// public void add(final long val) {
// count++;
// sum += val;
// if (val < min) {
// min = val;
// }
// if (val > max) {
// max = val;
// }
// }
//
// @Override
// public String toString() {
// return toString(new StringBuilder(128)).toString();
// }
//
// public final StringBuilder toString(final StringBuilder sb) {
// sb.append(name).append('[').append(count);
// sb.append("] sum: ").append(sum).append(" avg: ");
// sb.append(trimTo3Digits(((double) sum) / count));
// sb.append(" [").append(min).append(" | ").append(max).append("]");
// return sb;
// }
//
// /**
// * Adjust the given double value to keep only 3 decimal digits
// *
// * @param value value to adjust
// * @return double value with only 3 decimal digits
// */
// public static double trimTo3Digits(final double value) {
// return ((long) (1e3d * value)) / 1e3d;
// }
// }
| import java.util.Arrays;
import com.sun.marlin.stats.Histogram;
import com.sun.marlin.stats.StatLong; |
// a stack of polynomial curves where each curve shares endpoints with
// adjacent ones.
static final class PolyStack {
private static final byte TYPE_LINETO = (byte) 0;
private static final byte TYPE_QUADTO = (byte) 1;
private static final byte TYPE_CUBICTO = (byte) 2;
// curves capacity = edges count (8192) = edges x 2 (coords)
private static final int INITIAL_CURVES_COUNT = INITIAL_EDGES_COUNT << 1;
// types capacity = edges count (4096)
private static final int INITIAL_TYPES_COUNT = INITIAL_EDGES_COUNT;
double[] curves;
int end;
byte[] curveTypes;
int numCurves;
// curves ref (dirty)
final DoubleArrayCache.Reference curves_ref;
// curveTypes ref (dirty)
final ByteArrayCache.Reference curveTypes_ref;
// used marks (stats only)
int curveTypesUseMark;
int curvesUseMark;
private final StatLong stat_polystack_types;
private final StatLong stat_polystack_curves; | // Path: src/main/java/com/sun/marlin/stats/Histogram.java
// public final class Histogram extends StatLong {
//
// static final int BUCKET = 2;
// static final int MAX = 20;
// static final int LAST = MAX - 1;
// static final int[] STEPS = new int[MAX];
//
// static {
// STEPS[0] = 0;
// STEPS[1] = 1;
//
// for (int i = 2; i < MAX; i++) {
// STEPS[i] = STEPS[i - 1] * BUCKET;
// }
// }
//
// static int bucket(int val) {
// for (int i = 1; i < MAX; i++) {
// if (val < STEPS[i]) {
// return i - 1;
// }
// }
// return LAST;
// }
//
// private final StatLong[] stats = new StatLong[MAX];
//
// public Histogram(final String name) {
// super(name);
// for (int i = 0; i < MAX; i++) {
// stats[i] = new StatLong(String.format("%5s .. %5s", STEPS[i],
// ((i + 1 < MAX) ? STEPS[i + 1] : "~")));
// }
// }
//
// @Override
// public void reset() {
// super.reset();
// for (int i = 0; i < MAX; i++) {
// stats[i].reset();
// }
// }
//
// @Override
// public void add(int val) {
// super.add(val);
// stats[bucket(val)].add(val);
// }
//
// @Override
// public void add(long val) {
// add((int) val);
// }
//
// @Override
// public String toString() {
// final StringBuilder sb = new StringBuilder(2048);
// super.toString(sb).append(" { ");
//
// for (int i = 0; i < MAX; i++) {
// if (stats[i].count != 0l) {
// sb.append("\n ").append(stats[i].toString());
// }
// }
//
// return sb.append(" }").toString();
// }
// }
//
// Path: src/main/java/com/sun/marlin/stats/StatLong.java
// public class StatLong {
//
// public final String name;
// public long count = 0l;
// public long sum = 0l;
// public long min = Integer.MAX_VALUE;
// public long max = Integer.MIN_VALUE;
//
// public StatLong(final String name) {
// this.name = name;
// }
//
// public void reset() {
// count = 0l;
// sum = 0l;
// min = Integer.MAX_VALUE;
// max = Integer.MIN_VALUE;
// }
//
// public void add(final int val) {
// count++;
// sum += val;
// if (val < min) {
// min = val;
// }
// if (val > max) {
// max = val;
// }
// }
//
// public void add(final long val) {
// count++;
// sum += val;
// if (val < min) {
// min = val;
// }
// if (val > max) {
// max = val;
// }
// }
//
// @Override
// public String toString() {
// return toString(new StringBuilder(128)).toString();
// }
//
// public final StringBuilder toString(final StringBuilder sb) {
// sb.append(name).append('[').append(count);
// sb.append("] sum: ").append(sum).append(" avg: ");
// sb.append(trimTo3Digits(((double) sum) / count));
// sb.append(" [").append(min).append(" | ").append(max).append("]");
// return sb;
// }
//
// /**
// * Adjust the given double value to keep only 3 decimal digits
// *
// * @param value value to adjust
// * @return double value with only 3 decimal digits
// */
// public static double trimTo3Digits(final double value) {
// return ((long) (1e3d * value)) / 1e3d;
// }
// }
// Path: src/main/java/com/sun/marlin/DHelpers.java
import java.util.Arrays;
import com.sun.marlin.stats.Histogram;
import com.sun.marlin.stats.StatLong;
// a stack of polynomial curves where each curve shares endpoints with
// adjacent ones.
static final class PolyStack {
private static final byte TYPE_LINETO = (byte) 0;
private static final byte TYPE_QUADTO = (byte) 1;
private static final byte TYPE_CUBICTO = (byte) 2;
// curves capacity = edges count (8192) = edges x 2 (coords)
private static final int INITIAL_CURVES_COUNT = INITIAL_EDGES_COUNT << 1;
// types capacity = edges count (4096)
private static final int INITIAL_TYPES_COUNT = INITIAL_EDGES_COUNT;
double[] curves;
int end;
byte[] curveTypes;
int numCurves;
// curves ref (dirty)
final DoubleArrayCache.Reference curves_ref;
// curveTypes ref (dirty)
final ByteArrayCache.Reference curveTypes_ref;
// used marks (stats only)
int curveTypesUseMark;
int curvesUseMark;
private final StatLong stat_polystack_types;
private final StatLong stat_polystack_curves; | private final Histogram hist_polystack_curves; |
bourgesl/marlin-fx | src/main/java/com/sun/marlin/DoubleArrayCache.java | // Path: src/main/java/com/sun/marlin/ArrayCacheConst.java
// static final int[] ARRAY_SIZES = new int[BUCKETS];
//
// Path: src/main/java/com/sun/marlin/ArrayCacheConst.java
// static final int BUCKETS = 8;
//
// Path: src/main/java/com/sun/marlin/ArrayCacheConst.java
// static final int MAX_ARRAY_SIZE;
//
// Path: src/main/java/com/sun/marlin/MarlinUtils.java
// public static void logInfo(final String msg) {
// if (MarlinConst.USE_LOGGER) {
// LOG.info(msg);
// } else if (MarlinConst.ENABLE_LOGS) {
// System.out.print("INFO: ");
// System.out.println(msg);
// }
// }
//
// Path: src/main/java/com/sun/marlin/MarlinUtils.java
// public static void logException(final String msg, final Throwable th) {
// if (MarlinConst.USE_LOGGER) {
// LOG.log(java.util.logging.Level.WARNING, msg, th);
// } else if (MarlinConst.ENABLE_LOGS) {
// System.out.print("WARNING: ");
// System.out.println(msg);
// th.printStackTrace(System.err);
// }
// }
//
// Path: src/main/java/com/sun/marlin/ArrayCacheConst.java
// static final class BucketStats {
// int getOp = 0;
// int createOp = 0;
// int returnOp = 0;
// int maxSize = 0;
//
// void reset() {
// getOp = 0;
// createOp = 0;
// returnOp = 0;
// maxSize = 0;
// }
//
// void updateMaxSize(final int size) {
// if (size > maxSize) {
// maxSize = size;
// }
// }
// }
//
// Path: src/main/java/com/sun/marlin/ArrayCacheConst.java
// static final class CacheStats {
// final String name;
// final BucketStats[] bucketStats;
// int resize = 0;
// int oversize = 0;
// long totalInitial = 0L;
//
// CacheStats(final String name) {
// this.name = name;
//
// bucketStats = new BucketStats[BUCKETS];
// for (int i = 0; i < BUCKETS; i++) {
// bucketStats[i] = new BucketStats();
// }
// }
//
// void reset() {
// resize = 0;
// oversize = 0;
//
// for (int i = 0; i < BUCKETS; i++) {
// bucketStats[i].reset();
// }
// }
//
// long dumpStats() {
// long totalCacheBytes = 0L;
//
// if (DO_STATS) {
// for (int i = 0; i < BUCKETS; i++) {
// final BucketStats s = bucketStats[i];
//
// if (s.maxSize != 0) {
// totalCacheBytes += getByteFactor()
// * (s.maxSize * ARRAY_SIZES[i]);
// }
// }
//
// if (totalInitial != 0L || totalCacheBytes != 0L
// || resize != 0 || oversize != 0)
// {
// logInfo(name + ": resize: " + resize
// + " - oversize: " + oversize
// + " - initial: " + getTotalInitialBytes()
// + " bytes (" + totalInitial + " elements)"
// + " - cache: " + totalCacheBytes + " bytes"
// );
// }
//
// if (totalCacheBytes != 0L) {
// logInfo(name + ": usage stats:");
//
// for (int i = 0; i < BUCKETS; i++) {
// final BucketStats s = bucketStats[i];
//
// if (s.getOp != 0) {
// logInfo(" Bucket[" + ARRAY_SIZES[i] + "]: "
// + "get: " + s.getOp
// + " - put: " + s.returnOp
// + " - create: " + s.createOp
// + " :: max size: " + s.maxSize
// );
// }
// }
// }
// }
// return totalCacheBytes;
// }
//
// private int getByteFactor() {
// int factor = 1;
// if (name.contains("Int") || name.contains("Float")) {
// factor = 4;
// } else if (name.contains("Double")) {
// factor = 8;
// }
// return factor;
// }
//
// long getTotalInitialBytes() {
// return getByteFactor() * totalInitial;
// }
// }
| import java.lang.ref.WeakReference;
import java.util.Arrays;
import com.sun.marlin.ArrayCacheConst.BucketStats;
import com.sun.marlin.ArrayCacheConst.CacheStats;
import static com.sun.marlin.ArrayCacheConst.ARRAY_SIZES;
import static com.sun.marlin.ArrayCacheConst.BUCKETS;
import static com.sun.marlin.ArrayCacheConst.MAX_ARRAY_SIZE;
import static com.sun.marlin.MarlinUtils.logInfo;
import static com.sun.marlin.MarlinUtils.logException; | (DO_STATS) ? stats.bucketStats[i] : null);
}
// update weak reference:
refBuckets = new WeakReference<Bucket[]>(buckets);
}
return buckets;
}
Reference createRef(final int initialSize) {
return new Reference(this, initialSize);
}
static final class Reference {
// initial array reference (direct access)
final double[] initial;
private final boolean clean;
private final DoubleArrayCache cache;
Reference(final DoubleArrayCache cache, final int initialSize) {
this.cache = cache;
this.clean = cache.clean;
this.initial = createArray(initialSize);
if (DO_STATS) {
cache.stats.totalInitial += initialSize;
}
}
double[] getArray(final int length) { | // Path: src/main/java/com/sun/marlin/ArrayCacheConst.java
// static final int[] ARRAY_SIZES = new int[BUCKETS];
//
// Path: src/main/java/com/sun/marlin/ArrayCacheConst.java
// static final int BUCKETS = 8;
//
// Path: src/main/java/com/sun/marlin/ArrayCacheConst.java
// static final int MAX_ARRAY_SIZE;
//
// Path: src/main/java/com/sun/marlin/MarlinUtils.java
// public static void logInfo(final String msg) {
// if (MarlinConst.USE_LOGGER) {
// LOG.info(msg);
// } else if (MarlinConst.ENABLE_LOGS) {
// System.out.print("INFO: ");
// System.out.println(msg);
// }
// }
//
// Path: src/main/java/com/sun/marlin/MarlinUtils.java
// public static void logException(final String msg, final Throwable th) {
// if (MarlinConst.USE_LOGGER) {
// LOG.log(java.util.logging.Level.WARNING, msg, th);
// } else if (MarlinConst.ENABLE_LOGS) {
// System.out.print("WARNING: ");
// System.out.println(msg);
// th.printStackTrace(System.err);
// }
// }
//
// Path: src/main/java/com/sun/marlin/ArrayCacheConst.java
// static final class BucketStats {
// int getOp = 0;
// int createOp = 0;
// int returnOp = 0;
// int maxSize = 0;
//
// void reset() {
// getOp = 0;
// createOp = 0;
// returnOp = 0;
// maxSize = 0;
// }
//
// void updateMaxSize(final int size) {
// if (size > maxSize) {
// maxSize = size;
// }
// }
// }
//
// Path: src/main/java/com/sun/marlin/ArrayCacheConst.java
// static final class CacheStats {
// final String name;
// final BucketStats[] bucketStats;
// int resize = 0;
// int oversize = 0;
// long totalInitial = 0L;
//
// CacheStats(final String name) {
// this.name = name;
//
// bucketStats = new BucketStats[BUCKETS];
// for (int i = 0; i < BUCKETS; i++) {
// bucketStats[i] = new BucketStats();
// }
// }
//
// void reset() {
// resize = 0;
// oversize = 0;
//
// for (int i = 0; i < BUCKETS; i++) {
// bucketStats[i].reset();
// }
// }
//
// long dumpStats() {
// long totalCacheBytes = 0L;
//
// if (DO_STATS) {
// for (int i = 0; i < BUCKETS; i++) {
// final BucketStats s = bucketStats[i];
//
// if (s.maxSize != 0) {
// totalCacheBytes += getByteFactor()
// * (s.maxSize * ARRAY_SIZES[i]);
// }
// }
//
// if (totalInitial != 0L || totalCacheBytes != 0L
// || resize != 0 || oversize != 0)
// {
// logInfo(name + ": resize: " + resize
// + " - oversize: " + oversize
// + " - initial: " + getTotalInitialBytes()
// + " bytes (" + totalInitial + " elements)"
// + " - cache: " + totalCacheBytes + " bytes"
// );
// }
//
// if (totalCacheBytes != 0L) {
// logInfo(name + ": usage stats:");
//
// for (int i = 0; i < BUCKETS; i++) {
// final BucketStats s = bucketStats[i];
//
// if (s.getOp != 0) {
// logInfo(" Bucket[" + ARRAY_SIZES[i] + "]: "
// + "get: " + s.getOp
// + " - put: " + s.returnOp
// + " - create: " + s.createOp
// + " :: max size: " + s.maxSize
// );
// }
// }
// }
// }
// return totalCacheBytes;
// }
//
// private int getByteFactor() {
// int factor = 1;
// if (name.contains("Int") || name.contains("Float")) {
// factor = 4;
// } else if (name.contains("Double")) {
// factor = 8;
// }
// return factor;
// }
//
// long getTotalInitialBytes() {
// return getByteFactor() * totalInitial;
// }
// }
// Path: src/main/java/com/sun/marlin/DoubleArrayCache.java
import java.lang.ref.WeakReference;
import java.util.Arrays;
import com.sun.marlin.ArrayCacheConst.BucketStats;
import com.sun.marlin.ArrayCacheConst.CacheStats;
import static com.sun.marlin.ArrayCacheConst.ARRAY_SIZES;
import static com.sun.marlin.ArrayCacheConst.BUCKETS;
import static com.sun.marlin.ArrayCacheConst.MAX_ARRAY_SIZE;
import static com.sun.marlin.MarlinUtils.logInfo;
import static com.sun.marlin.MarlinUtils.logException;
(DO_STATS) ? stats.bucketStats[i] : null);
}
// update weak reference:
refBuckets = new WeakReference<Bucket[]>(buckets);
}
return buckets;
}
Reference createRef(final int initialSize) {
return new Reference(this, initialSize);
}
static final class Reference {
// initial array reference (direct access)
final double[] initial;
private final boolean clean;
private final DoubleArrayCache cache;
Reference(final DoubleArrayCache cache, final int initialSize) {
this.cache = cache;
this.clean = cache.clean;
this.initial = createArray(initialSize);
if (DO_STATS) {
cache.stats.totalInitial += initialSize;
}
}
double[] getArray(final int length) { | if (length <= MAX_ARRAY_SIZE) { |
bourgesl/marlin-fx | src/main/java/com/sun/marlin/DoubleArrayCache.java | // Path: src/main/java/com/sun/marlin/ArrayCacheConst.java
// static final int[] ARRAY_SIZES = new int[BUCKETS];
//
// Path: src/main/java/com/sun/marlin/ArrayCacheConst.java
// static final int BUCKETS = 8;
//
// Path: src/main/java/com/sun/marlin/ArrayCacheConst.java
// static final int MAX_ARRAY_SIZE;
//
// Path: src/main/java/com/sun/marlin/MarlinUtils.java
// public static void logInfo(final String msg) {
// if (MarlinConst.USE_LOGGER) {
// LOG.info(msg);
// } else if (MarlinConst.ENABLE_LOGS) {
// System.out.print("INFO: ");
// System.out.println(msg);
// }
// }
//
// Path: src/main/java/com/sun/marlin/MarlinUtils.java
// public static void logException(final String msg, final Throwable th) {
// if (MarlinConst.USE_LOGGER) {
// LOG.log(java.util.logging.Level.WARNING, msg, th);
// } else if (MarlinConst.ENABLE_LOGS) {
// System.out.print("WARNING: ");
// System.out.println(msg);
// th.printStackTrace(System.err);
// }
// }
//
// Path: src/main/java/com/sun/marlin/ArrayCacheConst.java
// static final class BucketStats {
// int getOp = 0;
// int createOp = 0;
// int returnOp = 0;
// int maxSize = 0;
//
// void reset() {
// getOp = 0;
// createOp = 0;
// returnOp = 0;
// maxSize = 0;
// }
//
// void updateMaxSize(final int size) {
// if (size > maxSize) {
// maxSize = size;
// }
// }
// }
//
// Path: src/main/java/com/sun/marlin/ArrayCacheConst.java
// static final class CacheStats {
// final String name;
// final BucketStats[] bucketStats;
// int resize = 0;
// int oversize = 0;
// long totalInitial = 0L;
//
// CacheStats(final String name) {
// this.name = name;
//
// bucketStats = new BucketStats[BUCKETS];
// for (int i = 0; i < BUCKETS; i++) {
// bucketStats[i] = new BucketStats();
// }
// }
//
// void reset() {
// resize = 0;
// oversize = 0;
//
// for (int i = 0; i < BUCKETS; i++) {
// bucketStats[i].reset();
// }
// }
//
// long dumpStats() {
// long totalCacheBytes = 0L;
//
// if (DO_STATS) {
// for (int i = 0; i < BUCKETS; i++) {
// final BucketStats s = bucketStats[i];
//
// if (s.maxSize != 0) {
// totalCacheBytes += getByteFactor()
// * (s.maxSize * ARRAY_SIZES[i]);
// }
// }
//
// if (totalInitial != 0L || totalCacheBytes != 0L
// || resize != 0 || oversize != 0)
// {
// logInfo(name + ": resize: " + resize
// + " - oversize: " + oversize
// + " - initial: " + getTotalInitialBytes()
// + " bytes (" + totalInitial + " elements)"
// + " - cache: " + totalCacheBytes + " bytes"
// );
// }
//
// if (totalCacheBytes != 0L) {
// logInfo(name + ": usage stats:");
//
// for (int i = 0; i < BUCKETS; i++) {
// final BucketStats s = bucketStats[i];
//
// if (s.getOp != 0) {
// logInfo(" Bucket[" + ARRAY_SIZES[i] + "]: "
// + "get: " + s.getOp
// + " - put: " + s.returnOp
// + " - create: " + s.createOp
// + " :: max size: " + s.maxSize
// );
// }
// }
// }
// }
// return totalCacheBytes;
// }
//
// private int getByteFactor() {
// int factor = 1;
// if (name.contains("Int") || name.contains("Float")) {
// factor = 4;
// } else if (name.contains("Double")) {
// factor = 8;
// }
// return factor;
// }
//
// long getTotalInitialBytes() {
// return getByteFactor() * totalInitial;
// }
// }
| import java.lang.ref.WeakReference;
import java.util.Arrays;
import com.sun.marlin.ArrayCacheConst.BucketStats;
import com.sun.marlin.ArrayCacheConst.CacheStats;
import static com.sun.marlin.ArrayCacheConst.ARRAY_SIZES;
import static com.sun.marlin.ArrayCacheConst.BUCKETS;
import static com.sun.marlin.ArrayCacheConst.MAX_ARRAY_SIZE;
import static com.sun.marlin.MarlinUtils.logInfo;
import static com.sun.marlin.MarlinUtils.logException; | }
Reference createRef(final int initialSize) {
return new Reference(this, initialSize);
}
static final class Reference {
// initial array reference (direct access)
final double[] initial;
private final boolean clean;
private final DoubleArrayCache cache;
Reference(final DoubleArrayCache cache, final int initialSize) {
this.cache = cache;
this.clean = cache.clean;
this.initial = createArray(initialSize);
if (DO_STATS) {
cache.stats.totalInitial += initialSize;
}
}
double[] getArray(final int length) {
if (length <= MAX_ARRAY_SIZE) {
return cache.getCacheBucket(length).getArray();
}
if (DO_STATS) {
cache.stats.oversize++;
}
if (DO_LOG_OVERSIZE) { | // Path: src/main/java/com/sun/marlin/ArrayCacheConst.java
// static final int[] ARRAY_SIZES = new int[BUCKETS];
//
// Path: src/main/java/com/sun/marlin/ArrayCacheConst.java
// static final int BUCKETS = 8;
//
// Path: src/main/java/com/sun/marlin/ArrayCacheConst.java
// static final int MAX_ARRAY_SIZE;
//
// Path: src/main/java/com/sun/marlin/MarlinUtils.java
// public static void logInfo(final String msg) {
// if (MarlinConst.USE_LOGGER) {
// LOG.info(msg);
// } else if (MarlinConst.ENABLE_LOGS) {
// System.out.print("INFO: ");
// System.out.println(msg);
// }
// }
//
// Path: src/main/java/com/sun/marlin/MarlinUtils.java
// public static void logException(final String msg, final Throwable th) {
// if (MarlinConst.USE_LOGGER) {
// LOG.log(java.util.logging.Level.WARNING, msg, th);
// } else if (MarlinConst.ENABLE_LOGS) {
// System.out.print("WARNING: ");
// System.out.println(msg);
// th.printStackTrace(System.err);
// }
// }
//
// Path: src/main/java/com/sun/marlin/ArrayCacheConst.java
// static final class BucketStats {
// int getOp = 0;
// int createOp = 0;
// int returnOp = 0;
// int maxSize = 0;
//
// void reset() {
// getOp = 0;
// createOp = 0;
// returnOp = 0;
// maxSize = 0;
// }
//
// void updateMaxSize(final int size) {
// if (size > maxSize) {
// maxSize = size;
// }
// }
// }
//
// Path: src/main/java/com/sun/marlin/ArrayCacheConst.java
// static final class CacheStats {
// final String name;
// final BucketStats[] bucketStats;
// int resize = 0;
// int oversize = 0;
// long totalInitial = 0L;
//
// CacheStats(final String name) {
// this.name = name;
//
// bucketStats = new BucketStats[BUCKETS];
// for (int i = 0; i < BUCKETS; i++) {
// bucketStats[i] = new BucketStats();
// }
// }
//
// void reset() {
// resize = 0;
// oversize = 0;
//
// for (int i = 0; i < BUCKETS; i++) {
// bucketStats[i].reset();
// }
// }
//
// long dumpStats() {
// long totalCacheBytes = 0L;
//
// if (DO_STATS) {
// for (int i = 0; i < BUCKETS; i++) {
// final BucketStats s = bucketStats[i];
//
// if (s.maxSize != 0) {
// totalCacheBytes += getByteFactor()
// * (s.maxSize * ARRAY_SIZES[i]);
// }
// }
//
// if (totalInitial != 0L || totalCacheBytes != 0L
// || resize != 0 || oversize != 0)
// {
// logInfo(name + ": resize: " + resize
// + " - oversize: " + oversize
// + " - initial: " + getTotalInitialBytes()
// + " bytes (" + totalInitial + " elements)"
// + " - cache: " + totalCacheBytes + " bytes"
// );
// }
//
// if (totalCacheBytes != 0L) {
// logInfo(name + ": usage stats:");
//
// for (int i = 0; i < BUCKETS; i++) {
// final BucketStats s = bucketStats[i];
//
// if (s.getOp != 0) {
// logInfo(" Bucket[" + ARRAY_SIZES[i] + "]: "
// + "get: " + s.getOp
// + " - put: " + s.returnOp
// + " - create: " + s.createOp
// + " :: max size: " + s.maxSize
// );
// }
// }
// }
// }
// return totalCacheBytes;
// }
//
// private int getByteFactor() {
// int factor = 1;
// if (name.contains("Int") || name.contains("Float")) {
// factor = 4;
// } else if (name.contains("Double")) {
// factor = 8;
// }
// return factor;
// }
//
// long getTotalInitialBytes() {
// return getByteFactor() * totalInitial;
// }
// }
// Path: src/main/java/com/sun/marlin/DoubleArrayCache.java
import java.lang.ref.WeakReference;
import java.util.Arrays;
import com.sun.marlin.ArrayCacheConst.BucketStats;
import com.sun.marlin.ArrayCacheConst.CacheStats;
import static com.sun.marlin.ArrayCacheConst.ARRAY_SIZES;
import static com.sun.marlin.ArrayCacheConst.BUCKETS;
import static com.sun.marlin.ArrayCacheConst.MAX_ARRAY_SIZE;
import static com.sun.marlin.MarlinUtils.logInfo;
import static com.sun.marlin.MarlinUtils.logException;
}
Reference createRef(final int initialSize) {
return new Reference(this, initialSize);
}
static final class Reference {
// initial array reference (direct access)
final double[] initial;
private final boolean clean;
private final DoubleArrayCache cache;
Reference(final DoubleArrayCache cache, final int initialSize) {
this.cache = cache;
this.clean = cache.clean;
this.initial = createArray(initialSize);
if (DO_STATS) {
cache.stats.totalInitial += initialSize;
}
}
double[] getArray(final int length) {
if (length <= MAX_ARRAY_SIZE) {
return cache.getCacheBucket(length).getArray();
}
if (DO_STATS) {
cache.stats.oversize++;
}
if (DO_LOG_OVERSIZE) { | logInfo(getLogPrefix(clean) + "DoubleArrayCache: " |
bourgesl/marlin-fx | src/main/java/com/sun/marlin/DoubleArrayCache.java | // Path: src/main/java/com/sun/marlin/ArrayCacheConst.java
// static final int[] ARRAY_SIZES = new int[BUCKETS];
//
// Path: src/main/java/com/sun/marlin/ArrayCacheConst.java
// static final int BUCKETS = 8;
//
// Path: src/main/java/com/sun/marlin/ArrayCacheConst.java
// static final int MAX_ARRAY_SIZE;
//
// Path: src/main/java/com/sun/marlin/MarlinUtils.java
// public static void logInfo(final String msg) {
// if (MarlinConst.USE_LOGGER) {
// LOG.info(msg);
// } else if (MarlinConst.ENABLE_LOGS) {
// System.out.print("INFO: ");
// System.out.println(msg);
// }
// }
//
// Path: src/main/java/com/sun/marlin/MarlinUtils.java
// public static void logException(final String msg, final Throwable th) {
// if (MarlinConst.USE_LOGGER) {
// LOG.log(java.util.logging.Level.WARNING, msg, th);
// } else if (MarlinConst.ENABLE_LOGS) {
// System.out.print("WARNING: ");
// System.out.println(msg);
// th.printStackTrace(System.err);
// }
// }
//
// Path: src/main/java/com/sun/marlin/ArrayCacheConst.java
// static final class BucketStats {
// int getOp = 0;
// int createOp = 0;
// int returnOp = 0;
// int maxSize = 0;
//
// void reset() {
// getOp = 0;
// createOp = 0;
// returnOp = 0;
// maxSize = 0;
// }
//
// void updateMaxSize(final int size) {
// if (size > maxSize) {
// maxSize = size;
// }
// }
// }
//
// Path: src/main/java/com/sun/marlin/ArrayCacheConst.java
// static final class CacheStats {
// final String name;
// final BucketStats[] bucketStats;
// int resize = 0;
// int oversize = 0;
// long totalInitial = 0L;
//
// CacheStats(final String name) {
// this.name = name;
//
// bucketStats = new BucketStats[BUCKETS];
// for (int i = 0; i < BUCKETS; i++) {
// bucketStats[i] = new BucketStats();
// }
// }
//
// void reset() {
// resize = 0;
// oversize = 0;
//
// for (int i = 0; i < BUCKETS; i++) {
// bucketStats[i].reset();
// }
// }
//
// long dumpStats() {
// long totalCacheBytes = 0L;
//
// if (DO_STATS) {
// for (int i = 0; i < BUCKETS; i++) {
// final BucketStats s = bucketStats[i];
//
// if (s.maxSize != 0) {
// totalCacheBytes += getByteFactor()
// * (s.maxSize * ARRAY_SIZES[i]);
// }
// }
//
// if (totalInitial != 0L || totalCacheBytes != 0L
// || resize != 0 || oversize != 0)
// {
// logInfo(name + ": resize: " + resize
// + " - oversize: " + oversize
// + " - initial: " + getTotalInitialBytes()
// + " bytes (" + totalInitial + " elements)"
// + " - cache: " + totalCacheBytes + " bytes"
// );
// }
//
// if (totalCacheBytes != 0L) {
// logInfo(name + ": usage stats:");
//
// for (int i = 0; i < BUCKETS; i++) {
// final BucketStats s = bucketStats[i];
//
// if (s.getOp != 0) {
// logInfo(" Bucket[" + ARRAY_SIZES[i] + "]: "
// + "get: " + s.getOp
// + " - put: " + s.returnOp
// + " - create: " + s.createOp
// + " :: max size: " + s.maxSize
// );
// }
// }
// }
// }
// return totalCacheBytes;
// }
//
// private int getByteFactor() {
// int factor = 1;
// if (name.contains("Int") || name.contains("Float")) {
// factor = 4;
// } else if (name.contains("Double")) {
// factor = 8;
// }
// return factor;
// }
//
// long getTotalInitialBytes() {
// return getByteFactor() * totalInitial;
// }
// }
| import java.lang.ref.WeakReference;
import java.util.Arrays;
import com.sun.marlin.ArrayCacheConst.BucketStats;
import com.sun.marlin.ArrayCacheConst.CacheStats;
import static com.sun.marlin.ArrayCacheConst.ARRAY_SIZES;
import static com.sun.marlin.ArrayCacheConst.BUCKETS;
import static com.sun.marlin.ArrayCacheConst.MAX_ARRAY_SIZE;
import static com.sun.marlin.MarlinUtils.logInfo;
import static com.sun.marlin.MarlinUtils.logException; |
double[] putArray(final double[] array)
{
// dirty array helper:
return putArray(array, 0, array.length);
}
double[] putArray(final double[] array, final int fromIndex,
final int toIndex)
{
if (array.length <= MAX_ARRAY_SIZE) {
if ((clean || DO_CLEAN_DIRTY) && (toIndex != 0)) {
// clean-up array of dirty part[fromIndex; toIndex[
fill(array, fromIndex, toIndex, 0.0d);
}
// ensure to never store initial arrays in cache:
if (array != initial) {
cache.getCacheBucket(array.length).putArray(array);
}
}
return initial;
}
}
static final class Bucket {
private int tail = 0;
private final int arraySize;
private final boolean clean;
private final double[][] arrays; | // Path: src/main/java/com/sun/marlin/ArrayCacheConst.java
// static final int[] ARRAY_SIZES = new int[BUCKETS];
//
// Path: src/main/java/com/sun/marlin/ArrayCacheConst.java
// static final int BUCKETS = 8;
//
// Path: src/main/java/com/sun/marlin/ArrayCacheConst.java
// static final int MAX_ARRAY_SIZE;
//
// Path: src/main/java/com/sun/marlin/MarlinUtils.java
// public static void logInfo(final String msg) {
// if (MarlinConst.USE_LOGGER) {
// LOG.info(msg);
// } else if (MarlinConst.ENABLE_LOGS) {
// System.out.print("INFO: ");
// System.out.println(msg);
// }
// }
//
// Path: src/main/java/com/sun/marlin/MarlinUtils.java
// public static void logException(final String msg, final Throwable th) {
// if (MarlinConst.USE_LOGGER) {
// LOG.log(java.util.logging.Level.WARNING, msg, th);
// } else if (MarlinConst.ENABLE_LOGS) {
// System.out.print("WARNING: ");
// System.out.println(msg);
// th.printStackTrace(System.err);
// }
// }
//
// Path: src/main/java/com/sun/marlin/ArrayCacheConst.java
// static final class BucketStats {
// int getOp = 0;
// int createOp = 0;
// int returnOp = 0;
// int maxSize = 0;
//
// void reset() {
// getOp = 0;
// createOp = 0;
// returnOp = 0;
// maxSize = 0;
// }
//
// void updateMaxSize(final int size) {
// if (size > maxSize) {
// maxSize = size;
// }
// }
// }
//
// Path: src/main/java/com/sun/marlin/ArrayCacheConst.java
// static final class CacheStats {
// final String name;
// final BucketStats[] bucketStats;
// int resize = 0;
// int oversize = 0;
// long totalInitial = 0L;
//
// CacheStats(final String name) {
// this.name = name;
//
// bucketStats = new BucketStats[BUCKETS];
// for (int i = 0; i < BUCKETS; i++) {
// bucketStats[i] = new BucketStats();
// }
// }
//
// void reset() {
// resize = 0;
// oversize = 0;
//
// for (int i = 0; i < BUCKETS; i++) {
// bucketStats[i].reset();
// }
// }
//
// long dumpStats() {
// long totalCacheBytes = 0L;
//
// if (DO_STATS) {
// for (int i = 0; i < BUCKETS; i++) {
// final BucketStats s = bucketStats[i];
//
// if (s.maxSize != 0) {
// totalCacheBytes += getByteFactor()
// * (s.maxSize * ARRAY_SIZES[i]);
// }
// }
//
// if (totalInitial != 0L || totalCacheBytes != 0L
// || resize != 0 || oversize != 0)
// {
// logInfo(name + ": resize: " + resize
// + " - oversize: " + oversize
// + " - initial: " + getTotalInitialBytes()
// + " bytes (" + totalInitial + " elements)"
// + " - cache: " + totalCacheBytes + " bytes"
// );
// }
//
// if (totalCacheBytes != 0L) {
// logInfo(name + ": usage stats:");
//
// for (int i = 0; i < BUCKETS; i++) {
// final BucketStats s = bucketStats[i];
//
// if (s.getOp != 0) {
// logInfo(" Bucket[" + ARRAY_SIZES[i] + "]: "
// + "get: " + s.getOp
// + " - put: " + s.returnOp
// + " - create: " + s.createOp
// + " :: max size: " + s.maxSize
// );
// }
// }
// }
// }
// return totalCacheBytes;
// }
//
// private int getByteFactor() {
// int factor = 1;
// if (name.contains("Int") || name.contains("Float")) {
// factor = 4;
// } else if (name.contains("Double")) {
// factor = 8;
// }
// return factor;
// }
//
// long getTotalInitialBytes() {
// return getByteFactor() * totalInitial;
// }
// }
// Path: src/main/java/com/sun/marlin/DoubleArrayCache.java
import java.lang.ref.WeakReference;
import java.util.Arrays;
import com.sun.marlin.ArrayCacheConst.BucketStats;
import com.sun.marlin.ArrayCacheConst.CacheStats;
import static com.sun.marlin.ArrayCacheConst.ARRAY_SIZES;
import static com.sun.marlin.ArrayCacheConst.BUCKETS;
import static com.sun.marlin.ArrayCacheConst.MAX_ARRAY_SIZE;
import static com.sun.marlin.MarlinUtils.logInfo;
import static com.sun.marlin.MarlinUtils.logException;
double[] putArray(final double[] array)
{
// dirty array helper:
return putArray(array, 0, array.length);
}
double[] putArray(final double[] array, final int fromIndex,
final int toIndex)
{
if (array.length <= MAX_ARRAY_SIZE) {
if ((clean || DO_CLEAN_DIRTY) && (toIndex != 0)) {
// clean-up array of dirty part[fromIndex; toIndex[
fill(array, fromIndex, toIndex, 0.0d);
}
// ensure to never store initial arrays in cache:
if (array != initial) {
cache.getCacheBucket(array.length).putArray(array);
}
}
return initial;
}
}
static final class Bucket {
private int tail = 0;
private final int arraySize;
private final boolean clean;
private final double[][] arrays; | private final BucketStats stats; |
bourgesl/marlin-fx | src/main/java/com/sun/marlin/DoubleArrayCache.java | // Path: src/main/java/com/sun/marlin/ArrayCacheConst.java
// static final int[] ARRAY_SIZES = new int[BUCKETS];
//
// Path: src/main/java/com/sun/marlin/ArrayCacheConst.java
// static final int BUCKETS = 8;
//
// Path: src/main/java/com/sun/marlin/ArrayCacheConst.java
// static final int MAX_ARRAY_SIZE;
//
// Path: src/main/java/com/sun/marlin/MarlinUtils.java
// public static void logInfo(final String msg) {
// if (MarlinConst.USE_LOGGER) {
// LOG.info(msg);
// } else if (MarlinConst.ENABLE_LOGS) {
// System.out.print("INFO: ");
// System.out.println(msg);
// }
// }
//
// Path: src/main/java/com/sun/marlin/MarlinUtils.java
// public static void logException(final String msg, final Throwable th) {
// if (MarlinConst.USE_LOGGER) {
// LOG.log(java.util.logging.Level.WARNING, msg, th);
// } else if (MarlinConst.ENABLE_LOGS) {
// System.out.print("WARNING: ");
// System.out.println(msg);
// th.printStackTrace(System.err);
// }
// }
//
// Path: src/main/java/com/sun/marlin/ArrayCacheConst.java
// static final class BucketStats {
// int getOp = 0;
// int createOp = 0;
// int returnOp = 0;
// int maxSize = 0;
//
// void reset() {
// getOp = 0;
// createOp = 0;
// returnOp = 0;
// maxSize = 0;
// }
//
// void updateMaxSize(final int size) {
// if (size > maxSize) {
// maxSize = size;
// }
// }
// }
//
// Path: src/main/java/com/sun/marlin/ArrayCacheConst.java
// static final class CacheStats {
// final String name;
// final BucketStats[] bucketStats;
// int resize = 0;
// int oversize = 0;
// long totalInitial = 0L;
//
// CacheStats(final String name) {
// this.name = name;
//
// bucketStats = new BucketStats[BUCKETS];
// for (int i = 0; i < BUCKETS; i++) {
// bucketStats[i] = new BucketStats();
// }
// }
//
// void reset() {
// resize = 0;
// oversize = 0;
//
// for (int i = 0; i < BUCKETS; i++) {
// bucketStats[i].reset();
// }
// }
//
// long dumpStats() {
// long totalCacheBytes = 0L;
//
// if (DO_STATS) {
// for (int i = 0; i < BUCKETS; i++) {
// final BucketStats s = bucketStats[i];
//
// if (s.maxSize != 0) {
// totalCacheBytes += getByteFactor()
// * (s.maxSize * ARRAY_SIZES[i]);
// }
// }
//
// if (totalInitial != 0L || totalCacheBytes != 0L
// || resize != 0 || oversize != 0)
// {
// logInfo(name + ": resize: " + resize
// + " - oversize: " + oversize
// + " - initial: " + getTotalInitialBytes()
// + " bytes (" + totalInitial + " elements)"
// + " - cache: " + totalCacheBytes + " bytes"
// );
// }
//
// if (totalCacheBytes != 0L) {
// logInfo(name + ": usage stats:");
//
// for (int i = 0; i < BUCKETS; i++) {
// final BucketStats s = bucketStats[i];
//
// if (s.getOp != 0) {
// logInfo(" Bucket[" + ARRAY_SIZES[i] + "]: "
// + "get: " + s.getOp
// + " - put: " + s.returnOp
// + " - create: " + s.createOp
// + " :: max size: " + s.maxSize
// );
// }
// }
// }
// }
// return totalCacheBytes;
// }
//
// private int getByteFactor() {
// int factor = 1;
// if (name.contains("Int") || name.contains("Float")) {
// factor = 4;
// } else if (name.contains("Double")) {
// factor = 8;
// }
// return factor;
// }
//
// long getTotalInitialBytes() {
// return getByteFactor() * totalInitial;
// }
// }
| import java.lang.ref.WeakReference;
import java.util.Arrays;
import com.sun.marlin.ArrayCacheConst.BucketStats;
import com.sun.marlin.ArrayCacheConst.CacheStats;
import static com.sun.marlin.ArrayCacheConst.ARRAY_SIZES;
import static com.sun.marlin.ArrayCacheConst.BUCKETS;
import static com.sun.marlin.ArrayCacheConst.MAX_ARRAY_SIZE;
import static com.sun.marlin.MarlinUtils.logInfo;
import static com.sun.marlin.MarlinUtils.logException; | stats.updateMaxSize(tail);
}
} else if (DO_CHECKS) {
logInfo(getLogPrefix(clean) + "DoubleArrayCache: "
+ "array capacity exceeded !");
}
}
}
static double[] createArray(final int length) {
return new double[length];
}
static void fill(final double[] array, final int fromIndex,
final int toIndex, final double value)
{
// clear array data:
Arrays.fill(array, fromIndex, toIndex, value);
if (DO_CHECKS) {
check(array, fromIndex, toIndex, value);
}
}
public static void check(final double[] array, final int fromIndex,
final int toIndex, final double value)
{
if (DO_CHECKS) {
// check zero on full array:
for (int i = 0; i < array.length; i++) {
if (array[i] != value) { | // Path: src/main/java/com/sun/marlin/ArrayCacheConst.java
// static final int[] ARRAY_SIZES = new int[BUCKETS];
//
// Path: src/main/java/com/sun/marlin/ArrayCacheConst.java
// static final int BUCKETS = 8;
//
// Path: src/main/java/com/sun/marlin/ArrayCacheConst.java
// static final int MAX_ARRAY_SIZE;
//
// Path: src/main/java/com/sun/marlin/MarlinUtils.java
// public static void logInfo(final String msg) {
// if (MarlinConst.USE_LOGGER) {
// LOG.info(msg);
// } else if (MarlinConst.ENABLE_LOGS) {
// System.out.print("INFO: ");
// System.out.println(msg);
// }
// }
//
// Path: src/main/java/com/sun/marlin/MarlinUtils.java
// public static void logException(final String msg, final Throwable th) {
// if (MarlinConst.USE_LOGGER) {
// LOG.log(java.util.logging.Level.WARNING, msg, th);
// } else if (MarlinConst.ENABLE_LOGS) {
// System.out.print("WARNING: ");
// System.out.println(msg);
// th.printStackTrace(System.err);
// }
// }
//
// Path: src/main/java/com/sun/marlin/ArrayCacheConst.java
// static final class BucketStats {
// int getOp = 0;
// int createOp = 0;
// int returnOp = 0;
// int maxSize = 0;
//
// void reset() {
// getOp = 0;
// createOp = 0;
// returnOp = 0;
// maxSize = 0;
// }
//
// void updateMaxSize(final int size) {
// if (size > maxSize) {
// maxSize = size;
// }
// }
// }
//
// Path: src/main/java/com/sun/marlin/ArrayCacheConst.java
// static final class CacheStats {
// final String name;
// final BucketStats[] bucketStats;
// int resize = 0;
// int oversize = 0;
// long totalInitial = 0L;
//
// CacheStats(final String name) {
// this.name = name;
//
// bucketStats = new BucketStats[BUCKETS];
// for (int i = 0; i < BUCKETS; i++) {
// bucketStats[i] = new BucketStats();
// }
// }
//
// void reset() {
// resize = 0;
// oversize = 0;
//
// for (int i = 0; i < BUCKETS; i++) {
// bucketStats[i].reset();
// }
// }
//
// long dumpStats() {
// long totalCacheBytes = 0L;
//
// if (DO_STATS) {
// for (int i = 0; i < BUCKETS; i++) {
// final BucketStats s = bucketStats[i];
//
// if (s.maxSize != 0) {
// totalCacheBytes += getByteFactor()
// * (s.maxSize * ARRAY_SIZES[i]);
// }
// }
//
// if (totalInitial != 0L || totalCacheBytes != 0L
// || resize != 0 || oversize != 0)
// {
// logInfo(name + ": resize: " + resize
// + " - oversize: " + oversize
// + " - initial: " + getTotalInitialBytes()
// + " bytes (" + totalInitial + " elements)"
// + " - cache: " + totalCacheBytes + " bytes"
// );
// }
//
// if (totalCacheBytes != 0L) {
// logInfo(name + ": usage stats:");
//
// for (int i = 0; i < BUCKETS; i++) {
// final BucketStats s = bucketStats[i];
//
// if (s.getOp != 0) {
// logInfo(" Bucket[" + ARRAY_SIZES[i] + "]: "
// + "get: " + s.getOp
// + " - put: " + s.returnOp
// + " - create: " + s.createOp
// + " :: max size: " + s.maxSize
// );
// }
// }
// }
// }
// return totalCacheBytes;
// }
//
// private int getByteFactor() {
// int factor = 1;
// if (name.contains("Int") || name.contains("Float")) {
// factor = 4;
// } else if (name.contains("Double")) {
// factor = 8;
// }
// return factor;
// }
//
// long getTotalInitialBytes() {
// return getByteFactor() * totalInitial;
// }
// }
// Path: src/main/java/com/sun/marlin/DoubleArrayCache.java
import java.lang.ref.WeakReference;
import java.util.Arrays;
import com.sun.marlin.ArrayCacheConst.BucketStats;
import com.sun.marlin.ArrayCacheConst.CacheStats;
import static com.sun.marlin.ArrayCacheConst.ARRAY_SIZES;
import static com.sun.marlin.ArrayCacheConst.BUCKETS;
import static com.sun.marlin.ArrayCacheConst.MAX_ARRAY_SIZE;
import static com.sun.marlin.MarlinUtils.logInfo;
import static com.sun.marlin.MarlinUtils.logException;
stats.updateMaxSize(tail);
}
} else if (DO_CHECKS) {
logInfo(getLogPrefix(clean) + "DoubleArrayCache: "
+ "array capacity exceeded !");
}
}
}
static double[] createArray(final int length) {
return new double[length];
}
static void fill(final double[] array, final int fromIndex,
final int toIndex, final double value)
{
// clear array data:
Arrays.fill(array, fromIndex, toIndex, value);
if (DO_CHECKS) {
check(array, fromIndex, toIndex, value);
}
}
public static void check(final double[] array, final int fromIndex,
final int toIndex, final double value)
{
if (DO_CHECKS) {
// check zero on full array:
for (int i = 0; i < array.length; i++) {
if (array[i] != value) { | logException("Invalid value at: " + i + " = " + array[i] |
bourgesl/marlin-fx | src/test/java/test/com/sun/marlin/QPathTest.java | // Path: src/test/java/test/util/Util.java
// public static final int TIMEOUT = 5000;
| import java.util.Locale;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import java.util.logging.Handler;
import java.util.logging.Level;
import java.util.logging.LogRecord;
import java.util.logging.Logger;
import javafx.animation.KeyFrame;
import javafx.animation.KeyValue;
import javafx.animation.Timeline;
import javafx.application.Application;
import javafx.application.Platform;
import javafx.beans.property.DoubleProperty;
import javafx.beans.property.SimpleDoubleProperty;
import javafx.geometry.Bounds;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.paint.Color;
import javafx.scene.shape.SVGPath;
import javafx.stage.Stage;
import javafx.util.Duration;
import junit.framework.AssertionFailedError;
import org.junit.AfterClass;
import org.junit.Assert;
import static org.junit.Assert.assertEquals;
import org.junit.BeforeClass;
import org.junit.Test;
import static test.util.Util.TIMEOUT; | private CountDownLatch latch = new CountDownLatch(1);
// Application class. An instance is created and initialized before running
// the first test, and it lives through the execution of all tests.
public static class MyApp extends Application {
Stage stage = null;
public MyApp() {
super();
}
@Override
public void init() {
QPathTest.myApp = this;
}
@Override
public void start(Stage primaryStage) throws Exception {
this.stage = primaryStage;
launchLatch.countDown();
}
}
@BeforeClass
public static void setupOnce() {
// Start the Application
new Thread(() -> Application.launch(MyApp.class, (String[]) null)).start();
try { | // Path: src/test/java/test/util/Util.java
// public static final int TIMEOUT = 5000;
// Path: src/test/java/test/com/sun/marlin/QPathTest.java
import java.util.Locale;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import java.util.logging.Handler;
import java.util.logging.Level;
import java.util.logging.LogRecord;
import java.util.logging.Logger;
import javafx.animation.KeyFrame;
import javafx.animation.KeyValue;
import javafx.animation.Timeline;
import javafx.application.Application;
import javafx.application.Platform;
import javafx.beans.property.DoubleProperty;
import javafx.beans.property.SimpleDoubleProperty;
import javafx.geometry.Bounds;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.paint.Color;
import javafx.scene.shape.SVGPath;
import javafx.stage.Stage;
import javafx.util.Duration;
import junit.framework.AssertionFailedError;
import org.junit.AfterClass;
import org.junit.Assert;
import static org.junit.Assert.assertEquals;
import org.junit.BeforeClass;
import org.junit.Test;
import static test.util.Util.TIMEOUT;
private CountDownLatch latch = new CountDownLatch(1);
// Application class. An instance is created and initialized before running
// the first test, and it lives through the execution of all tests.
public static class MyApp extends Application {
Stage stage = null;
public MyApp() {
super();
}
@Override
public void init() {
QPathTest.myApp = this;
}
@Override
public void start(Stage primaryStage) throws Exception {
this.stage = primaryStage;
launchLatch.countDown();
}
}
@BeforeClass
public static void setupOnce() {
// Start the Application
new Thread(() -> Application.launch(MyApp.class, (String[]) null)).start();
try { | if (!launchLatch.await(TIMEOUT, TimeUnit.MILLISECONDS)) { |
Querz/NBT | src/main/java/net/querz/nbt/io/NBTOutput.java | // Path: src/main/java/net/querz/nbt/tag/Tag.java
// public abstract class Tag<T> implements Cloneable {
//
// /**
// * The default maximum depth of the NBT structure.
// * */
// public static final int DEFAULT_MAX_DEPTH = 512;
//
// private static final Map<String, String> ESCAPE_CHARACTERS;
// static {
// final Map<String, String> temp = new HashMap<>();
// temp.put("\\", "\\\\\\\\");
// temp.put("\n", "\\\\n");
// temp.put("\t", "\\\\t");
// temp.put("\r", "\\\\r");
// temp.put("\"", "\\\\\"");
// ESCAPE_CHARACTERS = Collections.unmodifiableMap(temp);
// }
//
// private static final Pattern ESCAPE_PATTERN = Pattern.compile("[\\\\\n\t\r\"]");
// private static final Pattern NON_QUOTE_PATTERN = Pattern.compile("[a-zA-Z0-9_\\-+]+");
//
// private T value;
//
// /**
// * Initializes this Tag with some value. If the value is {@code null}, it will
// * throw a {@code NullPointerException}
// * @param value The value to be set for this Tag.
// * */
// public Tag(T value) {
// setValue(value);
// }
//
// /**
// * @return This Tag's ID, usually used for serialization and deserialization.
// * */
// public abstract byte getID();
//
// /**
// * @return The value of this Tag.
// * */
// protected T getValue() {
// return value;
// }
//
// /**
// * Sets the value for this Tag directly.
// * @param value The value to be set.
// * @throws NullPointerException If the value is null
// * */
// protected void setValue(T value) {
// this.value = checkValue(value);
// }
//
// /**
// * Checks if the value {@code value} is {@code null}.
// * @param value The value to check
// * @throws NullPointerException If {@code value} was {@code null}
// * @return The parameter {@code value}
// * */
// protected T checkValue(T value) {
// return Objects.requireNonNull(value);
// }
//
// /**
// * Calls {@link Tag#toString(int)} with an initial depth of {@code 0}.
// * @see Tag#toString(int)
// * @throws MaxDepthReachedException If the maximum nesting depth is exceeded.
// * */
// @Override
// public final String toString() {
// return toString(DEFAULT_MAX_DEPTH);
// }
//
// /**
// * Creates a string representation of this Tag in a valid JSON format.
// * @param maxDepth The maximum nesting depth.
// * @return The string representation of this Tag.
// * @throws MaxDepthReachedException If the maximum nesting depth is exceeded.
// * */
// public String toString(int maxDepth) {
// return "{\"type\":\""+ getClass().getSimpleName() + "\"," +
// "\"value\":" + valueToString(maxDepth) + "}";
// }
//
// /**
// * Calls {@link Tag#valueToString(int)} with {@link Tag#DEFAULT_MAX_DEPTH}.
// * @return The string representation of the value of this Tag.
// * @throws MaxDepthReachedException If the maximum nesting depth is exceeded.
// * */
// public String valueToString() {
// return valueToString(DEFAULT_MAX_DEPTH);
// }
//
// /**
// * Returns a JSON representation of the value of this Tag.
// * @param maxDepth The maximum nesting depth.
// * @return The string representation of the value of this Tag.
// * @throws MaxDepthReachedException If the maximum nesting depth is exceeded.
// * */
// public abstract String valueToString(int maxDepth);
//
// /**
// * Returns whether this Tag and some other Tag are equal.
// * They are equal if {@code other} is not {@code null} and they are of the same class.
// * Custom Tag implementations should overwrite this but check the result
// * of this {@code super}-method while comparing.
// * @param other The Tag to compare to.
// * @return {@code true} if they are equal based on the conditions mentioned above.
// * */
// @Override
// public boolean equals(Object other) {
// return other != null && getClass() == other.getClass();
// }
//
// /**
// * Calculates the hash code of this Tag. Tags which are equal according to {@link Tag#equals(Object)}
// * must return an equal hash code.
// * @return The hash code of this Tag.
// * */
// @Override
// public int hashCode() {
// return value.hashCode();
// }
//
// /**
// * Creates a clone of this Tag.
// * @return A clone of this Tag.
// * */
// @SuppressWarnings("CloneDoesntDeclareCloneNotSupportedException")
// public abstract Tag<T> clone();
//
// /**
// * Escapes a string to fit into a JSON-like string representation for Minecraft
// * or to create the JSON string representation of a Tag returned from {@link Tag#toString()}
// * @param s The string to be escaped.
// * @param lenient {@code true} if it should force double quotes ({@code "}) at the start and
// * the end of the string.
// * @return The escaped string.
// * */
// protected static String escapeString(String s, boolean lenient) {
// StringBuffer sb = new StringBuffer();
// Matcher m = ESCAPE_PATTERN.matcher(s);
// while (m.find()) {
// m.appendReplacement(sb, ESCAPE_CHARACTERS.get(m.group()));
// }
// m.appendTail(sb);
// m = NON_QUOTE_PATTERN.matcher(s);
// if (!lenient || !m.matches()) {
// sb.insert(0, "\"").append("\"");
// }
// return sb.toString();
// }
// }
| import net.querz.nbt.tag.Tag;
import java.io.IOException; | package net.querz.nbt.io;
public interface NBTOutput {
void writeTag(NamedTag tag, int maxDepth) throws IOException;
| // Path: src/main/java/net/querz/nbt/tag/Tag.java
// public abstract class Tag<T> implements Cloneable {
//
// /**
// * The default maximum depth of the NBT structure.
// * */
// public static final int DEFAULT_MAX_DEPTH = 512;
//
// private static final Map<String, String> ESCAPE_CHARACTERS;
// static {
// final Map<String, String> temp = new HashMap<>();
// temp.put("\\", "\\\\\\\\");
// temp.put("\n", "\\\\n");
// temp.put("\t", "\\\\t");
// temp.put("\r", "\\\\r");
// temp.put("\"", "\\\\\"");
// ESCAPE_CHARACTERS = Collections.unmodifiableMap(temp);
// }
//
// private static final Pattern ESCAPE_PATTERN = Pattern.compile("[\\\\\n\t\r\"]");
// private static final Pattern NON_QUOTE_PATTERN = Pattern.compile("[a-zA-Z0-9_\\-+]+");
//
// private T value;
//
// /**
// * Initializes this Tag with some value. If the value is {@code null}, it will
// * throw a {@code NullPointerException}
// * @param value The value to be set for this Tag.
// * */
// public Tag(T value) {
// setValue(value);
// }
//
// /**
// * @return This Tag's ID, usually used for serialization and deserialization.
// * */
// public abstract byte getID();
//
// /**
// * @return The value of this Tag.
// * */
// protected T getValue() {
// return value;
// }
//
// /**
// * Sets the value for this Tag directly.
// * @param value The value to be set.
// * @throws NullPointerException If the value is null
// * */
// protected void setValue(T value) {
// this.value = checkValue(value);
// }
//
// /**
// * Checks if the value {@code value} is {@code null}.
// * @param value The value to check
// * @throws NullPointerException If {@code value} was {@code null}
// * @return The parameter {@code value}
// * */
// protected T checkValue(T value) {
// return Objects.requireNonNull(value);
// }
//
// /**
// * Calls {@link Tag#toString(int)} with an initial depth of {@code 0}.
// * @see Tag#toString(int)
// * @throws MaxDepthReachedException If the maximum nesting depth is exceeded.
// * */
// @Override
// public final String toString() {
// return toString(DEFAULT_MAX_DEPTH);
// }
//
// /**
// * Creates a string representation of this Tag in a valid JSON format.
// * @param maxDepth The maximum nesting depth.
// * @return The string representation of this Tag.
// * @throws MaxDepthReachedException If the maximum nesting depth is exceeded.
// * */
// public String toString(int maxDepth) {
// return "{\"type\":\""+ getClass().getSimpleName() + "\"," +
// "\"value\":" + valueToString(maxDepth) + "}";
// }
//
// /**
// * Calls {@link Tag#valueToString(int)} with {@link Tag#DEFAULT_MAX_DEPTH}.
// * @return The string representation of the value of this Tag.
// * @throws MaxDepthReachedException If the maximum nesting depth is exceeded.
// * */
// public String valueToString() {
// return valueToString(DEFAULT_MAX_DEPTH);
// }
//
// /**
// * Returns a JSON representation of the value of this Tag.
// * @param maxDepth The maximum nesting depth.
// * @return The string representation of the value of this Tag.
// * @throws MaxDepthReachedException If the maximum nesting depth is exceeded.
// * */
// public abstract String valueToString(int maxDepth);
//
// /**
// * Returns whether this Tag and some other Tag are equal.
// * They are equal if {@code other} is not {@code null} and they are of the same class.
// * Custom Tag implementations should overwrite this but check the result
// * of this {@code super}-method while comparing.
// * @param other The Tag to compare to.
// * @return {@code true} if they are equal based on the conditions mentioned above.
// * */
// @Override
// public boolean equals(Object other) {
// return other != null && getClass() == other.getClass();
// }
//
// /**
// * Calculates the hash code of this Tag. Tags which are equal according to {@link Tag#equals(Object)}
// * must return an equal hash code.
// * @return The hash code of this Tag.
// * */
// @Override
// public int hashCode() {
// return value.hashCode();
// }
//
// /**
// * Creates a clone of this Tag.
// * @return A clone of this Tag.
// * */
// @SuppressWarnings("CloneDoesntDeclareCloneNotSupportedException")
// public abstract Tag<T> clone();
//
// /**
// * Escapes a string to fit into a JSON-like string representation for Minecraft
// * or to create the JSON string representation of a Tag returned from {@link Tag#toString()}
// * @param s The string to be escaped.
// * @param lenient {@code true} if it should force double quotes ({@code "}) at the start and
// * the end of the string.
// * @return The escaped string.
// * */
// protected static String escapeString(String s, boolean lenient) {
// StringBuffer sb = new StringBuffer();
// Matcher m = ESCAPE_PATTERN.matcher(s);
// while (m.find()) {
// m.appendReplacement(sb, ESCAPE_CHARACTERS.get(m.group()));
// }
// m.appendTail(sb);
// m = NON_QUOTE_PATTERN.matcher(s);
// if (!lenient || !m.matches()) {
// sb.insert(0, "\"").append("\"");
// }
// return sb.toString();
// }
// }
// Path: src/main/java/net/querz/nbt/io/NBTOutput.java
import net.querz.nbt.tag.Tag;
import java.io.IOException;
package net.querz.nbt.io;
public interface NBTOutput {
void writeTag(NamedTag tag, int maxDepth) throws IOException;
| void writeTag(Tag<?> tag, int maxDepth) throws IOException; |
Querz/NBT | src/main/java/net/querz/nbt/io/NamedTag.java | // Path: src/main/java/net/querz/nbt/tag/Tag.java
// public abstract class Tag<T> implements Cloneable {
//
// /**
// * The default maximum depth of the NBT structure.
// * */
// public static final int DEFAULT_MAX_DEPTH = 512;
//
// private static final Map<String, String> ESCAPE_CHARACTERS;
// static {
// final Map<String, String> temp = new HashMap<>();
// temp.put("\\", "\\\\\\\\");
// temp.put("\n", "\\\\n");
// temp.put("\t", "\\\\t");
// temp.put("\r", "\\\\r");
// temp.put("\"", "\\\\\"");
// ESCAPE_CHARACTERS = Collections.unmodifiableMap(temp);
// }
//
// private static final Pattern ESCAPE_PATTERN = Pattern.compile("[\\\\\n\t\r\"]");
// private static final Pattern NON_QUOTE_PATTERN = Pattern.compile("[a-zA-Z0-9_\\-+]+");
//
// private T value;
//
// /**
// * Initializes this Tag with some value. If the value is {@code null}, it will
// * throw a {@code NullPointerException}
// * @param value The value to be set for this Tag.
// * */
// public Tag(T value) {
// setValue(value);
// }
//
// /**
// * @return This Tag's ID, usually used for serialization and deserialization.
// * */
// public abstract byte getID();
//
// /**
// * @return The value of this Tag.
// * */
// protected T getValue() {
// return value;
// }
//
// /**
// * Sets the value for this Tag directly.
// * @param value The value to be set.
// * @throws NullPointerException If the value is null
// * */
// protected void setValue(T value) {
// this.value = checkValue(value);
// }
//
// /**
// * Checks if the value {@code value} is {@code null}.
// * @param value The value to check
// * @throws NullPointerException If {@code value} was {@code null}
// * @return The parameter {@code value}
// * */
// protected T checkValue(T value) {
// return Objects.requireNonNull(value);
// }
//
// /**
// * Calls {@link Tag#toString(int)} with an initial depth of {@code 0}.
// * @see Tag#toString(int)
// * @throws MaxDepthReachedException If the maximum nesting depth is exceeded.
// * */
// @Override
// public final String toString() {
// return toString(DEFAULT_MAX_DEPTH);
// }
//
// /**
// * Creates a string representation of this Tag in a valid JSON format.
// * @param maxDepth The maximum nesting depth.
// * @return The string representation of this Tag.
// * @throws MaxDepthReachedException If the maximum nesting depth is exceeded.
// * */
// public String toString(int maxDepth) {
// return "{\"type\":\""+ getClass().getSimpleName() + "\"," +
// "\"value\":" + valueToString(maxDepth) + "}";
// }
//
// /**
// * Calls {@link Tag#valueToString(int)} with {@link Tag#DEFAULT_MAX_DEPTH}.
// * @return The string representation of the value of this Tag.
// * @throws MaxDepthReachedException If the maximum nesting depth is exceeded.
// * */
// public String valueToString() {
// return valueToString(DEFAULT_MAX_DEPTH);
// }
//
// /**
// * Returns a JSON representation of the value of this Tag.
// * @param maxDepth The maximum nesting depth.
// * @return The string representation of the value of this Tag.
// * @throws MaxDepthReachedException If the maximum nesting depth is exceeded.
// * */
// public abstract String valueToString(int maxDepth);
//
// /**
// * Returns whether this Tag and some other Tag are equal.
// * They are equal if {@code other} is not {@code null} and they are of the same class.
// * Custom Tag implementations should overwrite this but check the result
// * of this {@code super}-method while comparing.
// * @param other The Tag to compare to.
// * @return {@code true} if they are equal based on the conditions mentioned above.
// * */
// @Override
// public boolean equals(Object other) {
// return other != null && getClass() == other.getClass();
// }
//
// /**
// * Calculates the hash code of this Tag. Tags which are equal according to {@link Tag#equals(Object)}
// * must return an equal hash code.
// * @return The hash code of this Tag.
// * */
// @Override
// public int hashCode() {
// return value.hashCode();
// }
//
// /**
// * Creates a clone of this Tag.
// * @return A clone of this Tag.
// * */
// @SuppressWarnings("CloneDoesntDeclareCloneNotSupportedException")
// public abstract Tag<T> clone();
//
// /**
// * Escapes a string to fit into a JSON-like string representation for Minecraft
// * or to create the JSON string representation of a Tag returned from {@link Tag#toString()}
// * @param s The string to be escaped.
// * @param lenient {@code true} if it should force double quotes ({@code "}) at the start and
// * the end of the string.
// * @return The escaped string.
// * */
// protected static String escapeString(String s, boolean lenient) {
// StringBuffer sb = new StringBuffer();
// Matcher m = ESCAPE_PATTERN.matcher(s);
// while (m.find()) {
// m.appendReplacement(sb, ESCAPE_CHARACTERS.get(m.group()));
// }
// m.appendTail(sb);
// m = NON_QUOTE_PATTERN.matcher(s);
// if (!lenient || !m.matches()) {
// sb.insert(0, "\"").append("\"");
// }
// return sb.toString();
// }
// }
| import net.querz.nbt.tag.Tag; | package net.querz.nbt.io;
public class NamedTag {
private String name; | // Path: src/main/java/net/querz/nbt/tag/Tag.java
// public abstract class Tag<T> implements Cloneable {
//
// /**
// * The default maximum depth of the NBT structure.
// * */
// public static final int DEFAULT_MAX_DEPTH = 512;
//
// private static final Map<String, String> ESCAPE_CHARACTERS;
// static {
// final Map<String, String> temp = new HashMap<>();
// temp.put("\\", "\\\\\\\\");
// temp.put("\n", "\\\\n");
// temp.put("\t", "\\\\t");
// temp.put("\r", "\\\\r");
// temp.put("\"", "\\\\\"");
// ESCAPE_CHARACTERS = Collections.unmodifiableMap(temp);
// }
//
// private static final Pattern ESCAPE_PATTERN = Pattern.compile("[\\\\\n\t\r\"]");
// private static final Pattern NON_QUOTE_PATTERN = Pattern.compile("[a-zA-Z0-9_\\-+]+");
//
// private T value;
//
// /**
// * Initializes this Tag with some value. If the value is {@code null}, it will
// * throw a {@code NullPointerException}
// * @param value The value to be set for this Tag.
// * */
// public Tag(T value) {
// setValue(value);
// }
//
// /**
// * @return This Tag's ID, usually used for serialization and deserialization.
// * */
// public abstract byte getID();
//
// /**
// * @return The value of this Tag.
// * */
// protected T getValue() {
// return value;
// }
//
// /**
// * Sets the value for this Tag directly.
// * @param value The value to be set.
// * @throws NullPointerException If the value is null
// * */
// protected void setValue(T value) {
// this.value = checkValue(value);
// }
//
// /**
// * Checks if the value {@code value} is {@code null}.
// * @param value The value to check
// * @throws NullPointerException If {@code value} was {@code null}
// * @return The parameter {@code value}
// * */
// protected T checkValue(T value) {
// return Objects.requireNonNull(value);
// }
//
// /**
// * Calls {@link Tag#toString(int)} with an initial depth of {@code 0}.
// * @see Tag#toString(int)
// * @throws MaxDepthReachedException If the maximum nesting depth is exceeded.
// * */
// @Override
// public final String toString() {
// return toString(DEFAULT_MAX_DEPTH);
// }
//
// /**
// * Creates a string representation of this Tag in a valid JSON format.
// * @param maxDepth The maximum nesting depth.
// * @return The string representation of this Tag.
// * @throws MaxDepthReachedException If the maximum nesting depth is exceeded.
// * */
// public String toString(int maxDepth) {
// return "{\"type\":\""+ getClass().getSimpleName() + "\"," +
// "\"value\":" + valueToString(maxDepth) + "}";
// }
//
// /**
// * Calls {@link Tag#valueToString(int)} with {@link Tag#DEFAULT_MAX_DEPTH}.
// * @return The string representation of the value of this Tag.
// * @throws MaxDepthReachedException If the maximum nesting depth is exceeded.
// * */
// public String valueToString() {
// return valueToString(DEFAULT_MAX_DEPTH);
// }
//
// /**
// * Returns a JSON representation of the value of this Tag.
// * @param maxDepth The maximum nesting depth.
// * @return The string representation of the value of this Tag.
// * @throws MaxDepthReachedException If the maximum nesting depth is exceeded.
// * */
// public abstract String valueToString(int maxDepth);
//
// /**
// * Returns whether this Tag and some other Tag are equal.
// * They are equal if {@code other} is not {@code null} and they are of the same class.
// * Custom Tag implementations should overwrite this but check the result
// * of this {@code super}-method while comparing.
// * @param other The Tag to compare to.
// * @return {@code true} if they are equal based on the conditions mentioned above.
// * */
// @Override
// public boolean equals(Object other) {
// return other != null && getClass() == other.getClass();
// }
//
// /**
// * Calculates the hash code of this Tag. Tags which are equal according to {@link Tag#equals(Object)}
// * must return an equal hash code.
// * @return The hash code of this Tag.
// * */
// @Override
// public int hashCode() {
// return value.hashCode();
// }
//
// /**
// * Creates a clone of this Tag.
// * @return A clone of this Tag.
// * */
// @SuppressWarnings("CloneDoesntDeclareCloneNotSupportedException")
// public abstract Tag<T> clone();
//
// /**
// * Escapes a string to fit into a JSON-like string representation for Minecraft
// * or to create the JSON string representation of a Tag returned from {@link Tag#toString()}
// * @param s The string to be escaped.
// * @param lenient {@code true} if it should force double quotes ({@code "}) at the start and
// * the end of the string.
// * @return The escaped string.
// * */
// protected static String escapeString(String s, boolean lenient) {
// StringBuffer sb = new StringBuffer();
// Matcher m = ESCAPE_PATTERN.matcher(s);
// while (m.find()) {
// m.appendReplacement(sb, ESCAPE_CHARACTERS.get(m.group()));
// }
// m.appendTail(sb);
// m = NON_QUOTE_PATTERN.matcher(s);
// if (!lenient || !m.matches()) {
// sb.insert(0, "\"").append("\"");
// }
// return sb.toString();
// }
// }
// Path: src/main/java/net/querz/nbt/io/NamedTag.java
import net.querz.nbt.tag.Tag;
package net.querz.nbt.io;
public class NamedTag {
private String name; | private Tag<?> tag; |
Querz/NBT | src/main/java/net/querz/nbt/io/NBTInput.java | // Path: src/main/java/net/querz/nbt/tag/Tag.java
// public abstract class Tag<T> implements Cloneable {
//
// /**
// * The default maximum depth of the NBT structure.
// * */
// public static final int DEFAULT_MAX_DEPTH = 512;
//
// private static final Map<String, String> ESCAPE_CHARACTERS;
// static {
// final Map<String, String> temp = new HashMap<>();
// temp.put("\\", "\\\\\\\\");
// temp.put("\n", "\\\\n");
// temp.put("\t", "\\\\t");
// temp.put("\r", "\\\\r");
// temp.put("\"", "\\\\\"");
// ESCAPE_CHARACTERS = Collections.unmodifiableMap(temp);
// }
//
// private static final Pattern ESCAPE_PATTERN = Pattern.compile("[\\\\\n\t\r\"]");
// private static final Pattern NON_QUOTE_PATTERN = Pattern.compile("[a-zA-Z0-9_\\-+]+");
//
// private T value;
//
// /**
// * Initializes this Tag with some value. If the value is {@code null}, it will
// * throw a {@code NullPointerException}
// * @param value The value to be set for this Tag.
// * */
// public Tag(T value) {
// setValue(value);
// }
//
// /**
// * @return This Tag's ID, usually used for serialization and deserialization.
// * */
// public abstract byte getID();
//
// /**
// * @return The value of this Tag.
// * */
// protected T getValue() {
// return value;
// }
//
// /**
// * Sets the value for this Tag directly.
// * @param value The value to be set.
// * @throws NullPointerException If the value is null
// * */
// protected void setValue(T value) {
// this.value = checkValue(value);
// }
//
// /**
// * Checks if the value {@code value} is {@code null}.
// * @param value The value to check
// * @throws NullPointerException If {@code value} was {@code null}
// * @return The parameter {@code value}
// * */
// protected T checkValue(T value) {
// return Objects.requireNonNull(value);
// }
//
// /**
// * Calls {@link Tag#toString(int)} with an initial depth of {@code 0}.
// * @see Tag#toString(int)
// * @throws MaxDepthReachedException If the maximum nesting depth is exceeded.
// * */
// @Override
// public final String toString() {
// return toString(DEFAULT_MAX_DEPTH);
// }
//
// /**
// * Creates a string representation of this Tag in a valid JSON format.
// * @param maxDepth The maximum nesting depth.
// * @return The string representation of this Tag.
// * @throws MaxDepthReachedException If the maximum nesting depth is exceeded.
// * */
// public String toString(int maxDepth) {
// return "{\"type\":\""+ getClass().getSimpleName() + "\"," +
// "\"value\":" + valueToString(maxDepth) + "}";
// }
//
// /**
// * Calls {@link Tag#valueToString(int)} with {@link Tag#DEFAULT_MAX_DEPTH}.
// * @return The string representation of the value of this Tag.
// * @throws MaxDepthReachedException If the maximum nesting depth is exceeded.
// * */
// public String valueToString() {
// return valueToString(DEFAULT_MAX_DEPTH);
// }
//
// /**
// * Returns a JSON representation of the value of this Tag.
// * @param maxDepth The maximum nesting depth.
// * @return The string representation of the value of this Tag.
// * @throws MaxDepthReachedException If the maximum nesting depth is exceeded.
// * */
// public abstract String valueToString(int maxDepth);
//
// /**
// * Returns whether this Tag and some other Tag are equal.
// * They are equal if {@code other} is not {@code null} and they are of the same class.
// * Custom Tag implementations should overwrite this but check the result
// * of this {@code super}-method while comparing.
// * @param other The Tag to compare to.
// * @return {@code true} if they are equal based on the conditions mentioned above.
// * */
// @Override
// public boolean equals(Object other) {
// return other != null && getClass() == other.getClass();
// }
//
// /**
// * Calculates the hash code of this Tag. Tags which are equal according to {@link Tag#equals(Object)}
// * must return an equal hash code.
// * @return The hash code of this Tag.
// * */
// @Override
// public int hashCode() {
// return value.hashCode();
// }
//
// /**
// * Creates a clone of this Tag.
// * @return A clone of this Tag.
// * */
// @SuppressWarnings("CloneDoesntDeclareCloneNotSupportedException")
// public abstract Tag<T> clone();
//
// /**
// * Escapes a string to fit into a JSON-like string representation for Minecraft
// * or to create the JSON string representation of a Tag returned from {@link Tag#toString()}
// * @param s The string to be escaped.
// * @param lenient {@code true} if it should force double quotes ({@code "}) at the start and
// * the end of the string.
// * @return The escaped string.
// * */
// protected static String escapeString(String s, boolean lenient) {
// StringBuffer sb = new StringBuffer();
// Matcher m = ESCAPE_PATTERN.matcher(s);
// while (m.find()) {
// m.appendReplacement(sb, ESCAPE_CHARACTERS.get(m.group()));
// }
// m.appendTail(sb);
// m = NON_QUOTE_PATTERN.matcher(s);
// if (!lenient || !m.matches()) {
// sb.insert(0, "\"").append("\"");
// }
// return sb.toString();
// }
// }
| import net.querz.nbt.tag.Tag;
import java.io.IOException; | package net.querz.nbt.io;
public interface NBTInput {
NamedTag readTag(int maxDepth) throws IOException;
| // Path: src/main/java/net/querz/nbt/tag/Tag.java
// public abstract class Tag<T> implements Cloneable {
//
// /**
// * The default maximum depth of the NBT structure.
// * */
// public static final int DEFAULT_MAX_DEPTH = 512;
//
// private static final Map<String, String> ESCAPE_CHARACTERS;
// static {
// final Map<String, String> temp = new HashMap<>();
// temp.put("\\", "\\\\\\\\");
// temp.put("\n", "\\\\n");
// temp.put("\t", "\\\\t");
// temp.put("\r", "\\\\r");
// temp.put("\"", "\\\\\"");
// ESCAPE_CHARACTERS = Collections.unmodifiableMap(temp);
// }
//
// private static final Pattern ESCAPE_PATTERN = Pattern.compile("[\\\\\n\t\r\"]");
// private static final Pattern NON_QUOTE_PATTERN = Pattern.compile("[a-zA-Z0-9_\\-+]+");
//
// private T value;
//
// /**
// * Initializes this Tag with some value. If the value is {@code null}, it will
// * throw a {@code NullPointerException}
// * @param value The value to be set for this Tag.
// * */
// public Tag(T value) {
// setValue(value);
// }
//
// /**
// * @return This Tag's ID, usually used for serialization and deserialization.
// * */
// public abstract byte getID();
//
// /**
// * @return The value of this Tag.
// * */
// protected T getValue() {
// return value;
// }
//
// /**
// * Sets the value for this Tag directly.
// * @param value The value to be set.
// * @throws NullPointerException If the value is null
// * */
// protected void setValue(T value) {
// this.value = checkValue(value);
// }
//
// /**
// * Checks if the value {@code value} is {@code null}.
// * @param value The value to check
// * @throws NullPointerException If {@code value} was {@code null}
// * @return The parameter {@code value}
// * */
// protected T checkValue(T value) {
// return Objects.requireNonNull(value);
// }
//
// /**
// * Calls {@link Tag#toString(int)} with an initial depth of {@code 0}.
// * @see Tag#toString(int)
// * @throws MaxDepthReachedException If the maximum nesting depth is exceeded.
// * */
// @Override
// public final String toString() {
// return toString(DEFAULT_MAX_DEPTH);
// }
//
// /**
// * Creates a string representation of this Tag in a valid JSON format.
// * @param maxDepth The maximum nesting depth.
// * @return The string representation of this Tag.
// * @throws MaxDepthReachedException If the maximum nesting depth is exceeded.
// * */
// public String toString(int maxDepth) {
// return "{\"type\":\""+ getClass().getSimpleName() + "\"," +
// "\"value\":" + valueToString(maxDepth) + "}";
// }
//
// /**
// * Calls {@link Tag#valueToString(int)} with {@link Tag#DEFAULT_MAX_DEPTH}.
// * @return The string representation of the value of this Tag.
// * @throws MaxDepthReachedException If the maximum nesting depth is exceeded.
// * */
// public String valueToString() {
// return valueToString(DEFAULT_MAX_DEPTH);
// }
//
// /**
// * Returns a JSON representation of the value of this Tag.
// * @param maxDepth The maximum nesting depth.
// * @return The string representation of the value of this Tag.
// * @throws MaxDepthReachedException If the maximum nesting depth is exceeded.
// * */
// public abstract String valueToString(int maxDepth);
//
// /**
// * Returns whether this Tag and some other Tag are equal.
// * They are equal if {@code other} is not {@code null} and they are of the same class.
// * Custom Tag implementations should overwrite this but check the result
// * of this {@code super}-method while comparing.
// * @param other The Tag to compare to.
// * @return {@code true} if they are equal based on the conditions mentioned above.
// * */
// @Override
// public boolean equals(Object other) {
// return other != null && getClass() == other.getClass();
// }
//
// /**
// * Calculates the hash code of this Tag. Tags which are equal according to {@link Tag#equals(Object)}
// * must return an equal hash code.
// * @return The hash code of this Tag.
// * */
// @Override
// public int hashCode() {
// return value.hashCode();
// }
//
// /**
// * Creates a clone of this Tag.
// * @return A clone of this Tag.
// * */
// @SuppressWarnings("CloneDoesntDeclareCloneNotSupportedException")
// public abstract Tag<T> clone();
//
// /**
// * Escapes a string to fit into a JSON-like string representation for Minecraft
// * or to create the JSON string representation of a Tag returned from {@link Tag#toString()}
// * @param s The string to be escaped.
// * @param lenient {@code true} if it should force double quotes ({@code "}) at the start and
// * the end of the string.
// * @return The escaped string.
// * */
// protected static String escapeString(String s, boolean lenient) {
// StringBuffer sb = new StringBuffer();
// Matcher m = ESCAPE_PATTERN.matcher(s);
// while (m.find()) {
// m.appendReplacement(sb, ESCAPE_CHARACTERS.get(m.group()));
// }
// m.appendTail(sb);
// m = NON_QUOTE_PATTERN.matcher(s);
// if (!lenient || !m.matches()) {
// sb.insert(0, "\"").append("\"");
// }
// return sb.toString();
// }
// }
// Path: src/main/java/net/querz/nbt/io/NBTInput.java
import net.querz.nbt.tag.Tag;
import java.io.IOException;
package net.querz.nbt.io;
public interface NBTInput {
NamedTag readTag(int maxDepth) throws IOException;
| Tag<?> readRawTag(int maxDepth) throws IOException; |
lacuna/bifurcan | src/io/lacuna/bifurcan/nodes/Util.java | // Path: src/io/lacuna/bifurcan/utils/Bits.java
// public static int bitOffset(long n) {
// return deBruijnIndex[0xFF & (int) ((n * 0x022fdd63cc95386dL) >>> 58)];
// }
//
// Path: src/io/lacuna/bifurcan/utils/Bits.java
// public static long highestBit(long n) {
// return Long.highestOneBit(n);
// }
//
// Path: src/io/lacuna/bifurcan/utils/Bits.java
// public static long lowestBit(long n) {
// return n & -n;
// }
| import java.util.NoSuchElementException;
import java.util.PrimitiveIterator;
import static io.lacuna.bifurcan.utils.Bits.bitOffset;
import static io.lacuna.bifurcan.utils.Bits.highestBit;
import static io.lacuna.bifurcan.utils.Bits.lowestBit;
import static java.lang.Integer.bitCount; | package io.lacuna.bifurcan.nodes;
/**
* @author ztellman
*/
public class Util {
static final Object DEFAULT_VALUE = new Object();
static final int NONE_NONE = 0;
static final int NODE_NONE = 0x1;
static final int ENTRY_NONE = 0x2;
static final int NONE_NODE = 0x4;
static final int NONE_ENTRY = 0x8;
static final int ENTRY_NODE = ENTRY_NONE | NONE_NODE;
static final int NODE_ENTRY = NODE_NONE | NONE_ENTRY;
static final int ENTRY_ENTRY = ENTRY_NONE | NONE_ENTRY;
static final int NODE_NODE = NODE_NONE | NONE_NODE;
public static int mergeState(int mask, int nodeA, int dataA, int nodeB, int dataB) {
int state = 0;
// this compiles down to no branches, apparently
state |= ((mask & nodeA) != 0 ? 1 : 0);
state |= ((mask & dataA) != 0 ? 1 : 0) << 1;
state |= ((mask & nodeB) != 0 ? 1 : 0) << 2;
state |= ((mask & dataB) != 0 ? 1 : 0) << 3;
return state;
}
static int compressedIndex(int bitmap, int hashMask) {
return bitCount(bitmap & (hashMask - 1));
}
public static int startIndex(int bitmap) { | // Path: src/io/lacuna/bifurcan/utils/Bits.java
// public static int bitOffset(long n) {
// return deBruijnIndex[0xFF & (int) ((n * 0x022fdd63cc95386dL) >>> 58)];
// }
//
// Path: src/io/lacuna/bifurcan/utils/Bits.java
// public static long highestBit(long n) {
// return Long.highestOneBit(n);
// }
//
// Path: src/io/lacuna/bifurcan/utils/Bits.java
// public static long lowestBit(long n) {
// return n & -n;
// }
// Path: src/io/lacuna/bifurcan/nodes/Util.java
import java.util.NoSuchElementException;
import java.util.PrimitiveIterator;
import static io.lacuna.bifurcan.utils.Bits.bitOffset;
import static io.lacuna.bifurcan.utils.Bits.highestBit;
import static io.lacuna.bifurcan.utils.Bits.lowestBit;
import static java.lang.Integer.bitCount;
package io.lacuna.bifurcan.nodes;
/**
* @author ztellman
*/
public class Util {
static final Object DEFAULT_VALUE = new Object();
static final int NONE_NONE = 0;
static final int NODE_NONE = 0x1;
static final int ENTRY_NONE = 0x2;
static final int NONE_NODE = 0x4;
static final int NONE_ENTRY = 0x8;
static final int ENTRY_NODE = ENTRY_NONE | NONE_NODE;
static final int NODE_ENTRY = NODE_NONE | NONE_ENTRY;
static final int ENTRY_ENTRY = ENTRY_NONE | NONE_ENTRY;
static final int NODE_NODE = NODE_NONE | NONE_NODE;
public static int mergeState(int mask, int nodeA, int dataA, int nodeB, int dataB) {
int state = 0;
// this compiles down to no branches, apparently
state |= ((mask & nodeA) != 0 ? 1 : 0);
state |= ((mask & dataA) != 0 ? 1 : 0) << 1;
state |= ((mask & nodeB) != 0 ? 1 : 0) << 2;
state |= ((mask & dataB) != 0 ? 1 : 0) << 3;
return state;
}
static int compressedIndex(int bitmap, int hashMask) {
return bitCount(bitmap & (hashMask - 1));
}
public static int startIndex(int bitmap) { | return bitOffset(lowestBit(bitmap & 0xFFFFFFFFL)); |
lacuna/bifurcan | src/io/lacuna/bifurcan/nodes/Util.java | // Path: src/io/lacuna/bifurcan/utils/Bits.java
// public static int bitOffset(long n) {
// return deBruijnIndex[0xFF & (int) ((n * 0x022fdd63cc95386dL) >>> 58)];
// }
//
// Path: src/io/lacuna/bifurcan/utils/Bits.java
// public static long highestBit(long n) {
// return Long.highestOneBit(n);
// }
//
// Path: src/io/lacuna/bifurcan/utils/Bits.java
// public static long lowestBit(long n) {
// return n & -n;
// }
| import java.util.NoSuchElementException;
import java.util.PrimitiveIterator;
import static io.lacuna.bifurcan.utils.Bits.bitOffset;
import static io.lacuna.bifurcan.utils.Bits.highestBit;
import static io.lacuna.bifurcan.utils.Bits.lowestBit;
import static java.lang.Integer.bitCount; | package io.lacuna.bifurcan.nodes;
/**
* @author ztellman
*/
public class Util {
static final Object DEFAULT_VALUE = new Object();
static final int NONE_NONE = 0;
static final int NODE_NONE = 0x1;
static final int ENTRY_NONE = 0x2;
static final int NONE_NODE = 0x4;
static final int NONE_ENTRY = 0x8;
static final int ENTRY_NODE = ENTRY_NONE | NONE_NODE;
static final int NODE_ENTRY = NODE_NONE | NONE_ENTRY;
static final int ENTRY_ENTRY = ENTRY_NONE | NONE_ENTRY;
static final int NODE_NODE = NODE_NONE | NONE_NODE;
public static int mergeState(int mask, int nodeA, int dataA, int nodeB, int dataB) {
int state = 0;
// this compiles down to no branches, apparently
state |= ((mask & nodeA) != 0 ? 1 : 0);
state |= ((mask & dataA) != 0 ? 1 : 0) << 1;
state |= ((mask & nodeB) != 0 ? 1 : 0) << 2;
state |= ((mask & dataB) != 0 ? 1 : 0) << 3;
return state;
}
static int compressedIndex(int bitmap, int hashMask) {
return bitCount(bitmap & (hashMask - 1));
}
public static int startIndex(int bitmap) { | // Path: src/io/lacuna/bifurcan/utils/Bits.java
// public static int bitOffset(long n) {
// return deBruijnIndex[0xFF & (int) ((n * 0x022fdd63cc95386dL) >>> 58)];
// }
//
// Path: src/io/lacuna/bifurcan/utils/Bits.java
// public static long highestBit(long n) {
// return Long.highestOneBit(n);
// }
//
// Path: src/io/lacuna/bifurcan/utils/Bits.java
// public static long lowestBit(long n) {
// return n & -n;
// }
// Path: src/io/lacuna/bifurcan/nodes/Util.java
import java.util.NoSuchElementException;
import java.util.PrimitiveIterator;
import static io.lacuna.bifurcan.utils.Bits.bitOffset;
import static io.lacuna.bifurcan.utils.Bits.highestBit;
import static io.lacuna.bifurcan.utils.Bits.lowestBit;
import static java.lang.Integer.bitCount;
package io.lacuna.bifurcan.nodes;
/**
* @author ztellman
*/
public class Util {
static final Object DEFAULT_VALUE = new Object();
static final int NONE_NONE = 0;
static final int NODE_NONE = 0x1;
static final int ENTRY_NONE = 0x2;
static final int NONE_NODE = 0x4;
static final int NONE_ENTRY = 0x8;
static final int ENTRY_NODE = ENTRY_NONE | NONE_NODE;
static final int NODE_ENTRY = NODE_NONE | NONE_ENTRY;
static final int ENTRY_ENTRY = ENTRY_NONE | NONE_ENTRY;
static final int NODE_NODE = NODE_NONE | NONE_NODE;
public static int mergeState(int mask, int nodeA, int dataA, int nodeB, int dataB) {
int state = 0;
// this compiles down to no branches, apparently
state |= ((mask & nodeA) != 0 ? 1 : 0);
state |= ((mask & dataA) != 0 ? 1 : 0) << 1;
state |= ((mask & nodeB) != 0 ? 1 : 0) << 2;
state |= ((mask & dataB) != 0 ? 1 : 0) << 3;
return state;
}
static int compressedIndex(int bitmap, int hashMask) {
return bitCount(bitmap & (hashMask - 1));
}
public static int startIndex(int bitmap) { | return bitOffset(lowestBit(bitmap & 0xFFFFFFFFL)); |
lacuna/bifurcan | src/io/lacuna/bifurcan/nodes/Util.java | // Path: src/io/lacuna/bifurcan/utils/Bits.java
// public static int bitOffset(long n) {
// return deBruijnIndex[0xFF & (int) ((n * 0x022fdd63cc95386dL) >>> 58)];
// }
//
// Path: src/io/lacuna/bifurcan/utils/Bits.java
// public static long highestBit(long n) {
// return Long.highestOneBit(n);
// }
//
// Path: src/io/lacuna/bifurcan/utils/Bits.java
// public static long lowestBit(long n) {
// return n & -n;
// }
| import java.util.NoSuchElementException;
import java.util.PrimitiveIterator;
import static io.lacuna.bifurcan.utils.Bits.bitOffset;
import static io.lacuna.bifurcan.utils.Bits.highestBit;
import static io.lacuna.bifurcan.utils.Bits.lowestBit;
import static java.lang.Integer.bitCount; | package io.lacuna.bifurcan.nodes;
/**
* @author ztellman
*/
public class Util {
static final Object DEFAULT_VALUE = new Object();
static final int NONE_NONE = 0;
static final int NODE_NONE = 0x1;
static final int ENTRY_NONE = 0x2;
static final int NONE_NODE = 0x4;
static final int NONE_ENTRY = 0x8;
static final int ENTRY_NODE = ENTRY_NONE | NONE_NODE;
static final int NODE_ENTRY = NODE_NONE | NONE_ENTRY;
static final int ENTRY_ENTRY = ENTRY_NONE | NONE_ENTRY;
static final int NODE_NODE = NODE_NONE | NONE_NODE;
public static int mergeState(int mask, int nodeA, int dataA, int nodeB, int dataB) {
int state = 0;
// this compiles down to no branches, apparently
state |= ((mask & nodeA) != 0 ? 1 : 0);
state |= ((mask & dataA) != 0 ? 1 : 0) << 1;
state |= ((mask & nodeB) != 0 ? 1 : 0) << 2;
state |= ((mask & dataB) != 0 ? 1 : 0) << 3;
return state;
}
static int compressedIndex(int bitmap, int hashMask) {
return bitCount(bitmap & (hashMask - 1));
}
public static int startIndex(int bitmap) {
return bitOffset(lowestBit(bitmap & 0xFFFFFFFFL));
}
public static int endIndex(int bitmap) { | // Path: src/io/lacuna/bifurcan/utils/Bits.java
// public static int bitOffset(long n) {
// return deBruijnIndex[0xFF & (int) ((n * 0x022fdd63cc95386dL) >>> 58)];
// }
//
// Path: src/io/lacuna/bifurcan/utils/Bits.java
// public static long highestBit(long n) {
// return Long.highestOneBit(n);
// }
//
// Path: src/io/lacuna/bifurcan/utils/Bits.java
// public static long lowestBit(long n) {
// return n & -n;
// }
// Path: src/io/lacuna/bifurcan/nodes/Util.java
import java.util.NoSuchElementException;
import java.util.PrimitiveIterator;
import static io.lacuna.bifurcan.utils.Bits.bitOffset;
import static io.lacuna.bifurcan.utils.Bits.highestBit;
import static io.lacuna.bifurcan.utils.Bits.lowestBit;
import static java.lang.Integer.bitCount;
package io.lacuna.bifurcan.nodes;
/**
* @author ztellman
*/
public class Util {
static final Object DEFAULT_VALUE = new Object();
static final int NONE_NONE = 0;
static final int NODE_NONE = 0x1;
static final int ENTRY_NONE = 0x2;
static final int NONE_NODE = 0x4;
static final int NONE_ENTRY = 0x8;
static final int ENTRY_NODE = ENTRY_NONE | NONE_NODE;
static final int NODE_ENTRY = NODE_NONE | NONE_ENTRY;
static final int ENTRY_ENTRY = ENTRY_NONE | NONE_ENTRY;
static final int NODE_NODE = NODE_NONE | NONE_NODE;
public static int mergeState(int mask, int nodeA, int dataA, int nodeB, int dataB) {
int state = 0;
// this compiles down to no branches, apparently
state |= ((mask & nodeA) != 0 ? 1 : 0);
state |= ((mask & dataA) != 0 ? 1 : 0) << 1;
state |= ((mask & nodeB) != 0 ? 1 : 0) << 2;
state |= ((mask & dataB) != 0 ? 1 : 0) << 3;
return state;
}
static int compressedIndex(int bitmap, int hashMask) {
return bitCount(bitmap & (hashMask - 1));
}
public static int startIndex(int bitmap) {
return bitOffset(lowestBit(bitmap & 0xFFFFFFFFL));
}
public static int endIndex(int bitmap) { | return bitOffset(highestBit(bitmap & 0xFFFFFFFFL)); |
lacuna/bifurcan | src/io/lacuna/bifurcan/DirectedGraph.java | // Path: src/io/lacuna/bifurcan/Graphs.java
// static final BinaryOperator MERGE_LAST_WRITE_WINS = (a, b) -> b;
| import java.util.function.*;
import static io.lacuna.bifurcan.Graphs.MERGE_LAST_WRITE_WINS; | m = new Map<>(out.keyHash(), out.keyEquality());
}
return m.put(to, edge, merge, editor);
}, editor);
outPrime = outPrime.update(to, m -> {
if (m == null) {
m = new Map<>(out.keyHash(), out.keyEquality());
}
return m;
}, editor);
Map<V, Set<V>> inPrime = in.update(to, s -> {
if (s == null) {
s = new Set<>(out.keyHash(), out.keyEquality());
}
return s.add(from, editor);
}, editor);
if (isLinear()) {
out = outPrime;
in = inPrime;
return this;
} else {
return new DirectedGraph<>(false, outPrime, inPrime);
}
}
@Override
public DirectedGraph<V, E> link(V from, V to, E edge) { | // Path: src/io/lacuna/bifurcan/Graphs.java
// static final BinaryOperator MERGE_LAST_WRITE_WINS = (a, b) -> b;
// Path: src/io/lacuna/bifurcan/DirectedGraph.java
import java.util.function.*;
import static io.lacuna.bifurcan.Graphs.MERGE_LAST_WRITE_WINS;
m = new Map<>(out.keyHash(), out.keyEquality());
}
return m.put(to, edge, merge, editor);
}, editor);
outPrime = outPrime.update(to, m -> {
if (m == null) {
m = new Map<>(out.keyHash(), out.keyEquality());
}
return m;
}, editor);
Map<V, Set<V>> inPrime = in.update(to, s -> {
if (s == null) {
s = new Set<>(out.keyHash(), out.keyEquality());
}
return s.add(from, editor);
}, editor);
if (isLinear()) {
out = outPrime;
in = inPrime;
return this;
} else {
return new DirectedGraph<>(false, outPrime, inPrime);
}
}
@Override
public DirectedGraph<V, E> link(V from, V to, E edge) { | return link(from, to, edge, (BinaryOperator<E>) MERGE_LAST_WRITE_WINS); |
lacuna/bifurcan | src/io/lacuna/bifurcan/durable/io/BufferedChannel.java | // Path: src/io/lacuna/bifurcan/durable/Bytes.java
// public class Bytes {
//
// public static String toHexTable(DurableInput in) {
// StringBuffer sb = new StringBuffer();
// ByteBuffer buf = ByteBuffer.allocate(16);
// while (in.remaining() > 0) {
// buf.clear();
// in.read(buf);
// buf.flip();
//
// for (int i = 0; i < 16; i++) {
// if (i == 8) {
// sb.append(" ");
// }
//
// if (buf.hasRemaining()) {
// sb.append(String.format("%02X", buf.get())).append(" ");
// } else {
// sb.append(" ");
// }
// }
// sb.append("\n");
// }
// return sb.toString();
// }
//
// public static String toHexString(ByteBuffer buf) {
// StringBuffer sb = new StringBuffer();
// buf = buf.duplicate();
// while (buf.hasRemaining()) {
// sb.append(Integer.toHexString(buf.get() & 0xFF));
// }
// return sb.toString();
// }
//
// public static int compareBuffers(ByteBuffer a, ByteBuffer b) {
// a = a.duplicate();
// b = b.duplicate();
//
// while (a.hasRemaining() && b.hasRemaining()) {
// int d = (a.get() & 0xFF) - (b.get() & 0xFF);
// if (d != 0) {
// return d;
// }
// }
//
// if (a.hasRemaining()) {
// return 1;
// } else if (b.hasRemaining()) {
// return -1;
// } else {
// return 0;
// }
// }
//
// public static int compareInputs(DurableInput a, DurableInput b) {
// a = a.duplicate();
// b = b.duplicate();
//
// while (a.hasRemaining() && b.hasRemaining()) {
// int d = a.readUnsignedByte() - b.readUnsignedByte();
// if (d != 0) {
// return d;
// }
// }
//
// if (a.hasRemaining()) {
// return 1;
// } else if (b.hasRemaining()) {
// return -1;
// } else {
// return 0;
// }
// }
//
// public static ByteBuffer slice(ByteBuffer b, long start, long end) {
// return ((ByteBuffer) b.duplicate()
// .position((int) start)
// .limit((int) end))
// .slice()
// .order(ByteOrder.BIG_ENDIAN);
// }
//
// public static ByteBuffer allocate(int n) {
// return ByteBuffer.allocateDirect(n).order(ByteOrder.BIG_ENDIAN);
// }
//
// public static ByteBuffer duplicate(ByteBuffer b) {
// return b.duplicate().order(ByteOrder.BIG_ENDIAN);
// }
//
// public static int transfer(ByteBuffer src, ByteBuffer dst) {
// int n;
// if (dst.remaining() < src.remaining()) {
// n = dst.remaining();
// dst.put((ByteBuffer) src.duplicate().limit(src.position() + n));
// src.position(src.position() + n);
// } else {
// n = src.remaining();
// dst.put(src);
// }
//
// return n;
// }
// }
| import io.lacuna.bifurcan.durable.Bytes;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
import java.nio.channels.WritableByteChannel;
import java.nio.file.Path;
import java.util.concurrent.atomic.AtomicLong; | package io.lacuna.bifurcan.durable.io;
/**
* @author ztellman
*/
public class BufferedChannel {
public static final AtomicLong PAGES_READ = new AtomicLong();
private static final int PAGE_SIZE = 4 << 10;
private static final int READ_AHEAD = 256;
public final Path path;
private final FileChannel channel;
private long size;
// TODO: create thread-local-ish map of thread-id -> buffer
private final ByteBuffer buffer;
private long bufferOffset;
private long threadId = Thread.currentThread().getId();
public BufferedChannel(Path path, FileChannel channel) {
this.path = path;
this.channel = channel; | // Path: src/io/lacuna/bifurcan/durable/Bytes.java
// public class Bytes {
//
// public static String toHexTable(DurableInput in) {
// StringBuffer sb = new StringBuffer();
// ByteBuffer buf = ByteBuffer.allocate(16);
// while (in.remaining() > 0) {
// buf.clear();
// in.read(buf);
// buf.flip();
//
// for (int i = 0; i < 16; i++) {
// if (i == 8) {
// sb.append(" ");
// }
//
// if (buf.hasRemaining()) {
// sb.append(String.format("%02X", buf.get())).append(" ");
// } else {
// sb.append(" ");
// }
// }
// sb.append("\n");
// }
// return sb.toString();
// }
//
// public static String toHexString(ByteBuffer buf) {
// StringBuffer sb = new StringBuffer();
// buf = buf.duplicate();
// while (buf.hasRemaining()) {
// sb.append(Integer.toHexString(buf.get() & 0xFF));
// }
// return sb.toString();
// }
//
// public static int compareBuffers(ByteBuffer a, ByteBuffer b) {
// a = a.duplicate();
// b = b.duplicate();
//
// while (a.hasRemaining() && b.hasRemaining()) {
// int d = (a.get() & 0xFF) - (b.get() & 0xFF);
// if (d != 0) {
// return d;
// }
// }
//
// if (a.hasRemaining()) {
// return 1;
// } else if (b.hasRemaining()) {
// return -1;
// } else {
// return 0;
// }
// }
//
// public static int compareInputs(DurableInput a, DurableInput b) {
// a = a.duplicate();
// b = b.duplicate();
//
// while (a.hasRemaining() && b.hasRemaining()) {
// int d = a.readUnsignedByte() - b.readUnsignedByte();
// if (d != 0) {
// return d;
// }
// }
//
// if (a.hasRemaining()) {
// return 1;
// } else if (b.hasRemaining()) {
// return -1;
// } else {
// return 0;
// }
// }
//
// public static ByteBuffer slice(ByteBuffer b, long start, long end) {
// return ((ByteBuffer) b.duplicate()
// .position((int) start)
// .limit((int) end))
// .slice()
// .order(ByteOrder.BIG_ENDIAN);
// }
//
// public static ByteBuffer allocate(int n) {
// return ByteBuffer.allocateDirect(n).order(ByteOrder.BIG_ENDIAN);
// }
//
// public static ByteBuffer duplicate(ByteBuffer b) {
// return b.duplicate().order(ByteOrder.BIG_ENDIAN);
// }
//
// public static int transfer(ByteBuffer src, ByteBuffer dst) {
// int n;
// if (dst.remaining() < src.remaining()) {
// n = dst.remaining();
// dst.put((ByteBuffer) src.duplicate().limit(src.position() + n));
// src.position(src.position() + n);
// } else {
// n = src.remaining();
// dst.put(src);
// }
//
// return n;
// }
// }
// Path: src/io/lacuna/bifurcan/durable/io/BufferedChannel.java
import io.lacuna.bifurcan.durable.Bytes;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
import java.nio.channels.WritableByteChannel;
import java.nio.file.Path;
import java.util.concurrent.atomic.AtomicLong;
package io.lacuna.bifurcan.durable.io;
/**
* @author ztellman
*/
public class BufferedChannel {
public static final AtomicLong PAGES_READ = new AtomicLong();
private static final int PAGE_SIZE = 4 << 10;
private static final int READ_AHEAD = 256;
public final Path path;
private final FileChannel channel;
private long size;
// TODO: create thread-local-ish map of thread-id -> buffer
private final ByteBuffer buffer;
private long bufferOffset;
private long threadId = Thread.currentThread().getId();
public BufferedChannel(Path path, FileChannel channel) {
this.path = path;
this.channel = channel; | this.buffer = Bytes.allocate(PAGE_SIZE * 2); |
lacuna/bifurcan | src/io/lacuna/bifurcan/utils/BitVector.java | // Path: src/io/lacuna/bifurcan/utils/Bits.java
// public static int branchingBit(long a, long b) {
// if (a == b) {
// return -1;
// } else {
// return bitOffset(highestBit(a ^ b));
// }
// }
//
// Path: src/io/lacuna/bifurcan/utils/Bits.java
// public static long maskAbove(int bits) {
// return -1L & ~maskBelow(bits);
// }
//
// Path: src/io/lacuna/bifurcan/utils/Bits.java
// public static long maskBelow(int bits) {
// return (1L << bits) - 1;
// }
| import static io.lacuna.bifurcan.utils.Bits.branchingBit;
import static io.lacuna.bifurcan.utils.Bits.maskAbove;
import static io.lacuna.bifurcan.utils.Bits.maskBelow; | package io.lacuna.bifurcan.utils;
/**
* Static methods which implement bit-range operations over a bit-vector stored within a long[].
*
* @author ztellman
*/
public final class BitVector {
/**
* @param length the bit length of the vector
* @return a bit vector which can hold the specified number of bits
*/
public static long[] create(int length) {
return new long[(Math.max(0, length - 1) >> 6) + 1];
}
public static long[] clone(long[] vector) {
long[] nVector = new long[vector.length];
System.arraycopy(vector, 0, nVector, 0, vector.length);
return nVector;
}
/**
* @param vector the bit vector
* @param bitIndex the bit to be tested
* @return true if the bit is 1, false otherwise
*/
public static boolean test(long[] vector, int bitIndex) {
return (vector[bitIndex >> 6] & (1L << (bitIndex & 63))) != 0;
}
/**
* @param bitLen the number of significant bits in each vector
* @param vectors a list of bit-vectors
* @return the bit-wise interleaving of the values, starting with the topmost bit of the 0th vector, followed by the
* topmost bit of the 1st vector, and downward from there
*/
public static long[] interleave(int bitLen, long[] vectors) {
long[] interleaved = create(bitLen * vectors.length);
int offset = (interleaved.length << 6) - 1;
for (int i = 0; i < bitLen; i++) {
long mask = 1L << i;
for (int j = vectors.length - 1; j >= 0; j--) {
long val = (vectors[j] & mask) >>> i;
interleaved[offset >> 6] |= val << (63 - (offset & 63));
offset--;
}
}
return interleaved;
}
| // Path: src/io/lacuna/bifurcan/utils/Bits.java
// public static int branchingBit(long a, long b) {
// if (a == b) {
// return -1;
// } else {
// return bitOffset(highestBit(a ^ b));
// }
// }
//
// Path: src/io/lacuna/bifurcan/utils/Bits.java
// public static long maskAbove(int bits) {
// return -1L & ~maskBelow(bits);
// }
//
// Path: src/io/lacuna/bifurcan/utils/Bits.java
// public static long maskBelow(int bits) {
// return (1L << bits) - 1;
// }
// Path: src/io/lacuna/bifurcan/utils/BitVector.java
import static io.lacuna.bifurcan.utils.Bits.branchingBit;
import static io.lacuna.bifurcan.utils.Bits.maskAbove;
import static io.lacuna.bifurcan.utils.Bits.maskBelow;
package io.lacuna.bifurcan.utils;
/**
* Static methods which implement bit-range operations over a bit-vector stored within a long[].
*
* @author ztellman
*/
public final class BitVector {
/**
* @param length the bit length of the vector
* @return a bit vector which can hold the specified number of bits
*/
public static long[] create(int length) {
return new long[(Math.max(0, length - 1) >> 6) + 1];
}
public static long[] clone(long[] vector) {
long[] nVector = new long[vector.length];
System.arraycopy(vector, 0, nVector, 0, vector.length);
return nVector;
}
/**
* @param vector the bit vector
* @param bitIndex the bit to be tested
* @return true if the bit is 1, false otherwise
*/
public static boolean test(long[] vector, int bitIndex) {
return (vector[bitIndex >> 6] & (1L << (bitIndex & 63))) != 0;
}
/**
* @param bitLen the number of significant bits in each vector
* @param vectors a list of bit-vectors
* @return the bit-wise interleaving of the values, starting with the topmost bit of the 0th vector, followed by the
* topmost bit of the 1st vector, and downward from there
*/
public static long[] interleave(int bitLen, long[] vectors) {
long[] interleaved = create(bitLen * vectors.length);
int offset = (interleaved.length << 6) - 1;
for (int i = 0; i < bitLen; i++) {
long mask = 1L << i;
for (int j = vectors.length - 1; j >= 0; j--) {
long val = (vectors[j] & mask) >>> i;
interleaved[offset >> 6] |= val << (63 - (offset & 63));
offset--;
}
}
return interleaved;
}
| public static int branchingBit(long[] a, long[] b, int aIdx, int bIdx, int bitOffset, int bitLen) { |
lacuna/bifurcan | src/io/lacuna/bifurcan/utils/BitVector.java | // Path: src/io/lacuna/bifurcan/utils/Bits.java
// public static int branchingBit(long a, long b) {
// if (a == b) {
// return -1;
// } else {
// return bitOffset(highestBit(a ^ b));
// }
// }
//
// Path: src/io/lacuna/bifurcan/utils/Bits.java
// public static long maskAbove(int bits) {
// return -1L & ~maskBelow(bits);
// }
//
// Path: src/io/lacuna/bifurcan/utils/Bits.java
// public static long maskBelow(int bits) {
// return (1L << bits) - 1;
// }
| import static io.lacuna.bifurcan.utils.Bits.branchingBit;
import static io.lacuna.bifurcan.utils.Bits.maskAbove;
import static io.lacuna.bifurcan.utils.Bits.maskBelow; | package io.lacuna.bifurcan.utils;
/**
* Static methods which implement bit-range operations over a bit-vector stored within a long[].
*
* @author ztellman
*/
public final class BitVector {
/**
* @param length the bit length of the vector
* @return a bit vector which can hold the specified number of bits
*/
public static long[] create(int length) {
return new long[(Math.max(0, length - 1) >> 6) + 1];
}
public static long[] clone(long[] vector) {
long[] nVector = new long[vector.length];
System.arraycopy(vector, 0, nVector, 0, vector.length);
return nVector;
}
/**
* @param vector the bit vector
* @param bitIndex the bit to be tested
* @return true if the bit is 1, false otherwise
*/
public static boolean test(long[] vector, int bitIndex) {
return (vector[bitIndex >> 6] & (1L << (bitIndex & 63))) != 0;
}
/**
* @param bitLen the number of significant bits in each vector
* @param vectors a list of bit-vectors
* @return the bit-wise interleaving of the values, starting with the topmost bit of the 0th vector, followed by the
* topmost bit of the 1st vector, and downward from there
*/
public static long[] interleave(int bitLen, long[] vectors) {
long[] interleaved = create(bitLen * vectors.length);
int offset = (interleaved.length << 6) - 1;
for (int i = 0; i < bitLen; i++) {
long mask = 1L << i;
for (int j = vectors.length - 1; j >= 0; j--) {
long val = (vectors[j] & mask) >>> i;
interleaved[offset >> 6] |= val << (63 - (offset & 63));
offset--;
}
}
return interleaved;
}
public static int branchingBit(long[] a, long[] b, int aIdx, int bIdx, int bitOffset, int bitLen) { | // Path: src/io/lacuna/bifurcan/utils/Bits.java
// public static int branchingBit(long a, long b) {
// if (a == b) {
// return -1;
// } else {
// return bitOffset(highestBit(a ^ b));
// }
// }
//
// Path: src/io/lacuna/bifurcan/utils/Bits.java
// public static long maskAbove(int bits) {
// return -1L & ~maskBelow(bits);
// }
//
// Path: src/io/lacuna/bifurcan/utils/Bits.java
// public static long maskBelow(int bits) {
// return (1L << bits) - 1;
// }
// Path: src/io/lacuna/bifurcan/utils/BitVector.java
import static io.lacuna.bifurcan.utils.Bits.branchingBit;
import static io.lacuna.bifurcan.utils.Bits.maskAbove;
import static io.lacuna.bifurcan.utils.Bits.maskBelow;
package io.lacuna.bifurcan.utils;
/**
* Static methods which implement bit-range operations over a bit-vector stored within a long[].
*
* @author ztellman
*/
public final class BitVector {
/**
* @param length the bit length of the vector
* @return a bit vector which can hold the specified number of bits
*/
public static long[] create(int length) {
return new long[(Math.max(0, length - 1) >> 6) + 1];
}
public static long[] clone(long[] vector) {
long[] nVector = new long[vector.length];
System.arraycopy(vector, 0, nVector, 0, vector.length);
return nVector;
}
/**
* @param vector the bit vector
* @param bitIndex the bit to be tested
* @return true if the bit is 1, false otherwise
*/
public static boolean test(long[] vector, int bitIndex) {
return (vector[bitIndex >> 6] & (1L << (bitIndex & 63))) != 0;
}
/**
* @param bitLen the number of significant bits in each vector
* @param vectors a list of bit-vectors
* @return the bit-wise interleaving of the values, starting with the topmost bit of the 0th vector, followed by the
* topmost bit of the 1st vector, and downward from there
*/
public static long[] interleave(int bitLen, long[] vectors) {
long[] interleaved = create(bitLen * vectors.length);
int offset = (interleaved.length << 6) - 1;
for (int i = 0; i < bitLen; i++) {
long mask = 1L << i;
for (int j = vectors.length - 1; j >= 0; j--) {
long val = (vectors[j] & mask) >>> i;
interleaved[offset >> 6] |= val << (63 - (offset & 63));
offset--;
}
}
return interleaved;
}
public static int branchingBit(long[] a, long[] b, int aIdx, int bIdx, int bitOffset, int bitLen) { | long mask = maskAbove(bitOffset & 63); |
lacuna/bifurcan | src/io/lacuna/bifurcan/utils/BitVector.java | // Path: src/io/lacuna/bifurcan/utils/Bits.java
// public static int branchingBit(long a, long b) {
// if (a == b) {
// return -1;
// } else {
// return bitOffset(highestBit(a ^ b));
// }
// }
//
// Path: src/io/lacuna/bifurcan/utils/Bits.java
// public static long maskAbove(int bits) {
// return -1L & ~maskBelow(bits);
// }
//
// Path: src/io/lacuna/bifurcan/utils/Bits.java
// public static long maskBelow(int bits) {
// return (1L << bits) - 1;
// }
| import static io.lacuna.bifurcan.utils.Bits.branchingBit;
import static io.lacuna.bifurcan.utils.Bits.maskAbove;
import static io.lacuna.bifurcan.utils.Bits.maskBelow; | bIdx++;
int branchIdx = 64 - bitOffset;
int len = ((bitLen - (bitOffset + 1)) >> 6) + 1;
for (int i = 0; i < len; i++) {
branch = Bits.branchingBit(a[aIdx + i], b[bIdx + 1]);
if (branch >= 0) {
return branchIdx + branch;
} else {
branchIdx += 64;
}
}
return branchIdx > bitLen ? -1 : branchIdx;
}
/**
* Reads a bit range from the vector, which cannot be longer than 64 bits.
*
* @param vector the bit vector
* @param offset the bit offset
* @param len the bit length
* @return a number representing the bit range
*/
public static long get(long[] vector, int offset, int len) {
int idx = offset >> 6;
int bitIdx = offset & 63;
int truncatedLen = Math.min(len, 64 - bitIdx); | // Path: src/io/lacuna/bifurcan/utils/Bits.java
// public static int branchingBit(long a, long b) {
// if (a == b) {
// return -1;
// } else {
// return bitOffset(highestBit(a ^ b));
// }
// }
//
// Path: src/io/lacuna/bifurcan/utils/Bits.java
// public static long maskAbove(int bits) {
// return -1L & ~maskBelow(bits);
// }
//
// Path: src/io/lacuna/bifurcan/utils/Bits.java
// public static long maskBelow(int bits) {
// return (1L << bits) - 1;
// }
// Path: src/io/lacuna/bifurcan/utils/BitVector.java
import static io.lacuna.bifurcan.utils.Bits.branchingBit;
import static io.lacuna.bifurcan.utils.Bits.maskAbove;
import static io.lacuna.bifurcan.utils.Bits.maskBelow;
bIdx++;
int branchIdx = 64 - bitOffset;
int len = ((bitLen - (bitOffset + 1)) >> 6) + 1;
for (int i = 0; i < len; i++) {
branch = Bits.branchingBit(a[aIdx + i], b[bIdx + 1]);
if (branch >= 0) {
return branchIdx + branch;
} else {
branchIdx += 64;
}
}
return branchIdx > bitLen ? -1 : branchIdx;
}
/**
* Reads a bit range from the vector, which cannot be longer than 64 bits.
*
* @param vector the bit vector
* @param offset the bit offset
* @param len the bit length
* @return a number representing the bit range
*/
public static long get(long[] vector, int offset, int len) {
int idx = offset >> 6;
int bitIdx = offset & 63;
int truncatedLen = Math.min(len, 64 - bitIdx); | long val = (vector[idx] >>> bitIdx) & maskBelow(truncatedLen); |
lacuna/bifurcan | src/io/lacuna/bifurcan/nodes/ListNodes.java | // Path: src/io/lacuna/bifurcan/utils/Bits.java
// public class Bits {
//
// private static final byte deBruijnIndex[] =
// new byte[]{0, 1, 2, 53, 3, 7, 54, 27, 4, 38, 41, 8, 34, 55, 48, 28,
// 62, 5, 39, 46, 44, 42, 22, 9, 24, 35, 59, 56, 49, 18, 29, 11,
// 63, 52, 6, 26, 37, 40, 33, 47, 61, 45, 43, 21, 23, 58, 17, 10,
// 51, 25, 36, 32, 60, 20, 57, 16, 50, 31, 19, 15, 30, 14, 13, 12};
//
// /**
// * @param n a number, which must be a power of two
// * @return the offset of the bit
// */
// public static int bitOffset(long n) {
// return deBruijnIndex[0xFF & (int) ((n * 0x022fdd63cc95386dL) >>> 58)];
// }
//
// /**
// * @param n a number
// * @return the same number, with all but the lowest bit zeroed out
// */
// public static long lowestBit(long n) {
// return n & -n;
// }
//
// /**
// * @param n a number
// * @return the same number, with all but the lowest bit zeroed out
// */
// public static int lowestBit(int n) {
// return n & -n;
// }
//
// /**
// * @param n a number
// * @return the same number, with all but the highest bit zeroed out
// */
// public static long highestBit(long n) {
// return Long.highestOneBit(n);
// }
//
// /**
// * @param n a number
// * @return the same number, with all but the highest bit zeroed out
// */
// public static int highestBit(int n) {
// return Integer.highestOneBit(n);
// }
//
// /**
// * @param n a number
// * @return the log2 of that value, rounded down
// */
// public static int log2Floor(long n) {
// return bitOffset(highestBit(n));
// }
//
// /**
// * @param n a number
// * @return the log2 of the value, rounded up
// */
// public static int log2Ceil(long n) {
// int log2 = log2Floor(n);
// return isPowerOfTwo(n) ? log2 : log2 + 1;
// }
//
// /**
// * @param n a number
// * @param offset the offset of the bit being tested
// * @return true if the bit is 1, false otherwise
// */
// public static boolean test(int n, int offset) {
// return (n & (1 << offset)) != 0;
// }
//
// /**
// * @param n a number
// * @param offset the offset of the bit being tested
// * @return true if the bit is 1, false otherwise
// */
// public static boolean test(long n, int offset) {
// return (n & (1L << offset)) != 0;
// }
//
// /**
// * @param bits a bit offset
// * @return a mask, with all bits below that offset set to one
// */
// public static long maskBelow(int bits) {
// return (1L << bits) - 1;
// }
//
// /**
// * @param bits a bit offset
// * @return a mask, with all bits above that offset set to one
// */
// public static long maskAbove(int bits) {
// return -1L & ~maskBelow(bits);
// }
//
// /**
// * @return the offset of the highest bit which differs between {@code a} and {@code b}
// */
// public static int branchingBit(long a, long b) {
// if (a == b) {
// return -1;
// } else {
// return bitOffset(highestBit(a ^ b));
// }
// }
//
// /**
// * @param n a number
// * @return true, if the number is a power of two
// */
// public static boolean isPowerOfTwo(long n) {
// return (n & (n - 1)) == 0;
// }
//
// public static long slice(long n, int start, int end) {
// return (n >> start) & maskBelow(end - start);
// }
// }
| import io.lacuna.bifurcan.utils.Bits;
import static java.lang.System.arraycopy; |
Node n = this;
while (n.shift > SHIFT_INCREMENT) {
n = (Node) n.nodes[n.numNodes - 1];
}
return (Object[]) n.nodes[n.numNodes - 1];
}
public Object nth(long idx, boolean returnChunk) {
if (!isStrict) {
return relaxedNth(idx, returnChunk);
}
Node n = this;
while (n.shift > SHIFT_INCREMENT) {
int nodeIdx = (int) ((idx >>> n.shift) & BRANCH_MASK);
n = (Node) n.nodes[nodeIdx];
if (!n.isStrict) {
return n.relaxedNth(idx, returnChunk);
}
}
Object[] chunk = (Object[]) n.nodes[(int) ((idx >>> SHIFT_INCREMENT) & BRANCH_MASK)];
return returnChunk ? chunk : chunk[(int) (idx & BRANCH_MASK)];
}
private Object relaxedNth(long idx, boolean returnChunk) {
// moved inside here to make nth() more inline-able | // Path: src/io/lacuna/bifurcan/utils/Bits.java
// public class Bits {
//
// private static final byte deBruijnIndex[] =
// new byte[]{0, 1, 2, 53, 3, 7, 54, 27, 4, 38, 41, 8, 34, 55, 48, 28,
// 62, 5, 39, 46, 44, 42, 22, 9, 24, 35, 59, 56, 49, 18, 29, 11,
// 63, 52, 6, 26, 37, 40, 33, 47, 61, 45, 43, 21, 23, 58, 17, 10,
// 51, 25, 36, 32, 60, 20, 57, 16, 50, 31, 19, 15, 30, 14, 13, 12};
//
// /**
// * @param n a number, which must be a power of two
// * @return the offset of the bit
// */
// public static int bitOffset(long n) {
// return deBruijnIndex[0xFF & (int) ((n * 0x022fdd63cc95386dL) >>> 58)];
// }
//
// /**
// * @param n a number
// * @return the same number, with all but the lowest bit zeroed out
// */
// public static long lowestBit(long n) {
// return n & -n;
// }
//
// /**
// * @param n a number
// * @return the same number, with all but the lowest bit zeroed out
// */
// public static int lowestBit(int n) {
// return n & -n;
// }
//
// /**
// * @param n a number
// * @return the same number, with all but the highest bit zeroed out
// */
// public static long highestBit(long n) {
// return Long.highestOneBit(n);
// }
//
// /**
// * @param n a number
// * @return the same number, with all but the highest bit zeroed out
// */
// public static int highestBit(int n) {
// return Integer.highestOneBit(n);
// }
//
// /**
// * @param n a number
// * @return the log2 of that value, rounded down
// */
// public static int log2Floor(long n) {
// return bitOffset(highestBit(n));
// }
//
// /**
// * @param n a number
// * @return the log2 of the value, rounded up
// */
// public static int log2Ceil(long n) {
// int log2 = log2Floor(n);
// return isPowerOfTwo(n) ? log2 : log2 + 1;
// }
//
// /**
// * @param n a number
// * @param offset the offset of the bit being tested
// * @return true if the bit is 1, false otherwise
// */
// public static boolean test(int n, int offset) {
// return (n & (1 << offset)) != 0;
// }
//
// /**
// * @param n a number
// * @param offset the offset of the bit being tested
// * @return true if the bit is 1, false otherwise
// */
// public static boolean test(long n, int offset) {
// return (n & (1L << offset)) != 0;
// }
//
// /**
// * @param bits a bit offset
// * @return a mask, with all bits below that offset set to one
// */
// public static long maskBelow(int bits) {
// return (1L << bits) - 1;
// }
//
// /**
// * @param bits a bit offset
// * @return a mask, with all bits above that offset set to one
// */
// public static long maskAbove(int bits) {
// return -1L & ~maskBelow(bits);
// }
//
// /**
// * @return the offset of the highest bit which differs between {@code a} and {@code b}
// */
// public static int branchingBit(long a, long b) {
// if (a == b) {
// return -1;
// } else {
// return bitOffset(highestBit(a ^ b));
// }
// }
//
// /**
// * @param n a number
// * @return true, if the number is a power of two
// */
// public static boolean isPowerOfTwo(long n) {
// return (n & (n - 1)) == 0;
// }
//
// public static long slice(long n, int start, int end) {
// return (n >> start) & maskBelow(end - start);
// }
// }
// Path: src/io/lacuna/bifurcan/nodes/ListNodes.java
import io.lacuna.bifurcan.utils.Bits;
import static java.lang.System.arraycopy;
Node n = this;
while (n.shift > SHIFT_INCREMENT) {
n = (Node) n.nodes[n.numNodes - 1];
}
return (Object[]) n.nodes[n.numNodes - 1];
}
public Object nth(long idx, boolean returnChunk) {
if (!isStrict) {
return relaxedNth(idx, returnChunk);
}
Node n = this;
while (n.shift > SHIFT_INCREMENT) {
int nodeIdx = (int) ((idx >>> n.shift) & BRANCH_MASK);
n = (Node) n.nodes[nodeIdx];
if (!n.isStrict) {
return n.relaxedNth(idx, returnChunk);
}
}
Object[] chunk = (Object[]) n.nodes[(int) ((idx >>> SHIFT_INCREMENT) & BRANCH_MASK)];
return returnChunk ? chunk : chunk[(int) (idx & BRANCH_MASK)];
}
private Object relaxedNth(long idx, boolean returnChunk) {
// moved inside here to make nth() more inline-able | idx = idx & Bits.maskBelow(shift + SHIFT_INCREMENT); |
lacuna/bifurcan | src/io/lacuna/bifurcan/DirectedAcyclicGraph.java | // Path: src/io/lacuna/bifurcan/Graphs.java
// static final BinaryOperator MERGE_LAST_WRITE_WINS = (a, b) -> b;
| import java.util.Iterator;
import java.util.function.*;
import static io.lacuna.bifurcan.Graphs.MERGE_LAST_WRITE_WINS; | graph.vertices().stream().filter(v -> graph.in(v).size() == 0).forEach(top::add);
graph.vertices().stream().filter(v -> graph.out(v).size() == 0).forEach(bottom::add);
return new DirectedAcyclicGraph<>(graph, top.forked(), bottom.forked());
}
public Set<V> top() {
return top;
}
public Set<V> bottom() {
return bottom;
}
public DirectedGraph<V, E> directedGraph() {
return graph.clone();
}
@Override
public DirectedAcyclicGraph<V, E> add(IEdge<V, E> edge) {
return link(edge.from(), edge.to(), edge.value());
}
@Override
public DirectedAcyclicGraph<V, E> remove(IEdge<V, E> edge) {
return unlink(edge.from(), edge.to());
}
@Override
public DirectedAcyclicGraph<V, E> link(V from, V to, E edge) { | // Path: src/io/lacuna/bifurcan/Graphs.java
// static final BinaryOperator MERGE_LAST_WRITE_WINS = (a, b) -> b;
// Path: src/io/lacuna/bifurcan/DirectedAcyclicGraph.java
import java.util.Iterator;
import java.util.function.*;
import static io.lacuna.bifurcan.Graphs.MERGE_LAST_WRITE_WINS;
graph.vertices().stream().filter(v -> graph.in(v).size() == 0).forEach(top::add);
graph.vertices().stream().filter(v -> graph.out(v).size() == 0).forEach(bottom::add);
return new DirectedAcyclicGraph<>(graph, top.forked(), bottom.forked());
}
public Set<V> top() {
return top;
}
public Set<V> bottom() {
return bottom;
}
public DirectedGraph<V, E> directedGraph() {
return graph.clone();
}
@Override
public DirectedAcyclicGraph<V, E> add(IEdge<V, E> edge) {
return link(edge.from(), edge.to(), edge.value());
}
@Override
public DirectedAcyclicGraph<V, E> remove(IEdge<V, E> edge) {
return unlink(edge.from(), edge.to());
}
@Override
public DirectedAcyclicGraph<V, E> link(V from, V to, E edge) { | return link(from, to, edge, (BinaryOperator<E>) MERGE_LAST_WRITE_WINS); |
lacuna/bifurcan | src/io/lacuna/bifurcan/diffs/Slice.java | // Path: src/io/lacuna/bifurcan/ISortedSet.java
// enum Bound {
// INCLUSIVE,
// EXCLUSIVE
// }
| import io.lacuna.bifurcan.*;
import io.lacuna.bifurcan.ISortedSet.Bound; | package io.lacuna.bifurcan.diffs;
public class Slice {
public static class SortedMap<K, V> extends ISortedMap.Mixin<K, V> implements IDiffSortedMap<K, V> {
private static final IntSet OFFSETS = new IntSet().add(0L);
private final K min, max; | // Path: src/io/lacuna/bifurcan/ISortedSet.java
// enum Bound {
// INCLUSIVE,
// EXCLUSIVE
// }
// Path: src/io/lacuna/bifurcan/diffs/Slice.java
import io.lacuna.bifurcan.*;
import io.lacuna.bifurcan.ISortedSet.Bound;
package io.lacuna.bifurcan.diffs;
public class Slice {
public static class SortedMap<K, V> extends ISortedMap.Mixin<K, V> implements IDiffSortedMap<K, V> {
private static final IntSet OFFSETS = new IntSet().add(0L);
private final K min, max; | private final Bound minBound, maxBound; |
lacuna/bifurcan | src/io/lacuna/bifurcan/durable/Roots.java | // Path: src/io/lacuna/bifurcan/IDurableCollection.java
// interface Fingerprint extends Comparable<Fingerprint> {
// String ALGORITHM = "SHA-512";
// int HASH_BYTES = 32;
//
// byte[] binary();
//
// default String toHexString() {
// return Bytes.toHexString(ByteBuffer.wrap(binary()));
// }
//
// default int compareTo(Fingerprint o) {
// return Bytes.compareBuffers(
// ByteBuffer.wrap(binary()),
// ByteBuffer.wrap(o.binary())
// );
// }
// }
//
// Path: src/io/lacuna/bifurcan/IDurableCollection.java
// interface Root {
// void close();
//
// Path path();
//
// DurableInput.Pool bytes();
//
// Fingerprint fingerprint();
//
// DurableInput cached(DurableInput in);
//
// IMap<Fingerprint, Fingerprint> redirects();
//
// ISet<Fingerprint> dependencies();
//
// default DirectedAcyclicGraph<Fingerprint, Void> dependencyGraph() {
// Function<Root, Iterable<Root>> deps = r -> () -> r.dependencies().stream().map(r::open).iterator();
// DirectedAcyclicGraph<Fingerprint, Void> result = new DirectedAcyclicGraph<Fingerprint, Void>().linear();
// for (Root r : Graphs.bfsVertices(this, deps)) {
// deps.apply(r).forEach(d -> result.link(r.fingerprint(), d.fingerprint()));
// }
// return result.forked();
// }
//
// Root open(Fingerprint dependency);
//
// default <T extends IDurableCollection> T decode(IDurableEncoding encoding) {
// return (T) decodeCollection(encoding, this, bytes());
// }
// }
//
// Path: src/io/lacuna/bifurcan/utils/Functions.java
// public class Functions {
//
// private static class MemoizedFunction<U, V> implements Function<U, V> {
//
// private final LinearMap<U, V> cache = new LinearMap<>();
// private final Function<U, V> f;
//
// MemoizedFunction(Function<U, V> f) {
// this.f = f;
// }
//
// @Override
// public V apply(U u) {
// return cache.getOrCreate(u, () -> f.apply(u));
// }
// }
//
// public static <U, V> Function<U, V> memoize(Function<U, V> f) {
// if (f instanceof MemoizedFunction) {
// return f;
// } else {
// return new MemoizedFunction<>(f);
// }
// }
// }
| import io.lacuna.bifurcan.*;
import io.lacuna.bifurcan.IDurableCollection.Fingerprint;
import io.lacuna.bifurcan.IDurableCollection.Root;
import io.lacuna.bifurcan.durable.io.*;
import io.lacuna.bifurcan.utils.Functions;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
import java.nio.file.Path;
import java.nio.file.StandardOpenOption;
import java.util.Objects;
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Function; | package io.lacuna.bifurcan.durable;
public class Roots {
private static class Lookup { | // Path: src/io/lacuna/bifurcan/IDurableCollection.java
// interface Fingerprint extends Comparable<Fingerprint> {
// String ALGORITHM = "SHA-512";
// int HASH_BYTES = 32;
//
// byte[] binary();
//
// default String toHexString() {
// return Bytes.toHexString(ByteBuffer.wrap(binary()));
// }
//
// default int compareTo(Fingerprint o) {
// return Bytes.compareBuffers(
// ByteBuffer.wrap(binary()),
// ByteBuffer.wrap(o.binary())
// );
// }
// }
//
// Path: src/io/lacuna/bifurcan/IDurableCollection.java
// interface Root {
// void close();
//
// Path path();
//
// DurableInput.Pool bytes();
//
// Fingerprint fingerprint();
//
// DurableInput cached(DurableInput in);
//
// IMap<Fingerprint, Fingerprint> redirects();
//
// ISet<Fingerprint> dependencies();
//
// default DirectedAcyclicGraph<Fingerprint, Void> dependencyGraph() {
// Function<Root, Iterable<Root>> deps = r -> () -> r.dependencies().stream().map(r::open).iterator();
// DirectedAcyclicGraph<Fingerprint, Void> result = new DirectedAcyclicGraph<Fingerprint, Void>().linear();
// for (Root r : Graphs.bfsVertices(this, deps)) {
// deps.apply(r).forEach(d -> result.link(r.fingerprint(), d.fingerprint()));
// }
// return result.forked();
// }
//
// Root open(Fingerprint dependency);
//
// default <T extends IDurableCollection> T decode(IDurableEncoding encoding) {
// return (T) decodeCollection(encoding, this, bytes());
// }
// }
//
// Path: src/io/lacuna/bifurcan/utils/Functions.java
// public class Functions {
//
// private static class MemoizedFunction<U, V> implements Function<U, V> {
//
// private final LinearMap<U, V> cache = new LinearMap<>();
// private final Function<U, V> f;
//
// MemoizedFunction(Function<U, V> f) {
// this.f = f;
// }
//
// @Override
// public V apply(U u) {
// return cache.getOrCreate(u, () -> f.apply(u));
// }
// }
//
// public static <U, V> Function<U, V> memoize(Function<U, V> f) {
// if (f instanceof MemoizedFunction) {
// return f;
// } else {
// return new MemoizedFunction<>(f);
// }
// }
// }
// Path: src/io/lacuna/bifurcan/durable/Roots.java
import io.lacuna.bifurcan.*;
import io.lacuna.bifurcan.IDurableCollection.Fingerprint;
import io.lacuna.bifurcan.IDurableCollection.Root;
import io.lacuna.bifurcan.durable.io.*;
import io.lacuna.bifurcan.utils.Functions;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
import java.nio.file.Path;
import java.nio.file.StandardOpenOption;
import java.util.Objects;
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Function;
package io.lacuna.bifurcan.durable;
public class Roots {
private static class Lookup { | public final Fingerprint fingerprint; |
lacuna/bifurcan | src/io/lacuna/bifurcan/durable/Roots.java | // Path: src/io/lacuna/bifurcan/IDurableCollection.java
// interface Fingerprint extends Comparable<Fingerprint> {
// String ALGORITHM = "SHA-512";
// int HASH_BYTES = 32;
//
// byte[] binary();
//
// default String toHexString() {
// return Bytes.toHexString(ByteBuffer.wrap(binary()));
// }
//
// default int compareTo(Fingerprint o) {
// return Bytes.compareBuffers(
// ByteBuffer.wrap(binary()),
// ByteBuffer.wrap(o.binary())
// );
// }
// }
//
// Path: src/io/lacuna/bifurcan/IDurableCollection.java
// interface Root {
// void close();
//
// Path path();
//
// DurableInput.Pool bytes();
//
// Fingerprint fingerprint();
//
// DurableInput cached(DurableInput in);
//
// IMap<Fingerprint, Fingerprint> redirects();
//
// ISet<Fingerprint> dependencies();
//
// default DirectedAcyclicGraph<Fingerprint, Void> dependencyGraph() {
// Function<Root, Iterable<Root>> deps = r -> () -> r.dependencies().stream().map(r::open).iterator();
// DirectedAcyclicGraph<Fingerprint, Void> result = new DirectedAcyclicGraph<Fingerprint, Void>().linear();
// for (Root r : Graphs.bfsVertices(this, deps)) {
// deps.apply(r).forEach(d -> result.link(r.fingerprint(), d.fingerprint()));
// }
// return result.forked();
// }
//
// Root open(Fingerprint dependency);
//
// default <T extends IDurableCollection> T decode(IDurableEncoding encoding) {
// return (T) decodeCollection(encoding, this, bytes());
// }
// }
//
// Path: src/io/lacuna/bifurcan/utils/Functions.java
// public class Functions {
//
// private static class MemoizedFunction<U, V> implements Function<U, V> {
//
// private final LinearMap<U, V> cache = new LinearMap<>();
// private final Function<U, V> f;
//
// MemoizedFunction(Function<U, V> f) {
// this.f = f;
// }
//
// @Override
// public V apply(U u) {
// return cache.getOrCreate(u, () -> f.apply(u));
// }
// }
//
// public static <U, V> Function<U, V> memoize(Function<U, V> f) {
// if (f instanceof MemoizedFunction) {
// return f;
// } else {
// return new MemoizedFunction<>(f);
// }
// }
// }
| import io.lacuna.bifurcan.*;
import io.lacuna.bifurcan.IDurableCollection.Fingerprint;
import io.lacuna.bifurcan.IDurableCollection.Root;
import io.lacuna.bifurcan.durable.io.*;
import io.lacuna.bifurcan.utils.Functions;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
import java.nio.file.Path;
import java.nio.file.StandardOpenOption;
import java.util.Objects;
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Function; | if (obj instanceof Lookup) {
Lookup l = (Lookup) obj;
return l.fingerprint.equals(fingerprint) && l.redirects.equals(redirects);
}
return false;
}
}
private static DurableInput map(FileChannel file, long offset, long size) throws IOException {
return new BufferInput(file.map(FileChannel.MapMode.READ_ONLY, offset, size));
}
private static DurableInput map(FileChannel file) throws IOException {
long size = file.size();
LinearList<DurableInput> bufs = new LinearList<>();
long offset = 0;
while (offset < size) {
long len = Math.min(Integer.MAX_VALUE, size - offset);
bufs.addLast(map(file, offset, len));
offset += len;
}
return DurableInput.from(bufs);
}
public static DurableInput cachedInput(DurableInput in) {
ByteBuffer bytes = Bytes.allocate((int) in.size());
in.duplicate().read(bytes);
return new BufferInput((ByteBuffer) bytes.flip());
}
| // Path: src/io/lacuna/bifurcan/IDurableCollection.java
// interface Fingerprint extends Comparable<Fingerprint> {
// String ALGORITHM = "SHA-512";
// int HASH_BYTES = 32;
//
// byte[] binary();
//
// default String toHexString() {
// return Bytes.toHexString(ByteBuffer.wrap(binary()));
// }
//
// default int compareTo(Fingerprint o) {
// return Bytes.compareBuffers(
// ByteBuffer.wrap(binary()),
// ByteBuffer.wrap(o.binary())
// );
// }
// }
//
// Path: src/io/lacuna/bifurcan/IDurableCollection.java
// interface Root {
// void close();
//
// Path path();
//
// DurableInput.Pool bytes();
//
// Fingerprint fingerprint();
//
// DurableInput cached(DurableInput in);
//
// IMap<Fingerprint, Fingerprint> redirects();
//
// ISet<Fingerprint> dependencies();
//
// default DirectedAcyclicGraph<Fingerprint, Void> dependencyGraph() {
// Function<Root, Iterable<Root>> deps = r -> () -> r.dependencies().stream().map(r::open).iterator();
// DirectedAcyclicGraph<Fingerprint, Void> result = new DirectedAcyclicGraph<Fingerprint, Void>().linear();
// for (Root r : Graphs.bfsVertices(this, deps)) {
// deps.apply(r).forEach(d -> result.link(r.fingerprint(), d.fingerprint()));
// }
// return result.forked();
// }
//
// Root open(Fingerprint dependency);
//
// default <T extends IDurableCollection> T decode(IDurableEncoding encoding) {
// return (T) decodeCollection(encoding, this, bytes());
// }
// }
//
// Path: src/io/lacuna/bifurcan/utils/Functions.java
// public class Functions {
//
// private static class MemoizedFunction<U, V> implements Function<U, V> {
//
// private final LinearMap<U, V> cache = new LinearMap<>();
// private final Function<U, V> f;
//
// MemoizedFunction(Function<U, V> f) {
// this.f = f;
// }
//
// @Override
// public V apply(U u) {
// return cache.getOrCreate(u, () -> f.apply(u));
// }
// }
//
// public static <U, V> Function<U, V> memoize(Function<U, V> f) {
// if (f instanceof MemoizedFunction) {
// return f;
// } else {
// return new MemoizedFunction<>(f);
// }
// }
// }
// Path: src/io/lacuna/bifurcan/durable/Roots.java
import io.lacuna.bifurcan.*;
import io.lacuna.bifurcan.IDurableCollection.Fingerprint;
import io.lacuna.bifurcan.IDurableCollection.Root;
import io.lacuna.bifurcan.durable.io.*;
import io.lacuna.bifurcan.utils.Functions;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
import java.nio.file.Path;
import java.nio.file.StandardOpenOption;
import java.util.Objects;
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Function;
if (obj instanceof Lookup) {
Lookup l = (Lookup) obj;
return l.fingerprint.equals(fingerprint) && l.redirects.equals(redirects);
}
return false;
}
}
private static DurableInput map(FileChannel file, long offset, long size) throws IOException {
return new BufferInput(file.map(FileChannel.MapMode.READ_ONLY, offset, size));
}
private static DurableInput map(FileChannel file) throws IOException {
long size = file.size();
LinearList<DurableInput> bufs = new LinearList<>();
long offset = 0;
while (offset < size) {
long len = Math.min(Integer.MAX_VALUE, size - offset);
bufs.addLast(map(file, offset, len));
offset += len;
}
return DurableInput.from(bufs);
}
public static DurableInput cachedInput(DurableInput in) {
ByteBuffer bytes = Bytes.allocate((int) in.size());
in.duplicate().read(bytes);
return new BufferInput((ByteBuffer) bytes.flip());
}
| public static Root open(Path directory, Fingerprint fingerprint) { |
lacuna/bifurcan | src/io/lacuna/bifurcan/durable/Roots.java | // Path: src/io/lacuna/bifurcan/IDurableCollection.java
// interface Fingerprint extends Comparable<Fingerprint> {
// String ALGORITHM = "SHA-512";
// int HASH_BYTES = 32;
//
// byte[] binary();
//
// default String toHexString() {
// return Bytes.toHexString(ByteBuffer.wrap(binary()));
// }
//
// default int compareTo(Fingerprint o) {
// return Bytes.compareBuffers(
// ByteBuffer.wrap(binary()),
// ByteBuffer.wrap(o.binary())
// );
// }
// }
//
// Path: src/io/lacuna/bifurcan/IDurableCollection.java
// interface Root {
// void close();
//
// Path path();
//
// DurableInput.Pool bytes();
//
// Fingerprint fingerprint();
//
// DurableInput cached(DurableInput in);
//
// IMap<Fingerprint, Fingerprint> redirects();
//
// ISet<Fingerprint> dependencies();
//
// default DirectedAcyclicGraph<Fingerprint, Void> dependencyGraph() {
// Function<Root, Iterable<Root>> deps = r -> () -> r.dependencies().stream().map(r::open).iterator();
// DirectedAcyclicGraph<Fingerprint, Void> result = new DirectedAcyclicGraph<Fingerprint, Void>().linear();
// for (Root r : Graphs.bfsVertices(this, deps)) {
// deps.apply(r).forEach(d -> result.link(r.fingerprint(), d.fingerprint()));
// }
// return result.forked();
// }
//
// Root open(Fingerprint dependency);
//
// default <T extends IDurableCollection> T decode(IDurableEncoding encoding) {
// return (T) decodeCollection(encoding, this, bytes());
// }
// }
//
// Path: src/io/lacuna/bifurcan/utils/Functions.java
// public class Functions {
//
// private static class MemoizedFunction<U, V> implements Function<U, V> {
//
// private final LinearMap<U, V> cache = new LinearMap<>();
// private final Function<U, V> f;
//
// MemoizedFunction(Function<U, V> f) {
// this.f = f;
// }
//
// @Override
// public V apply(U u) {
// return cache.getOrCreate(u, () -> f.apply(u));
// }
// }
//
// public static <U, V> Function<U, V> memoize(Function<U, V> f) {
// if (f instanceof MemoizedFunction) {
// return f;
// } else {
// return new MemoizedFunction<>(f);
// }
// }
// }
| import io.lacuna.bifurcan.*;
import io.lacuna.bifurcan.IDurableCollection.Fingerprint;
import io.lacuna.bifurcan.IDurableCollection.Root;
import io.lacuna.bifurcan.durable.io.*;
import io.lacuna.bifurcan.utils.Functions;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
import java.nio.file.Path;
import java.nio.file.StandardOpenOption;
import java.util.Objects;
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Function; | }
private static DurableInput map(FileChannel file, long offset, long size) throws IOException {
return new BufferInput(file.map(FileChannel.MapMode.READ_ONLY, offset, size));
}
private static DurableInput map(FileChannel file) throws IOException {
long size = file.size();
LinearList<DurableInput> bufs = new LinearList<>();
long offset = 0;
while (offset < size) {
long len = Math.min(Integer.MAX_VALUE, size - offset);
bufs.addLast(map(file, offset, len));
offset += len;
}
return DurableInput.from(bufs);
}
public static DurableInput cachedInput(DurableInput in) {
ByteBuffer bytes = Bytes.allocate((int) in.size());
in.duplicate().read(bytes);
return new BufferInput((ByteBuffer) bytes.flip());
}
public static Root open(Path directory, Fingerprint fingerprint) {
return open(directory.resolve(fingerprint.toHexString() + ".bfn"));
}
public static Root open(Path path) {
AtomicReference<Function<Lookup, Root>> fn = new AtomicReference<>(); | // Path: src/io/lacuna/bifurcan/IDurableCollection.java
// interface Fingerprint extends Comparable<Fingerprint> {
// String ALGORITHM = "SHA-512";
// int HASH_BYTES = 32;
//
// byte[] binary();
//
// default String toHexString() {
// return Bytes.toHexString(ByteBuffer.wrap(binary()));
// }
//
// default int compareTo(Fingerprint o) {
// return Bytes.compareBuffers(
// ByteBuffer.wrap(binary()),
// ByteBuffer.wrap(o.binary())
// );
// }
// }
//
// Path: src/io/lacuna/bifurcan/IDurableCollection.java
// interface Root {
// void close();
//
// Path path();
//
// DurableInput.Pool bytes();
//
// Fingerprint fingerprint();
//
// DurableInput cached(DurableInput in);
//
// IMap<Fingerprint, Fingerprint> redirects();
//
// ISet<Fingerprint> dependencies();
//
// default DirectedAcyclicGraph<Fingerprint, Void> dependencyGraph() {
// Function<Root, Iterable<Root>> deps = r -> () -> r.dependencies().stream().map(r::open).iterator();
// DirectedAcyclicGraph<Fingerprint, Void> result = new DirectedAcyclicGraph<Fingerprint, Void>().linear();
// for (Root r : Graphs.bfsVertices(this, deps)) {
// deps.apply(r).forEach(d -> result.link(r.fingerprint(), d.fingerprint()));
// }
// return result.forked();
// }
//
// Root open(Fingerprint dependency);
//
// default <T extends IDurableCollection> T decode(IDurableEncoding encoding) {
// return (T) decodeCollection(encoding, this, bytes());
// }
// }
//
// Path: src/io/lacuna/bifurcan/utils/Functions.java
// public class Functions {
//
// private static class MemoizedFunction<U, V> implements Function<U, V> {
//
// private final LinearMap<U, V> cache = new LinearMap<>();
// private final Function<U, V> f;
//
// MemoizedFunction(Function<U, V> f) {
// this.f = f;
// }
//
// @Override
// public V apply(U u) {
// return cache.getOrCreate(u, () -> f.apply(u));
// }
// }
//
// public static <U, V> Function<U, V> memoize(Function<U, V> f) {
// if (f instanceof MemoizedFunction) {
// return f;
// } else {
// return new MemoizedFunction<>(f);
// }
// }
// }
// Path: src/io/lacuna/bifurcan/durable/Roots.java
import io.lacuna.bifurcan.*;
import io.lacuna.bifurcan.IDurableCollection.Fingerprint;
import io.lacuna.bifurcan.IDurableCollection.Root;
import io.lacuna.bifurcan.durable.io.*;
import io.lacuna.bifurcan.utils.Functions;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
import java.nio.file.Path;
import java.nio.file.StandardOpenOption;
import java.util.Objects;
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Function;
}
private static DurableInput map(FileChannel file, long offset, long size) throws IOException {
return new BufferInput(file.map(FileChannel.MapMode.READ_ONLY, offset, size));
}
private static DurableInput map(FileChannel file) throws IOException {
long size = file.size();
LinearList<DurableInput> bufs = new LinearList<>();
long offset = 0;
while (offset < size) {
long len = Math.min(Integer.MAX_VALUE, size - offset);
bufs.addLast(map(file, offset, len));
offset += len;
}
return DurableInput.from(bufs);
}
public static DurableInput cachedInput(DurableInput in) {
ByteBuffer bytes = Bytes.allocate((int) in.size());
in.duplicate().read(bytes);
return new BufferInput((ByteBuffer) bytes.flip());
}
public static Root open(Path directory, Fingerprint fingerprint) {
return open(directory.resolve(fingerprint.toHexString() + ".bfn"));
}
public static Root open(Path path) {
AtomicReference<Function<Lookup, Root>> fn = new AtomicReference<>(); | fn.set(Functions.memoize(l -> open( |
lacuna/bifurcan | src/io/lacuna/bifurcan/FloatMap.java | // Path: src/io/lacuna/bifurcan/utils/Encodings.java
// public class Encodings {
//
// private static long NEGATIVE_ZERO = Double.doubleToLongBits(-0.0);
//
// /**
// * Converts a double into a corresponding long that shares the same ordering semantics.
// */
// public static long doubleToLong(double value) {
// long v = Double.doubleToRawLongBits(value);
// if (v == NEGATIVE_ZERO) {
// return 0;
// }
//
// if (value < -0.0) {
// v ^= Long.MAX_VALUE;
// }
// return v;
// }
//
// /**
// * The inverse operation for {@link #doubleToLong(double)}.
// */
// public static double longToDouble(long value) {
// if (value < -0.0) {
// value ^= Long.MAX_VALUE;
// }
// return Double.longBitsToDouble(value);
// }
// }
//
// Path: src/io/lacuna/bifurcan/utils/Encodings.java
// public static long doubleToLong(double value) {
// long v = Double.doubleToRawLongBits(value);
// if (v == NEGATIVE_ZERO) {
// return 0;
// }
//
// if (value < -0.0) {
// v ^= Long.MAX_VALUE;
// }
// return v;
// }
//
// Path: src/io/lacuna/bifurcan/utils/Encodings.java
// public static double longToDouble(long value) {
// if (value < -0.0) {
// value ^= Long.MAX_VALUE;
// }
// return Double.longBitsToDouble(value);
// }
| import io.lacuna.bifurcan.utils.Encodings;
import java.util.*;
import java.util.function.*;
import static io.lacuna.bifurcan.utils.Encodings.doubleToLong;
import static io.lacuna.bifurcan.utils.Encodings.longToDouble; | @Override
public FloatMap<V> put(Double key, V value, BinaryOperator<V> merge) {
return put((double) key, value, merge);
}
/**
* @return an updated map that does not contain {@code key}
*/
public FloatMap<V> remove(double key) {
return remove(key, isLinear() ? map.editor : new Object());
}
public FloatMap<V> remove(double key, Object editor) {
IntMap<V> mapPrime = map.remove(doubleToLong(key), editor);
if (isLinear()) {
map = mapPrime;
return this;
} else {
return new FloatMap<>(mapPrime);
}
}
@Override
public FloatMap<V> remove(Double key) {
return remove((double) key);
}
@Override
public <U> FloatMap<U> mapValues(BiFunction<Double, V, U> f) { | // Path: src/io/lacuna/bifurcan/utils/Encodings.java
// public class Encodings {
//
// private static long NEGATIVE_ZERO = Double.doubleToLongBits(-0.0);
//
// /**
// * Converts a double into a corresponding long that shares the same ordering semantics.
// */
// public static long doubleToLong(double value) {
// long v = Double.doubleToRawLongBits(value);
// if (v == NEGATIVE_ZERO) {
// return 0;
// }
//
// if (value < -0.0) {
// v ^= Long.MAX_VALUE;
// }
// return v;
// }
//
// /**
// * The inverse operation for {@link #doubleToLong(double)}.
// */
// public static double longToDouble(long value) {
// if (value < -0.0) {
// value ^= Long.MAX_VALUE;
// }
// return Double.longBitsToDouble(value);
// }
// }
//
// Path: src/io/lacuna/bifurcan/utils/Encodings.java
// public static long doubleToLong(double value) {
// long v = Double.doubleToRawLongBits(value);
// if (v == NEGATIVE_ZERO) {
// return 0;
// }
//
// if (value < -0.0) {
// v ^= Long.MAX_VALUE;
// }
// return v;
// }
//
// Path: src/io/lacuna/bifurcan/utils/Encodings.java
// public static double longToDouble(long value) {
// if (value < -0.0) {
// value ^= Long.MAX_VALUE;
// }
// return Double.longBitsToDouble(value);
// }
// Path: src/io/lacuna/bifurcan/FloatMap.java
import io.lacuna.bifurcan.utils.Encodings;
import java.util.*;
import java.util.function.*;
import static io.lacuna.bifurcan.utils.Encodings.doubleToLong;
import static io.lacuna.bifurcan.utils.Encodings.longToDouble;
@Override
public FloatMap<V> put(Double key, V value, BinaryOperator<V> merge) {
return put((double) key, value, merge);
}
/**
* @return an updated map that does not contain {@code key}
*/
public FloatMap<V> remove(double key) {
return remove(key, isLinear() ? map.editor : new Object());
}
public FloatMap<V> remove(double key, Object editor) {
IntMap<V> mapPrime = map.remove(doubleToLong(key), editor);
if (isLinear()) {
map = mapPrime;
return this;
} else {
return new FloatMap<>(mapPrime);
}
}
@Override
public FloatMap<V> remove(Double key) {
return remove((double) key);
}
@Override
public <U> FloatMap<U> mapValues(BiFunction<Double, V, U> f) { | return new FloatMap<>(map.mapValues((k, v) -> f.apply(longToDouble(k), v))); |
lacuna/bifurcan | src/io/lacuna/bifurcan/Ropes.java | // Path: src/io/lacuna/bifurcan/hash/PerlHash.java
// public class PerlHash {
//
// public static int hash(ByteBuffer buf) {
// return hash(0, buf);
// }
//
// public static int hash(int seed, ByteBuffer buf) {
// return hash(seed, buf, buf.position(), buf.remaining());
// }
//
// public static int hash(int seed, DurableInput in) {
// int key = seed;
//
// while (in.hasRemaining()) {
// key += in.readUnsignedByte();
// key += key << 10;
// key ^= key >>> 6;
// }
//
// return finalize(key);
// }
//
// public static int hash(int seed, PrimitiveIterator.OfInt values) {
// int key = seed;
//
// while (values.hasNext()) {
// key += values.nextInt();
// key += key << 10;
// key ^= key >>> 6;
// }
//
// return finalize(key);
// }
//
// public static int hash(int seed, ByteBuffer buf, int offset, int len) {
// int key = seed;
//
// int limit = offset + len;
// for (int i = offset; i < limit; i++) {
// key += buf.get(i) & 0xFF;
// key += key << 10;
// key ^= key >>> 6;
// }
//
// return finalize(key);
// }
//
// public static int hash(int seed, Iterator<ByteBuffer> buffers) {
// int key = seed;
//
// while (buffers.hasNext()) {
// ByteBuffer buf = buffers.next();
// for (int i = buf.position(); i < buf.limit(); i++) {
// key += buf.get(i) & 0xFF;
// key += key << 10;
// key ^= key >>> 6;
// }
// }
//
// return finalize(key);
// }
//
// private static int finalize(int key) {
// key += key << 3;
// key ^= key >>> 11;
// key += key << 15;
// return key;
// }
// }
| import io.lacuna.bifurcan.hash.PerlHash;
import java.nio.ByteBuffer;
import java.util.Iterator; | package io.lacuna.bifurcan;
/**
* @author ztellman
*/
public class Ropes {
private Ropes() {
}
/**
* lexicographically compares two UTF-8 binary streams by code points, assumes both are of equal length
*/
static int compare(Iterator<ByteBuffer> a, Iterator<ByteBuffer> b) {
ByteBuffer x = a.next();
ByteBuffer y = b.next();
for (; ; ) {
int len = Math.min(x.remaining(), y.remaining());
for (int k = 0; k < len; k++) {
byte bx = x.get();
byte by = y.get();
if (bx != by) {
return (bx & 0xFF) - (by & 0xFF);
}
}
if (!x.hasRemaining()) {
if (!a.hasNext()) {
break;
}
x = a.next();
}
if (!y.hasRemaining()) {
y = b.next();
}
}
return 0;
}
public static int hash(Rope r) { | // Path: src/io/lacuna/bifurcan/hash/PerlHash.java
// public class PerlHash {
//
// public static int hash(ByteBuffer buf) {
// return hash(0, buf);
// }
//
// public static int hash(int seed, ByteBuffer buf) {
// return hash(seed, buf, buf.position(), buf.remaining());
// }
//
// public static int hash(int seed, DurableInput in) {
// int key = seed;
//
// while (in.hasRemaining()) {
// key += in.readUnsignedByte();
// key += key << 10;
// key ^= key >>> 6;
// }
//
// return finalize(key);
// }
//
// public static int hash(int seed, PrimitiveIterator.OfInt values) {
// int key = seed;
//
// while (values.hasNext()) {
// key += values.nextInt();
// key += key << 10;
// key ^= key >>> 6;
// }
//
// return finalize(key);
// }
//
// public static int hash(int seed, ByteBuffer buf, int offset, int len) {
// int key = seed;
//
// int limit = offset + len;
// for (int i = offset; i < limit; i++) {
// key += buf.get(i) & 0xFF;
// key += key << 10;
// key ^= key >>> 6;
// }
//
// return finalize(key);
// }
//
// public static int hash(int seed, Iterator<ByteBuffer> buffers) {
// int key = seed;
//
// while (buffers.hasNext()) {
// ByteBuffer buf = buffers.next();
// for (int i = buf.position(); i < buf.limit(); i++) {
// key += buf.get(i) & 0xFF;
// key += key << 10;
// key ^= key >>> 6;
// }
// }
//
// return finalize(key);
// }
//
// private static int finalize(int key) {
// key += key << 3;
// key ^= key >>> 11;
// key += key << 15;
// return key;
// }
// }
// Path: src/io/lacuna/bifurcan/Ropes.java
import io.lacuna.bifurcan.hash.PerlHash;
import java.nio.ByteBuffer;
import java.util.Iterator;
package io.lacuna.bifurcan;
/**
* @author ztellman
*/
public class Ropes {
private Ropes() {
}
/**
* lexicographically compares two UTF-8 binary streams by code points, assumes both are of equal length
*/
static int compare(Iterator<ByteBuffer> a, Iterator<ByteBuffer> b) {
ByteBuffer x = a.next();
ByteBuffer y = b.next();
for (; ; ) {
int len = Math.min(x.remaining(), y.remaining());
for (int k = 0; k < len; k++) {
byte bx = x.get();
byte by = y.get();
if (bx != by) {
return (bx & 0xFF) - (by & 0xFF);
}
}
if (!x.hasRemaining()) {
if (!a.hasNext()) {
break;
}
x = a.next();
}
if (!y.hasRemaining()) {
y = b.next();
}
}
return 0;
}
public static int hash(Rope r) { | return PerlHash.hash(0, r.bytes()); |
lacuna/bifurcan | src/io/lacuna/bifurcan/durable/Util.java | // Path: src/io/lacuna/bifurcan/utils/Bits.java
// public class Bits {
//
// private static final byte deBruijnIndex[] =
// new byte[]{0, 1, 2, 53, 3, 7, 54, 27, 4, 38, 41, 8, 34, 55, 48, 28,
// 62, 5, 39, 46, 44, 42, 22, 9, 24, 35, 59, 56, 49, 18, 29, 11,
// 63, 52, 6, 26, 37, 40, 33, 47, 61, 45, 43, 21, 23, 58, 17, 10,
// 51, 25, 36, 32, 60, 20, 57, 16, 50, 31, 19, 15, 30, 14, 13, 12};
//
// /**
// * @param n a number, which must be a power of two
// * @return the offset of the bit
// */
// public static int bitOffset(long n) {
// return deBruijnIndex[0xFF & (int) ((n * 0x022fdd63cc95386dL) >>> 58)];
// }
//
// /**
// * @param n a number
// * @return the same number, with all but the lowest bit zeroed out
// */
// public static long lowestBit(long n) {
// return n & -n;
// }
//
// /**
// * @param n a number
// * @return the same number, with all but the lowest bit zeroed out
// */
// public static int lowestBit(int n) {
// return n & -n;
// }
//
// /**
// * @param n a number
// * @return the same number, with all but the highest bit zeroed out
// */
// public static long highestBit(long n) {
// return Long.highestOneBit(n);
// }
//
// /**
// * @param n a number
// * @return the same number, with all but the highest bit zeroed out
// */
// public static int highestBit(int n) {
// return Integer.highestOneBit(n);
// }
//
// /**
// * @param n a number
// * @return the log2 of that value, rounded down
// */
// public static int log2Floor(long n) {
// return bitOffset(highestBit(n));
// }
//
// /**
// * @param n a number
// * @return the log2 of the value, rounded up
// */
// public static int log2Ceil(long n) {
// int log2 = log2Floor(n);
// return isPowerOfTwo(n) ? log2 : log2 + 1;
// }
//
// /**
// * @param n a number
// * @param offset the offset of the bit being tested
// * @return true if the bit is 1, false otherwise
// */
// public static boolean test(int n, int offset) {
// return (n & (1 << offset)) != 0;
// }
//
// /**
// * @param n a number
// * @param offset the offset of the bit being tested
// * @return true if the bit is 1, false otherwise
// */
// public static boolean test(long n, int offset) {
// return (n & (1L << offset)) != 0;
// }
//
// /**
// * @param bits a bit offset
// * @return a mask, with all bits below that offset set to one
// */
// public static long maskBelow(int bits) {
// return (1L << bits) - 1;
// }
//
// /**
// * @param bits a bit offset
// * @return a mask, with all bits above that offset set to one
// */
// public static long maskAbove(int bits) {
// return -1L & ~maskBelow(bits);
// }
//
// /**
// * @return the offset of the highest bit which differs between {@code a} and {@code b}
// */
// public static int branchingBit(long a, long b) {
// if (a == b) {
// return -1;
// } else {
// return bitOffset(highestBit(a ^ b));
// }
// }
//
// /**
// * @param n a number
// * @return true, if the number is a power of two
// */
// public static boolean isPowerOfTwo(long n) {
// return (n & (n - 1)) == 0;
// }
//
// public static long slice(long n, int start, int end) {
// return (n >> start) & maskBelow(end - start);
// }
// }
| import io.lacuna.bifurcan.*;
import io.lacuna.bifurcan.utils.Bits;
import java.nio.charset.Charset;
import java.util.Iterator;
import java.util.function.Predicate; | return curr;
}
};
}
/**
* Writes a signed variable-length quantity.
*/
public static void writeVLQ(long val, DurableOutput out) {
if (val < 0) {
writePrefixedUVLQ(1, 1, -val, out);
} else {
writePrefixedUVLQ(0, 1, val, out);
}
}
/**
* Reads a signed variable-length quantity.
*/
public static long readVLQ(DurableInput in) {
int b = in.readByte() & 0xFF;
long val = readPrefixedUVLQ(b, 1, in);
return (b & 128) > 0 ? -val : val;
}
/**
* Writes an unsigned variable-length quantity.
*/
public static void writeUVLQ(long val, DurableOutput out) { | // Path: src/io/lacuna/bifurcan/utils/Bits.java
// public class Bits {
//
// private static final byte deBruijnIndex[] =
// new byte[]{0, 1, 2, 53, 3, 7, 54, 27, 4, 38, 41, 8, 34, 55, 48, 28,
// 62, 5, 39, 46, 44, 42, 22, 9, 24, 35, 59, 56, 49, 18, 29, 11,
// 63, 52, 6, 26, 37, 40, 33, 47, 61, 45, 43, 21, 23, 58, 17, 10,
// 51, 25, 36, 32, 60, 20, 57, 16, 50, 31, 19, 15, 30, 14, 13, 12};
//
// /**
// * @param n a number, which must be a power of two
// * @return the offset of the bit
// */
// public static int bitOffset(long n) {
// return deBruijnIndex[0xFF & (int) ((n * 0x022fdd63cc95386dL) >>> 58)];
// }
//
// /**
// * @param n a number
// * @return the same number, with all but the lowest bit zeroed out
// */
// public static long lowestBit(long n) {
// return n & -n;
// }
//
// /**
// * @param n a number
// * @return the same number, with all but the lowest bit zeroed out
// */
// public static int lowestBit(int n) {
// return n & -n;
// }
//
// /**
// * @param n a number
// * @return the same number, with all but the highest bit zeroed out
// */
// public static long highestBit(long n) {
// return Long.highestOneBit(n);
// }
//
// /**
// * @param n a number
// * @return the same number, with all but the highest bit zeroed out
// */
// public static int highestBit(int n) {
// return Integer.highestOneBit(n);
// }
//
// /**
// * @param n a number
// * @return the log2 of that value, rounded down
// */
// public static int log2Floor(long n) {
// return bitOffset(highestBit(n));
// }
//
// /**
// * @param n a number
// * @return the log2 of the value, rounded up
// */
// public static int log2Ceil(long n) {
// int log2 = log2Floor(n);
// return isPowerOfTwo(n) ? log2 : log2 + 1;
// }
//
// /**
// * @param n a number
// * @param offset the offset of the bit being tested
// * @return true if the bit is 1, false otherwise
// */
// public static boolean test(int n, int offset) {
// return (n & (1 << offset)) != 0;
// }
//
// /**
// * @param n a number
// * @param offset the offset of the bit being tested
// * @return true if the bit is 1, false otherwise
// */
// public static boolean test(long n, int offset) {
// return (n & (1L << offset)) != 0;
// }
//
// /**
// * @param bits a bit offset
// * @return a mask, with all bits below that offset set to one
// */
// public static long maskBelow(int bits) {
// return (1L << bits) - 1;
// }
//
// /**
// * @param bits a bit offset
// * @return a mask, with all bits above that offset set to one
// */
// public static long maskAbove(int bits) {
// return -1L & ~maskBelow(bits);
// }
//
// /**
// * @return the offset of the highest bit which differs between {@code a} and {@code b}
// */
// public static int branchingBit(long a, long b) {
// if (a == b) {
// return -1;
// } else {
// return bitOffset(highestBit(a ^ b));
// }
// }
//
// /**
// * @param n a number
// * @return true, if the number is a power of two
// */
// public static boolean isPowerOfTwo(long n) {
// return (n & (n - 1)) == 0;
// }
//
// public static long slice(long n, int start, int end) {
// return (n >> start) & maskBelow(end - start);
// }
// }
// Path: src/io/lacuna/bifurcan/durable/Util.java
import io.lacuna.bifurcan.*;
import io.lacuna.bifurcan.utils.Bits;
import java.nio.charset.Charset;
import java.util.Iterator;
import java.util.function.Predicate;
return curr;
}
};
}
/**
* Writes a signed variable-length quantity.
*/
public static void writeVLQ(long val, DurableOutput out) {
if (val < 0) {
writePrefixedUVLQ(1, 1, -val, out);
} else {
writePrefixedUVLQ(0, 1, val, out);
}
}
/**
* Reads a signed variable-length quantity.
*/
public static long readVLQ(DurableInput in) {
int b = in.readByte() & 0xFF;
long val = readPrefixedUVLQ(b, 1, in);
return (b & 128) > 0 ? -val : val;
}
/**
* Writes an unsigned variable-length quantity.
*/
public static void writeUVLQ(long val, DurableOutput out) { | writeUVLQ(val, Bits.log2Floor(val) + 1, out); |
lacuna/bifurcan | src/io/lacuna/bifurcan/IGraph.java | // Path: src/io/lacuna/bifurcan/Graphs.java
// static final BinaryOperator MERGE_LAST_WRITE_WINS = (a, b) -> b;
| import java.util.Iterator;
import java.util.OptionalLong;
import java.util.function.*;
import static io.lacuna.bifurcan.Graphs.MERGE_LAST_WRITE_WINS; | package io.lacuna.bifurcan;
/**
* @author ztellman
*/
public interface IGraph<V, E> extends ICollection<IGraph<V, E>, V> {
/**
* @return the set of all vertices in the graph
*/
ISet<V> vertices();
/**
* @return an iterator over every edge in the graph
*/
Iterable<IEdge<V, E>> edges();
/**
* @return the value of the edge between {@code from} and {@code to}
* @throws IllegalArgumentException if no such edge exists
*/
E edge(V from, V to);
/**
* In an undirected graph, this is equivalent to {@link IGraph#out(Object)}.
*
* @return the set of all incoming edges to {@code vertex}
* @throws IllegalArgumentException if no such vertex exists
*/
ISet<V> in(V vertex);
/**
* In an undirected graph, this is equivalent to {@link IGraph#in(Object)}.
*
* @return the set of all outgoing edges from {@code vertex}
* @throws IllegalArgumentException if no such vertex exists
*/
ISet<V> out(V vertex);
/**
* @param from the source of the edge
* @param to the destination of the edge
* @param edge the value of the edge
* @param merge the merge function for the edge values, if an edge already exists
* @return a graph containing the new edge
*/
IGraph<V, E> link(V from, V to, E edge, BinaryOperator<E> merge);
/**
* @return a graph without any edge between {@code from} and {@code to}
*/
IGraph<V, E> unlink(V from, V to);
/**
* @return a graph with {@code vertex} added
*/
IGraph<V, E> add(V vertex);
/**
* @return a graph with {@code vertex} removed, as well as all incoming and outgoing edges
*/
IGraph<V, E> remove(V vertex);
<U> IGraph<V, U> mapEdges(Function<IEdge<V, E>, U> f);
/**
* @return the index of {@code vertex}, if it's present
*/
default OptionalLong indexOf(V vertex) {
return vertices().indexOf(vertex);
}
default V nth(long idx) {
return vertices().nth(idx);
}
default Iterator<V> iterator(long startIndex) {
return vertices().iterator(startIndex);
}
default long size() {
return vertices().size();
}
/**
* @return a graph containing only the specified vertices and the edges between them
*/
IGraph<V, E> select(ISet<V> vertices);
/**
* @return
*/
default IGraph<V, E> replace(V a, V b) { | // Path: src/io/lacuna/bifurcan/Graphs.java
// static final BinaryOperator MERGE_LAST_WRITE_WINS = (a, b) -> b;
// Path: src/io/lacuna/bifurcan/IGraph.java
import java.util.Iterator;
import java.util.OptionalLong;
import java.util.function.*;
import static io.lacuna.bifurcan.Graphs.MERGE_LAST_WRITE_WINS;
package io.lacuna.bifurcan;
/**
* @author ztellman
*/
public interface IGraph<V, E> extends ICollection<IGraph<V, E>, V> {
/**
* @return the set of all vertices in the graph
*/
ISet<V> vertices();
/**
* @return an iterator over every edge in the graph
*/
Iterable<IEdge<V, E>> edges();
/**
* @return the value of the edge between {@code from} and {@code to}
* @throws IllegalArgumentException if no such edge exists
*/
E edge(V from, V to);
/**
* In an undirected graph, this is equivalent to {@link IGraph#out(Object)}.
*
* @return the set of all incoming edges to {@code vertex}
* @throws IllegalArgumentException if no such vertex exists
*/
ISet<V> in(V vertex);
/**
* In an undirected graph, this is equivalent to {@link IGraph#in(Object)}.
*
* @return the set of all outgoing edges from {@code vertex}
* @throws IllegalArgumentException if no such vertex exists
*/
ISet<V> out(V vertex);
/**
* @param from the source of the edge
* @param to the destination of the edge
* @param edge the value of the edge
* @param merge the merge function for the edge values, if an edge already exists
* @return a graph containing the new edge
*/
IGraph<V, E> link(V from, V to, E edge, BinaryOperator<E> merge);
/**
* @return a graph without any edge between {@code from} and {@code to}
*/
IGraph<V, E> unlink(V from, V to);
/**
* @return a graph with {@code vertex} added
*/
IGraph<V, E> add(V vertex);
/**
* @return a graph with {@code vertex} removed, as well as all incoming and outgoing edges
*/
IGraph<V, E> remove(V vertex);
<U> IGraph<V, U> mapEdges(Function<IEdge<V, E>, U> f);
/**
* @return the index of {@code vertex}, if it's present
*/
default OptionalLong indexOf(V vertex) {
return vertices().indexOf(vertex);
}
default V nth(long idx) {
return vertices().nth(idx);
}
default Iterator<V> iterator(long startIndex) {
return vertices().iterator(startIndex);
}
default long size() {
return vertices().size();
}
/**
* @return a graph containing only the specified vertices and the edges between them
*/
IGraph<V, E> select(ISet<V> vertices);
/**
* @return
*/
default IGraph<V, E> replace(V a, V b) { | return replace(a, b, (BinaryOperator<E>) Graphs.MERGE_LAST_WRITE_WINS); |
adealjason/dtsopensource | dts-parent/dts-core/src/main/java/org/github/dtsopensource/core/store/help/ActivityHelper.java | // Path: dts-parent/dts-core/src/main/java/org/github/dtsopensource/core/dao/dataobject/DtsActivityDO.java
// @ToString
// public class DtsActivityDO {
//
// private Long id;
//
// private String activityId;
//
// private String app;
//
// private String bizType;
//
// private String context;
//
// private String status;
//
// private String isDeleted;
//
// private Date gmtCreated;
//
// private Date gmtModified;
//
// private String creator;
//
// private String modifier;
//
// /**
// * @return
// */
// public Long getId() {
// return id;
// }
//
// /**
// * @param id
// */
// public void setId(Long id) {
// this.id = id;
// }
//
// /**
// * @return
// */
// public String getActivityId() {
// return activityId;
// }
//
// /**
// * @param activityId
// */
// public void setActivityId(String activityId) {
// this.activityId = activityId == null ? null : activityId.trim();
// }
//
// /**
// * @return
// */
// public String getApp() {
// return app;
// }
//
// /**
// * @param app
// */
// public void setApp(String app) {
// this.app = app == null ? null : app.trim();
// }
//
// /**
// * @return
// */
// public String getBizType() {
// return bizType;
// }
//
// /**
// * @param bizType
// */
// public void setBizType(String bizType) {
// this.bizType = bizType == null ? null : bizType.trim();
// }
//
// /**
// * @return
// */
// public String getContext() {
// return context;
// }
//
// /**
// * @param context
// */
// public void setContext(String context) {
// this.context = context == null ? null : context.trim();
// }
//
// /**
// * @return
// */
// public String getStatus() {
// return status;
// }
//
// /**
// * @param status
// */
// public void setStatus(String status) {
// this.status = status;
// }
//
// /**
// * @return
// */
// public String getIsDeleted() {
// return isDeleted;
// }
//
// /**
// * @param isDeleted
// */
// public void setIsDeleted(String isDeleted) {
// this.isDeleted = isDeleted;
// }
//
// /**
// * @return
// */
// public Date getGmtCreated() {
// return gmtCreated;
// }
//
// /**
// * @param gmtCreated
// */
// public void setGmtCreated(Date gmtCreated) {
// this.gmtCreated = gmtCreated;
// }
//
// /**
// * @return
// */
// public Date getGmtModified() {
// return gmtModified;
// }
//
// /**
// * @param gmtModified
// */
// public void setGmtModified(Date gmtModified) {
// this.gmtModified = gmtModified;
// }
//
// /**
// * @return
// */
// public String getCreator() {
// return creator;
// }
//
// /**
// * @param creator
// */
// public void setCreator(String creator) {
// this.creator = creator;
// }
//
// /**
// * @return
// */
// public String getModifier() {
// return modifier;
// }
//
// /**
// * @param modifier
// */
// public void setModifier(String modifier) {
// this.modifier = modifier;
// }
// }
| import java.util.Date;
import org.github.dtsopensource.core.dao.dataobject.DtsActivityDO;
import org.github.dtsopensource.server.share.store.entity.ActivityEntity;
import com.alibaba.fastjson.JSON;
| package org.github.dtsopensource.core.store.help;
/**
* @author ligaofeng 2016年12月1日 下午9:09:08
*/
public class ActivityHelper {
private ActivityHelper() {
}
/**
* @param activityDO
* @return
*/
| // Path: dts-parent/dts-core/src/main/java/org/github/dtsopensource/core/dao/dataobject/DtsActivityDO.java
// @ToString
// public class DtsActivityDO {
//
// private Long id;
//
// private String activityId;
//
// private String app;
//
// private String bizType;
//
// private String context;
//
// private String status;
//
// private String isDeleted;
//
// private Date gmtCreated;
//
// private Date gmtModified;
//
// private String creator;
//
// private String modifier;
//
// /**
// * @return
// */
// public Long getId() {
// return id;
// }
//
// /**
// * @param id
// */
// public void setId(Long id) {
// this.id = id;
// }
//
// /**
// * @return
// */
// public String getActivityId() {
// return activityId;
// }
//
// /**
// * @param activityId
// */
// public void setActivityId(String activityId) {
// this.activityId = activityId == null ? null : activityId.trim();
// }
//
// /**
// * @return
// */
// public String getApp() {
// return app;
// }
//
// /**
// * @param app
// */
// public void setApp(String app) {
// this.app = app == null ? null : app.trim();
// }
//
// /**
// * @return
// */
// public String getBizType() {
// return bizType;
// }
//
// /**
// * @param bizType
// */
// public void setBizType(String bizType) {
// this.bizType = bizType == null ? null : bizType.trim();
// }
//
// /**
// * @return
// */
// public String getContext() {
// return context;
// }
//
// /**
// * @param context
// */
// public void setContext(String context) {
// this.context = context == null ? null : context.trim();
// }
//
// /**
// * @return
// */
// public String getStatus() {
// return status;
// }
//
// /**
// * @param status
// */
// public void setStatus(String status) {
// this.status = status;
// }
//
// /**
// * @return
// */
// public String getIsDeleted() {
// return isDeleted;
// }
//
// /**
// * @param isDeleted
// */
// public void setIsDeleted(String isDeleted) {
// this.isDeleted = isDeleted;
// }
//
// /**
// * @return
// */
// public Date getGmtCreated() {
// return gmtCreated;
// }
//
// /**
// * @param gmtCreated
// */
// public void setGmtCreated(Date gmtCreated) {
// this.gmtCreated = gmtCreated;
// }
//
// /**
// * @return
// */
// public Date getGmtModified() {
// return gmtModified;
// }
//
// /**
// * @param gmtModified
// */
// public void setGmtModified(Date gmtModified) {
// this.gmtModified = gmtModified;
// }
//
// /**
// * @return
// */
// public String getCreator() {
// return creator;
// }
//
// /**
// * @param creator
// */
// public void setCreator(String creator) {
// this.creator = creator;
// }
//
// /**
// * @return
// */
// public String getModifier() {
// return modifier;
// }
//
// /**
// * @param modifier
// */
// public void setModifier(String modifier) {
// this.modifier = modifier;
// }
// }
// Path: dts-parent/dts-core/src/main/java/org/github/dtsopensource/core/store/help/ActivityHelper.java
import java.util.Date;
import org.github.dtsopensource.core.dao.dataobject.DtsActivityDO;
import org.github.dtsopensource.server.share.store.entity.ActivityEntity;
import com.alibaba.fastjson.JSON;
package org.github.dtsopensource.core.store.help;
/**
* @author ligaofeng 2016年12月1日 下午9:09:08
*/
public class ActivityHelper {
private ActivityHelper() {
}
/**
* @param activityDO
* @return
*/
| public static ActivityEntity toActivityEntity(DtsActivityDO activityDO) {
|
adealjason/dtsopensource | dts-parent/dts-schedule/src/main/java/org/github/dtsopensource/schedule/taskTracker/task/HangTransactionMonitorTask.java | // Path: dts-parent/dts-server-share/src/main/java/org/github/dtsopensource/server/share/DTSConfig.java
// @Getter
// @Setter
// public class DTSConfig implements Serializable {
//
// private static final long serialVersionUID = -2408123274907783162L;
//
// private DTSManageType dtsManageType;
//
// private String app;
//
// //dts业务规则请求地址
// private String requestActivityRuleURL;
//
// @PostConstruct
// public void checkConfig() {
// if (dtsManageType == null) {
// throw new DTSRuntimeException("dts连接方式dtsManageType未定义");
// }
// if (app == null || app.trim().length() == 0) {
// throw new DTSRuntimeException("业务系统名称app未定义");
// }
// if (requestActivityRuleURL == null || requestActivityRuleURL.trim().length() == 0) {
// throw new DTSRuntimeException("dts业务规则请求地址requestActivityRuleURL尚未配置");
// }
// }
//
// @Override
// public String toString() {
// return JSON.toJSONString(this);
// }
// }
//
// Path: dts-parent/dts-server-share/src/main/java/org/github/dtsopensource/server/share/exception/DTSBizException.java
// public class DTSBizException extends Exception {
//
// private static final long serialVersionUID = 3473398255173602638L;
//
// /**
// * init BizException
// */
// public DTSBizException() {
// super();
// }
//
// /**
// * init BizException
// *
// * @param message
// */
// public DTSBizException(String message) {
// super(message);
// }
//
// /**
// * init BizException
// *
// * @param message
// * @param cause
// */
// public DTSBizException(String message, Throwable cause) {
// super(message, cause);
// }
//
// /**
// * init BizException
// *
// * @param cause
// */
// public DTSBizException(Throwable cause) {
// super(cause);
// }
//
// /**
// * init BizException
// *
// * @param message
// * @param cause
// * @param enableSuppression
// * @param writableStackTrace
// */
// public DTSBizException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
// super(message, cause, enableSuppression, writableStackTrace);
// }
// }
//
// Path: dts-parent/dts-server-share/src/main/java/org/github/dtsopensource/server/share/schedule/TaskTrackerContext.java
// @Getter
// @Setter
// public class TaskTrackerContext implements Serializable {
//
// private static final long serialVersionUID = 1612166307850489500L;
//
// private DTSConfig dtsConfig;
//
// @JSONField(serialize = false)
// private IDTSTaskTracker taskTracker;
//
// @JSONField(serialize = false)
// private IDTSSchedule dtsSchedule;
//
// private String taskTrackerType;
//
// @Override
// public String toString() {
// return JSON.toJSONString(this);
// }
//
// }
| import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import org.github.dtsopensource.server.share.DTSConfig;
import org.github.dtsopensource.server.share.exception.DTSBizException;
import org.github.dtsopensource.server.share.schedule.IDTSSchedule;
import org.github.dtsopensource.server.share.schedule.IDTSTaskTracker;
import org.github.dtsopensource.server.share.schedule.TaskTrackerContext;
import lombok.extern.slf4j.Slf4j;
| package org.github.dtsopensource.schedule.taskTracker.task;
/**
* dts二阶事务恢复监控<br>
* 执行超过一定次数自动将该业务活动置为异常(status:E)业务活动<br>
* taskTrackerType:hangTransactionMonitor
*
* @author ligaofeng 2016年12月18日 下午1:47:55
*/
@Slf4j
public class HangTransactionMonitorTask implements IDTSTaskTracker {
private final ExecutorService executor = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors());
@Override
| // Path: dts-parent/dts-server-share/src/main/java/org/github/dtsopensource/server/share/DTSConfig.java
// @Getter
// @Setter
// public class DTSConfig implements Serializable {
//
// private static final long serialVersionUID = -2408123274907783162L;
//
// private DTSManageType dtsManageType;
//
// private String app;
//
// //dts业务规则请求地址
// private String requestActivityRuleURL;
//
// @PostConstruct
// public void checkConfig() {
// if (dtsManageType == null) {
// throw new DTSRuntimeException("dts连接方式dtsManageType未定义");
// }
// if (app == null || app.trim().length() == 0) {
// throw new DTSRuntimeException("业务系统名称app未定义");
// }
// if (requestActivityRuleURL == null || requestActivityRuleURL.trim().length() == 0) {
// throw new DTSRuntimeException("dts业务规则请求地址requestActivityRuleURL尚未配置");
// }
// }
//
// @Override
// public String toString() {
// return JSON.toJSONString(this);
// }
// }
//
// Path: dts-parent/dts-server-share/src/main/java/org/github/dtsopensource/server/share/exception/DTSBizException.java
// public class DTSBizException extends Exception {
//
// private static final long serialVersionUID = 3473398255173602638L;
//
// /**
// * init BizException
// */
// public DTSBizException() {
// super();
// }
//
// /**
// * init BizException
// *
// * @param message
// */
// public DTSBizException(String message) {
// super(message);
// }
//
// /**
// * init BizException
// *
// * @param message
// * @param cause
// */
// public DTSBizException(String message, Throwable cause) {
// super(message, cause);
// }
//
// /**
// * init BizException
// *
// * @param cause
// */
// public DTSBizException(Throwable cause) {
// super(cause);
// }
//
// /**
// * init BizException
// *
// * @param message
// * @param cause
// * @param enableSuppression
// * @param writableStackTrace
// */
// public DTSBizException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
// super(message, cause, enableSuppression, writableStackTrace);
// }
// }
//
// Path: dts-parent/dts-server-share/src/main/java/org/github/dtsopensource/server/share/schedule/TaskTrackerContext.java
// @Getter
// @Setter
// public class TaskTrackerContext implements Serializable {
//
// private static final long serialVersionUID = 1612166307850489500L;
//
// private DTSConfig dtsConfig;
//
// @JSONField(serialize = false)
// private IDTSTaskTracker taskTracker;
//
// @JSONField(serialize = false)
// private IDTSSchedule dtsSchedule;
//
// private String taskTrackerType;
//
// @Override
// public String toString() {
// return JSON.toJSONString(this);
// }
//
// }
// Path: dts-parent/dts-schedule/src/main/java/org/github/dtsopensource/schedule/taskTracker/task/HangTransactionMonitorTask.java
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import org.github.dtsopensource.server.share.DTSConfig;
import org.github.dtsopensource.server.share.exception.DTSBizException;
import org.github.dtsopensource.server.share.schedule.IDTSSchedule;
import org.github.dtsopensource.server.share.schedule.IDTSTaskTracker;
import org.github.dtsopensource.server.share.schedule.TaskTrackerContext;
import lombok.extern.slf4j.Slf4j;
package org.github.dtsopensource.schedule.taskTracker.task;
/**
* dts二阶事务恢复监控<br>
* 执行超过一定次数自动将该业务活动置为异常(status:E)业务活动<br>
* taskTrackerType:hangTransactionMonitor
*
* @author ligaofeng 2016年12月18日 下午1:47:55
*/
@Slf4j
public class HangTransactionMonitorTask implements IDTSTaskTracker {
private final ExecutorService executor = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors());
@Override
| public void executeTask(TaskTrackerContext taskTrackerContext) throws DTSBizException {
|
adealjason/dtsopensource | dts-parent/dts-schedule/src/main/java/org/github/dtsopensource/schedule/taskTracker/task/HangTransactionMonitorTask.java | // Path: dts-parent/dts-server-share/src/main/java/org/github/dtsopensource/server/share/DTSConfig.java
// @Getter
// @Setter
// public class DTSConfig implements Serializable {
//
// private static final long serialVersionUID = -2408123274907783162L;
//
// private DTSManageType dtsManageType;
//
// private String app;
//
// //dts业务规则请求地址
// private String requestActivityRuleURL;
//
// @PostConstruct
// public void checkConfig() {
// if (dtsManageType == null) {
// throw new DTSRuntimeException("dts连接方式dtsManageType未定义");
// }
// if (app == null || app.trim().length() == 0) {
// throw new DTSRuntimeException("业务系统名称app未定义");
// }
// if (requestActivityRuleURL == null || requestActivityRuleURL.trim().length() == 0) {
// throw new DTSRuntimeException("dts业务规则请求地址requestActivityRuleURL尚未配置");
// }
// }
//
// @Override
// public String toString() {
// return JSON.toJSONString(this);
// }
// }
//
// Path: dts-parent/dts-server-share/src/main/java/org/github/dtsopensource/server/share/exception/DTSBizException.java
// public class DTSBizException extends Exception {
//
// private static final long serialVersionUID = 3473398255173602638L;
//
// /**
// * init BizException
// */
// public DTSBizException() {
// super();
// }
//
// /**
// * init BizException
// *
// * @param message
// */
// public DTSBizException(String message) {
// super(message);
// }
//
// /**
// * init BizException
// *
// * @param message
// * @param cause
// */
// public DTSBizException(String message, Throwable cause) {
// super(message, cause);
// }
//
// /**
// * init BizException
// *
// * @param cause
// */
// public DTSBizException(Throwable cause) {
// super(cause);
// }
//
// /**
// * init BizException
// *
// * @param message
// * @param cause
// * @param enableSuppression
// * @param writableStackTrace
// */
// public DTSBizException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
// super(message, cause, enableSuppression, writableStackTrace);
// }
// }
//
// Path: dts-parent/dts-server-share/src/main/java/org/github/dtsopensource/server/share/schedule/TaskTrackerContext.java
// @Getter
// @Setter
// public class TaskTrackerContext implements Serializable {
//
// private static final long serialVersionUID = 1612166307850489500L;
//
// private DTSConfig dtsConfig;
//
// @JSONField(serialize = false)
// private IDTSTaskTracker taskTracker;
//
// @JSONField(serialize = false)
// private IDTSSchedule dtsSchedule;
//
// private String taskTrackerType;
//
// @Override
// public String toString() {
// return JSON.toJSONString(this);
// }
//
// }
| import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import org.github.dtsopensource.server.share.DTSConfig;
import org.github.dtsopensource.server.share.exception.DTSBizException;
import org.github.dtsopensource.server.share.schedule.IDTSSchedule;
import org.github.dtsopensource.server.share.schedule.IDTSTaskTracker;
import org.github.dtsopensource.server.share.schedule.TaskTrackerContext;
import lombok.extern.slf4j.Slf4j;
| package org.github.dtsopensource.schedule.taskTracker.task;
/**
* dts二阶事务恢复监控<br>
* 执行超过一定次数自动将该业务活动置为异常(status:E)业务活动<br>
* taskTrackerType:hangTransactionMonitor
*
* @author ligaofeng 2016年12月18日 下午1:47:55
*/
@Slf4j
public class HangTransactionMonitorTask implements IDTSTaskTracker {
private final ExecutorService executor = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors());
@Override
| // Path: dts-parent/dts-server-share/src/main/java/org/github/dtsopensource/server/share/DTSConfig.java
// @Getter
// @Setter
// public class DTSConfig implements Serializable {
//
// private static final long serialVersionUID = -2408123274907783162L;
//
// private DTSManageType dtsManageType;
//
// private String app;
//
// //dts业务规则请求地址
// private String requestActivityRuleURL;
//
// @PostConstruct
// public void checkConfig() {
// if (dtsManageType == null) {
// throw new DTSRuntimeException("dts连接方式dtsManageType未定义");
// }
// if (app == null || app.trim().length() == 0) {
// throw new DTSRuntimeException("业务系统名称app未定义");
// }
// if (requestActivityRuleURL == null || requestActivityRuleURL.trim().length() == 0) {
// throw new DTSRuntimeException("dts业务规则请求地址requestActivityRuleURL尚未配置");
// }
// }
//
// @Override
// public String toString() {
// return JSON.toJSONString(this);
// }
// }
//
// Path: dts-parent/dts-server-share/src/main/java/org/github/dtsopensource/server/share/exception/DTSBizException.java
// public class DTSBizException extends Exception {
//
// private static final long serialVersionUID = 3473398255173602638L;
//
// /**
// * init BizException
// */
// public DTSBizException() {
// super();
// }
//
// /**
// * init BizException
// *
// * @param message
// */
// public DTSBizException(String message) {
// super(message);
// }
//
// /**
// * init BizException
// *
// * @param message
// * @param cause
// */
// public DTSBizException(String message, Throwable cause) {
// super(message, cause);
// }
//
// /**
// * init BizException
// *
// * @param cause
// */
// public DTSBizException(Throwable cause) {
// super(cause);
// }
//
// /**
// * init BizException
// *
// * @param message
// * @param cause
// * @param enableSuppression
// * @param writableStackTrace
// */
// public DTSBizException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
// super(message, cause, enableSuppression, writableStackTrace);
// }
// }
//
// Path: dts-parent/dts-server-share/src/main/java/org/github/dtsopensource/server/share/schedule/TaskTrackerContext.java
// @Getter
// @Setter
// public class TaskTrackerContext implements Serializable {
//
// private static final long serialVersionUID = 1612166307850489500L;
//
// private DTSConfig dtsConfig;
//
// @JSONField(serialize = false)
// private IDTSTaskTracker taskTracker;
//
// @JSONField(serialize = false)
// private IDTSSchedule dtsSchedule;
//
// private String taskTrackerType;
//
// @Override
// public String toString() {
// return JSON.toJSONString(this);
// }
//
// }
// Path: dts-parent/dts-schedule/src/main/java/org/github/dtsopensource/schedule/taskTracker/task/HangTransactionMonitorTask.java
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import org.github.dtsopensource.server.share.DTSConfig;
import org.github.dtsopensource.server.share.exception.DTSBizException;
import org.github.dtsopensource.server.share.schedule.IDTSSchedule;
import org.github.dtsopensource.server.share.schedule.IDTSTaskTracker;
import org.github.dtsopensource.server.share.schedule.TaskTrackerContext;
import lombok.extern.slf4j.Slf4j;
package org.github.dtsopensource.schedule.taskTracker.task;
/**
* dts二阶事务恢复监控<br>
* 执行超过一定次数自动将该业务活动置为异常(status:E)业务活动<br>
* taskTrackerType:hangTransactionMonitor
*
* @author ligaofeng 2016年12月18日 下午1:47:55
*/
@Slf4j
public class HangTransactionMonitorTask implements IDTSTaskTracker {
private final ExecutorService executor = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors());
@Override
| public void executeTask(TaskTrackerContext taskTrackerContext) throws DTSBizException {
|
adealjason/dtsopensource | dts-parent/dts-schedule/src/main/java/org/github/dtsopensource/schedule/taskTracker/task/HangTransactionMonitorTask.java | // Path: dts-parent/dts-server-share/src/main/java/org/github/dtsopensource/server/share/DTSConfig.java
// @Getter
// @Setter
// public class DTSConfig implements Serializable {
//
// private static final long serialVersionUID = -2408123274907783162L;
//
// private DTSManageType dtsManageType;
//
// private String app;
//
// //dts业务规则请求地址
// private String requestActivityRuleURL;
//
// @PostConstruct
// public void checkConfig() {
// if (dtsManageType == null) {
// throw new DTSRuntimeException("dts连接方式dtsManageType未定义");
// }
// if (app == null || app.trim().length() == 0) {
// throw new DTSRuntimeException("业务系统名称app未定义");
// }
// if (requestActivityRuleURL == null || requestActivityRuleURL.trim().length() == 0) {
// throw new DTSRuntimeException("dts业务规则请求地址requestActivityRuleURL尚未配置");
// }
// }
//
// @Override
// public String toString() {
// return JSON.toJSONString(this);
// }
// }
//
// Path: dts-parent/dts-server-share/src/main/java/org/github/dtsopensource/server/share/exception/DTSBizException.java
// public class DTSBizException extends Exception {
//
// private static final long serialVersionUID = 3473398255173602638L;
//
// /**
// * init BizException
// */
// public DTSBizException() {
// super();
// }
//
// /**
// * init BizException
// *
// * @param message
// */
// public DTSBizException(String message) {
// super(message);
// }
//
// /**
// * init BizException
// *
// * @param message
// * @param cause
// */
// public DTSBizException(String message, Throwable cause) {
// super(message, cause);
// }
//
// /**
// * init BizException
// *
// * @param cause
// */
// public DTSBizException(Throwable cause) {
// super(cause);
// }
//
// /**
// * init BizException
// *
// * @param message
// * @param cause
// * @param enableSuppression
// * @param writableStackTrace
// */
// public DTSBizException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
// super(message, cause, enableSuppression, writableStackTrace);
// }
// }
//
// Path: dts-parent/dts-server-share/src/main/java/org/github/dtsopensource/server/share/schedule/TaskTrackerContext.java
// @Getter
// @Setter
// public class TaskTrackerContext implements Serializable {
//
// private static final long serialVersionUID = 1612166307850489500L;
//
// private DTSConfig dtsConfig;
//
// @JSONField(serialize = false)
// private IDTSTaskTracker taskTracker;
//
// @JSONField(serialize = false)
// private IDTSSchedule dtsSchedule;
//
// private String taskTrackerType;
//
// @Override
// public String toString() {
// return JSON.toJSONString(this);
// }
//
// }
| import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import org.github.dtsopensource.server.share.DTSConfig;
import org.github.dtsopensource.server.share.exception.DTSBizException;
import org.github.dtsopensource.server.share.schedule.IDTSSchedule;
import org.github.dtsopensource.server.share.schedule.IDTSTaskTracker;
import org.github.dtsopensource.server.share.schedule.TaskTrackerContext;
import lombok.extern.slf4j.Slf4j;
| package org.github.dtsopensource.schedule.taskTracker.task;
/**
* dts二阶事务恢复监控<br>
* 执行超过一定次数自动将该业务活动置为异常(status:E)业务活动<br>
* taskTrackerType:hangTransactionMonitor
*
* @author ligaofeng 2016年12月18日 下午1:47:55
*/
@Slf4j
public class HangTransactionMonitorTask implements IDTSTaskTracker {
private final ExecutorService executor = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors());
@Override
public void executeTask(TaskTrackerContext taskTrackerContext) throws DTSBizException {
log.info("--->start to execute hang transaction monitor task:{}", taskTrackerContext);
IDTSSchedule dtsSchedule = taskTrackerContext.getDtsSchedule();
| // Path: dts-parent/dts-server-share/src/main/java/org/github/dtsopensource/server/share/DTSConfig.java
// @Getter
// @Setter
// public class DTSConfig implements Serializable {
//
// private static final long serialVersionUID = -2408123274907783162L;
//
// private DTSManageType dtsManageType;
//
// private String app;
//
// //dts业务规则请求地址
// private String requestActivityRuleURL;
//
// @PostConstruct
// public void checkConfig() {
// if (dtsManageType == null) {
// throw new DTSRuntimeException("dts连接方式dtsManageType未定义");
// }
// if (app == null || app.trim().length() == 0) {
// throw new DTSRuntimeException("业务系统名称app未定义");
// }
// if (requestActivityRuleURL == null || requestActivityRuleURL.trim().length() == 0) {
// throw new DTSRuntimeException("dts业务规则请求地址requestActivityRuleURL尚未配置");
// }
// }
//
// @Override
// public String toString() {
// return JSON.toJSONString(this);
// }
// }
//
// Path: dts-parent/dts-server-share/src/main/java/org/github/dtsopensource/server/share/exception/DTSBizException.java
// public class DTSBizException extends Exception {
//
// private static final long serialVersionUID = 3473398255173602638L;
//
// /**
// * init BizException
// */
// public DTSBizException() {
// super();
// }
//
// /**
// * init BizException
// *
// * @param message
// */
// public DTSBizException(String message) {
// super(message);
// }
//
// /**
// * init BizException
// *
// * @param message
// * @param cause
// */
// public DTSBizException(String message, Throwable cause) {
// super(message, cause);
// }
//
// /**
// * init BizException
// *
// * @param cause
// */
// public DTSBizException(Throwable cause) {
// super(cause);
// }
//
// /**
// * init BizException
// *
// * @param message
// * @param cause
// * @param enableSuppression
// * @param writableStackTrace
// */
// public DTSBizException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
// super(message, cause, enableSuppression, writableStackTrace);
// }
// }
//
// Path: dts-parent/dts-server-share/src/main/java/org/github/dtsopensource/server/share/schedule/TaskTrackerContext.java
// @Getter
// @Setter
// public class TaskTrackerContext implements Serializable {
//
// private static final long serialVersionUID = 1612166307850489500L;
//
// private DTSConfig dtsConfig;
//
// @JSONField(serialize = false)
// private IDTSTaskTracker taskTracker;
//
// @JSONField(serialize = false)
// private IDTSSchedule dtsSchedule;
//
// private String taskTrackerType;
//
// @Override
// public String toString() {
// return JSON.toJSONString(this);
// }
//
// }
// Path: dts-parent/dts-schedule/src/main/java/org/github/dtsopensource/schedule/taskTracker/task/HangTransactionMonitorTask.java
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import org.github.dtsopensource.server.share.DTSConfig;
import org.github.dtsopensource.server.share.exception.DTSBizException;
import org.github.dtsopensource.server.share.schedule.IDTSSchedule;
import org.github.dtsopensource.server.share.schedule.IDTSTaskTracker;
import org.github.dtsopensource.server.share.schedule.TaskTrackerContext;
import lombok.extern.slf4j.Slf4j;
package org.github.dtsopensource.schedule.taskTracker.task;
/**
* dts二阶事务恢复监控<br>
* 执行超过一定次数自动将该业务活动置为异常(status:E)业务活动<br>
* taskTrackerType:hangTransactionMonitor
*
* @author ligaofeng 2016年12月18日 下午1:47:55
*/
@Slf4j
public class HangTransactionMonitorTask implements IDTSTaskTracker {
private final ExecutorService executor = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors());
@Override
public void executeTask(TaskTrackerContext taskTrackerContext) throws DTSBizException {
log.info("--->start to execute hang transaction monitor task:{}", taskTrackerContext);
IDTSSchedule dtsSchedule = taskTrackerContext.getDtsSchedule();
| DTSConfig dtsConfig = taskTrackerContext.getDtsConfig();
|
adealjason/dtsopensource | dts-parent/dts-core/src/main/java/org/github/dtsopensource/core/manager/RemoteDTSManager.java | // Path: dts-parent/dts-core/src/main/java/org/github/dtsopensource/core/store/impl/RemoteDTSStore.java
// public class RemoteDTSStore implements IDTSStore {
//
// @Getter
// private final StoreProtocolManager remoteProtocol;
//
// /**
// * @param remoteProtocol
// */
// public RemoteDTSStore(StoreProtocolManager remoteProtocol) {
// this.remoteProtocol = remoteProtocol;
// }
//
// @Override
// public ResultBase<DTSContext> openTransaction(ActivityEntity activityEntity) {
// return remoteProtocol.openTransaction(activityEntity);
// }
//
// @Override
// public ResultBase<String> getAndCreateAction(ActionEntity actionEntity) {
// return remoteProtocol.getAndCreateAction(actionEntity);
// }
//
// @Override
// public ResultBase<String> updateAction(ActionEntity actionEntity) {
// return remoteProtocol.updateAction(actionEntity);
// }
//
// @Override
// public ResultBase<String> commitActivity(String activityId) {
// return remoteProtocol.commitActivity(activityId);
// }
//
// @Override
// public ResultBase<String> rollbackActivity(String activityId) {
// return remoteProtocol.rollbackActivity(activityId);
// }
//
// @Override
// public ResultBase<List<ActionEntity>> getActionEntities(String activityId) {
// return remoteProtocol.getActionEntities(activityId);
// }
//
// }
//
// Path: dts-parent/dts-server-share/src/main/java/org/github/dtsopensource/server/share/exception/DTSRuntimeException.java
// public class DTSRuntimeException extends RuntimeException {
//
// private static final long serialVersionUID = 4328158740883926572L;
//
// /**
// * init DTSRuntimeException
// */
// public DTSRuntimeException() {
// super();
// }
//
// /**
// * init DTSRuntimeException
// *
// * @param message
// */
// public DTSRuntimeException(String message) {
// super(message);
// }
//
// /**
// * init DTSRuntimeException
// *
// * @param message
// * @param cause
// */
// public DTSRuntimeException(String message, Throwable cause) {
// super(message, cause);
// }
//
// /**
// * init DTSRuntimeException
// *
// * @param cause
// */
// public DTSRuntimeException(Throwable cause) {
// super(cause);
// }
//
// /**
// * init DTSRuntimeException
// *
// * @param message
// * @param cause
// * @param enableSuppression
// * @param writableStackTrace
// */
// public DTSRuntimeException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
// super(message, cause, enableSuppression, writableStackTrace);
// }
// }
//
// Path: dts-parent/dts-server-share/src/main/java/org/github/dtsopensource/server/share/store/IDTSStore.java
// public interface IDTSStore extends IDTS {
//
// /**
// * 开启事务
// *
// * @param activityEntity
// * @return
// */
// public ResultBase<DTSContext> openTransaction(ActivityEntity activityEntity);
//
// /**
// * @param actionEntity
// * @return
// */
// public ResultBase<String> getAndCreateAction(ActionEntity actionEntity);
//
// /**
// * 一阶commit时调用
// *
// * @param activityId
// * @return
// */
// public ResultBase<String> commitActivity(String activityId);
//
// /**
// * 一阶rollback时调用
// *
// * @param activityId
// * @return
// */
// public ResultBase<String> rollbackActivity(String activityId);
//
// /**
// * 更新action
// *
// * @param actionEntity
// * @return
// */
// public ResultBase<String> updateAction(ActionEntity actionEntity);
//
// }
| import org.github.dtsopensource.core.protocol.StoreProtocolManager;
import org.github.dtsopensource.core.store.impl.RemoteDTSStore;
import org.github.dtsopensource.server.share.exception.DTSRuntimeException;
import org.github.dtsopensource.server.share.store.IDTSStore;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
| package org.github.dtsopensource.core.manager;
/**
* @author ligaofeng 2016年12月3日 下午4:28:49
*/
@Slf4j
@Setter
public class RemoteDTSManager extends DTSManager {
private StoreProtocolManager remoteProtocol;
@Override
protected void check() {
if (remoteProtocol == null) {
| // Path: dts-parent/dts-core/src/main/java/org/github/dtsopensource/core/store/impl/RemoteDTSStore.java
// public class RemoteDTSStore implements IDTSStore {
//
// @Getter
// private final StoreProtocolManager remoteProtocol;
//
// /**
// * @param remoteProtocol
// */
// public RemoteDTSStore(StoreProtocolManager remoteProtocol) {
// this.remoteProtocol = remoteProtocol;
// }
//
// @Override
// public ResultBase<DTSContext> openTransaction(ActivityEntity activityEntity) {
// return remoteProtocol.openTransaction(activityEntity);
// }
//
// @Override
// public ResultBase<String> getAndCreateAction(ActionEntity actionEntity) {
// return remoteProtocol.getAndCreateAction(actionEntity);
// }
//
// @Override
// public ResultBase<String> updateAction(ActionEntity actionEntity) {
// return remoteProtocol.updateAction(actionEntity);
// }
//
// @Override
// public ResultBase<String> commitActivity(String activityId) {
// return remoteProtocol.commitActivity(activityId);
// }
//
// @Override
// public ResultBase<String> rollbackActivity(String activityId) {
// return remoteProtocol.rollbackActivity(activityId);
// }
//
// @Override
// public ResultBase<List<ActionEntity>> getActionEntities(String activityId) {
// return remoteProtocol.getActionEntities(activityId);
// }
//
// }
//
// Path: dts-parent/dts-server-share/src/main/java/org/github/dtsopensource/server/share/exception/DTSRuntimeException.java
// public class DTSRuntimeException extends RuntimeException {
//
// private static final long serialVersionUID = 4328158740883926572L;
//
// /**
// * init DTSRuntimeException
// */
// public DTSRuntimeException() {
// super();
// }
//
// /**
// * init DTSRuntimeException
// *
// * @param message
// */
// public DTSRuntimeException(String message) {
// super(message);
// }
//
// /**
// * init DTSRuntimeException
// *
// * @param message
// * @param cause
// */
// public DTSRuntimeException(String message, Throwable cause) {
// super(message, cause);
// }
//
// /**
// * init DTSRuntimeException
// *
// * @param cause
// */
// public DTSRuntimeException(Throwable cause) {
// super(cause);
// }
//
// /**
// * init DTSRuntimeException
// *
// * @param message
// * @param cause
// * @param enableSuppression
// * @param writableStackTrace
// */
// public DTSRuntimeException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
// super(message, cause, enableSuppression, writableStackTrace);
// }
// }
//
// Path: dts-parent/dts-server-share/src/main/java/org/github/dtsopensource/server/share/store/IDTSStore.java
// public interface IDTSStore extends IDTS {
//
// /**
// * 开启事务
// *
// * @param activityEntity
// * @return
// */
// public ResultBase<DTSContext> openTransaction(ActivityEntity activityEntity);
//
// /**
// * @param actionEntity
// * @return
// */
// public ResultBase<String> getAndCreateAction(ActionEntity actionEntity);
//
// /**
// * 一阶commit时调用
// *
// * @param activityId
// * @return
// */
// public ResultBase<String> commitActivity(String activityId);
//
// /**
// * 一阶rollback时调用
// *
// * @param activityId
// * @return
// */
// public ResultBase<String> rollbackActivity(String activityId);
//
// /**
// * 更新action
// *
// * @param actionEntity
// * @return
// */
// public ResultBase<String> updateAction(ActionEntity actionEntity);
//
// }
// Path: dts-parent/dts-core/src/main/java/org/github/dtsopensource/core/manager/RemoteDTSManager.java
import org.github.dtsopensource.core.protocol.StoreProtocolManager;
import org.github.dtsopensource.core.store.impl.RemoteDTSStore;
import org.github.dtsopensource.server.share.exception.DTSRuntimeException;
import org.github.dtsopensource.server.share.store.IDTSStore;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
package org.github.dtsopensource.core.manager;
/**
* @author ligaofeng 2016年12月3日 下午4:28:49
*/
@Slf4j
@Setter
public class RemoteDTSManager extends DTSManager {
private StoreProtocolManager remoteProtocol;
@Override
protected void check() {
if (remoteProtocol == null) {
| throw new DTSRuntimeException("remote模式下必须指定IStoreProtocol协议");
|
adealjason/dtsopensource | dts-parent/dts-core/src/main/java/org/github/dtsopensource/core/manager/RemoteDTSManager.java | // Path: dts-parent/dts-core/src/main/java/org/github/dtsopensource/core/store/impl/RemoteDTSStore.java
// public class RemoteDTSStore implements IDTSStore {
//
// @Getter
// private final StoreProtocolManager remoteProtocol;
//
// /**
// * @param remoteProtocol
// */
// public RemoteDTSStore(StoreProtocolManager remoteProtocol) {
// this.remoteProtocol = remoteProtocol;
// }
//
// @Override
// public ResultBase<DTSContext> openTransaction(ActivityEntity activityEntity) {
// return remoteProtocol.openTransaction(activityEntity);
// }
//
// @Override
// public ResultBase<String> getAndCreateAction(ActionEntity actionEntity) {
// return remoteProtocol.getAndCreateAction(actionEntity);
// }
//
// @Override
// public ResultBase<String> updateAction(ActionEntity actionEntity) {
// return remoteProtocol.updateAction(actionEntity);
// }
//
// @Override
// public ResultBase<String> commitActivity(String activityId) {
// return remoteProtocol.commitActivity(activityId);
// }
//
// @Override
// public ResultBase<String> rollbackActivity(String activityId) {
// return remoteProtocol.rollbackActivity(activityId);
// }
//
// @Override
// public ResultBase<List<ActionEntity>> getActionEntities(String activityId) {
// return remoteProtocol.getActionEntities(activityId);
// }
//
// }
//
// Path: dts-parent/dts-server-share/src/main/java/org/github/dtsopensource/server/share/exception/DTSRuntimeException.java
// public class DTSRuntimeException extends RuntimeException {
//
// private static final long serialVersionUID = 4328158740883926572L;
//
// /**
// * init DTSRuntimeException
// */
// public DTSRuntimeException() {
// super();
// }
//
// /**
// * init DTSRuntimeException
// *
// * @param message
// */
// public DTSRuntimeException(String message) {
// super(message);
// }
//
// /**
// * init DTSRuntimeException
// *
// * @param message
// * @param cause
// */
// public DTSRuntimeException(String message, Throwable cause) {
// super(message, cause);
// }
//
// /**
// * init DTSRuntimeException
// *
// * @param cause
// */
// public DTSRuntimeException(Throwable cause) {
// super(cause);
// }
//
// /**
// * init DTSRuntimeException
// *
// * @param message
// * @param cause
// * @param enableSuppression
// * @param writableStackTrace
// */
// public DTSRuntimeException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
// super(message, cause, enableSuppression, writableStackTrace);
// }
// }
//
// Path: dts-parent/dts-server-share/src/main/java/org/github/dtsopensource/server/share/store/IDTSStore.java
// public interface IDTSStore extends IDTS {
//
// /**
// * 开启事务
// *
// * @param activityEntity
// * @return
// */
// public ResultBase<DTSContext> openTransaction(ActivityEntity activityEntity);
//
// /**
// * @param actionEntity
// * @return
// */
// public ResultBase<String> getAndCreateAction(ActionEntity actionEntity);
//
// /**
// * 一阶commit时调用
// *
// * @param activityId
// * @return
// */
// public ResultBase<String> commitActivity(String activityId);
//
// /**
// * 一阶rollback时调用
// *
// * @param activityId
// * @return
// */
// public ResultBase<String> rollbackActivity(String activityId);
//
// /**
// * 更新action
// *
// * @param actionEntity
// * @return
// */
// public ResultBase<String> updateAction(ActionEntity actionEntity);
//
// }
| import org.github.dtsopensource.core.protocol.StoreProtocolManager;
import org.github.dtsopensource.core.store.impl.RemoteDTSStore;
import org.github.dtsopensource.server.share.exception.DTSRuntimeException;
import org.github.dtsopensource.server.share.store.IDTSStore;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
| package org.github.dtsopensource.core.manager;
/**
* @author ligaofeng 2016年12月3日 下午4:28:49
*/
@Slf4j
@Setter
public class RemoteDTSManager extends DTSManager {
private StoreProtocolManager remoteProtocol;
@Override
protected void check() {
if (remoteProtocol == null) {
throw new DTSRuntimeException("remote模式下必须指定IStoreProtocol协议");
}
log.info("--->RemoteDTSManager check ok");
}
@Override
| // Path: dts-parent/dts-core/src/main/java/org/github/dtsopensource/core/store/impl/RemoteDTSStore.java
// public class RemoteDTSStore implements IDTSStore {
//
// @Getter
// private final StoreProtocolManager remoteProtocol;
//
// /**
// * @param remoteProtocol
// */
// public RemoteDTSStore(StoreProtocolManager remoteProtocol) {
// this.remoteProtocol = remoteProtocol;
// }
//
// @Override
// public ResultBase<DTSContext> openTransaction(ActivityEntity activityEntity) {
// return remoteProtocol.openTransaction(activityEntity);
// }
//
// @Override
// public ResultBase<String> getAndCreateAction(ActionEntity actionEntity) {
// return remoteProtocol.getAndCreateAction(actionEntity);
// }
//
// @Override
// public ResultBase<String> updateAction(ActionEntity actionEntity) {
// return remoteProtocol.updateAction(actionEntity);
// }
//
// @Override
// public ResultBase<String> commitActivity(String activityId) {
// return remoteProtocol.commitActivity(activityId);
// }
//
// @Override
// public ResultBase<String> rollbackActivity(String activityId) {
// return remoteProtocol.rollbackActivity(activityId);
// }
//
// @Override
// public ResultBase<List<ActionEntity>> getActionEntities(String activityId) {
// return remoteProtocol.getActionEntities(activityId);
// }
//
// }
//
// Path: dts-parent/dts-server-share/src/main/java/org/github/dtsopensource/server/share/exception/DTSRuntimeException.java
// public class DTSRuntimeException extends RuntimeException {
//
// private static final long serialVersionUID = 4328158740883926572L;
//
// /**
// * init DTSRuntimeException
// */
// public DTSRuntimeException() {
// super();
// }
//
// /**
// * init DTSRuntimeException
// *
// * @param message
// */
// public DTSRuntimeException(String message) {
// super(message);
// }
//
// /**
// * init DTSRuntimeException
// *
// * @param message
// * @param cause
// */
// public DTSRuntimeException(String message, Throwable cause) {
// super(message, cause);
// }
//
// /**
// * init DTSRuntimeException
// *
// * @param cause
// */
// public DTSRuntimeException(Throwable cause) {
// super(cause);
// }
//
// /**
// * init DTSRuntimeException
// *
// * @param message
// * @param cause
// * @param enableSuppression
// * @param writableStackTrace
// */
// public DTSRuntimeException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
// super(message, cause, enableSuppression, writableStackTrace);
// }
// }
//
// Path: dts-parent/dts-server-share/src/main/java/org/github/dtsopensource/server/share/store/IDTSStore.java
// public interface IDTSStore extends IDTS {
//
// /**
// * 开启事务
// *
// * @param activityEntity
// * @return
// */
// public ResultBase<DTSContext> openTransaction(ActivityEntity activityEntity);
//
// /**
// * @param actionEntity
// * @return
// */
// public ResultBase<String> getAndCreateAction(ActionEntity actionEntity);
//
// /**
// * 一阶commit时调用
// *
// * @param activityId
// * @return
// */
// public ResultBase<String> commitActivity(String activityId);
//
// /**
// * 一阶rollback时调用
// *
// * @param activityId
// * @return
// */
// public ResultBase<String> rollbackActivity(String activityId);
//
// /**
// * 更新action
// *
// * @param actionEntity
// * @return
// */
// public ResultBase<String> updateAction(ActionEntity actionEntity);
//
// }
// Path: dts-parent/dts-core/src/main/java/org/github/dtsopensource/core/manager/RemoteDTSManager.java
import org.github.dtsopensource.core.protocol.StoreProtocolManager;
import org.github.dtsopensource.core.store.impl.RemoteDTSStore;
import org.github.dtsopensource.server.share.exception.DTSRuntimeException;
import org.github.dtsopensource.server.share.store.IDTSStore;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
package org.github.dtsopensource.core.manager;
/**
* @author ligaofeng 2016年12月3日 下午4:28:49
*/
@Slf4j
@Setter
public class RemoteDTSManager extends DTSManager {
private StoreProtocolManager remoteProtocol;
@Override
protected void check() {
if (remoteProtocol == null) {
throw new DTSRuntimeException("remote模式下必须指定IStoreProtocol协议");
}
log.info("--->RemoteDTSManager check ok");
}
@Override
| protected IDTSStore initStore() {
|
adealjason/dtsopensource | dts-parent/dts-core/src/main/java/org/github/dtsopensource/core/manager/RemoteDTSManager.java | // Path: dts-parent/dts-core/src/main/java/org/github/dtsopensource/core/store/impl/RemoteDTSStore.java
// public class RemoteDTSStore implements IDTSStore {
//
// @Getter
// private final StoreProtocolManager remoteProtocol;
//
// /**
// * @param remoteProtocol
// */
// public RemoteDTSStore(StoreProtocolManager remoteProtocol) {
// this.remoteProtocol = remoteProtocol;
// }
//
// @Override
// public ResultBase<DTSContext> openTransaction(ActivityEntity activityEntity) {
// return remoteProtocol.openTransaction(activityEntity);
// }
//
// @Override
// public ResultBase<String> getAndCreateAction(ActionEntity actionEntity) {
// return remoteProtocol.getAndCreateAction(actionEntity);
// }
//
// @Override
// public ResultBase<String> updateAction(ActionEntity actionEntity) {
// return remoteProtocol.updateAction(actionEntity);
// }
//
// @Override
// public ResultBase<String> commitActivity(String activityId) {
// return remoteProtocol.commitActivity(activityId);
// }
//
// @Override
// public ResultBase<String> rollbackActivity(String activityId) {
// return remoteProtocol.rollbackActivity(activityId);
// }
//
// @Override
// public ResultBase<List<ActionEntity>> getActionEntities(String activityId) {
// return remoteProtocol.getActionEntities(activityId);
// }
//
// }
//
// Path: dts-parent/dts-server-share/src/main/java/org/github/dtsopensource/server/share/exception/DTSRuntimeException.java
// public class DTSRuntimeException extends RuntimeException {
//
// private static final long serialVersionUID = 4328158740883926572L;
//
// /**
// * init DTSRuntimeException
// */
// public DTSRuntimeException() {
// super();
// }
//
// /**
// * init DTSRuntimeException
// *
// * @param message
// */
// public DTSRuntimeException(String message) {
// super(message);
// }
//
// /**
// * init DTSRuntimeException
// *
// * @param message
// * @param cause
// */
// public DTSRuntimeException(String message, Throwable cause) {
// super(message, cause);
// }
//
// /**
// * init DTSRuntimeException
// *
// * @param cause
// */
// public DTSRuntimeException(Throwable cause) {
// super(cause);
// }
//
// /**
// * init DTSRuntimeException
// *
// * @param message
// * @param cause
// * @param enableSuppression
// * @param writableStackTrace
// */
// public DTSRuntimeException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
// super(message, cause, enableSuppression, writableStackTrace);
// }
// }
//
// Path: dts-parent/dts-server-share/src/main/java/org/github/dtsopensource/server/share/store/IDTSStore.java
// public interface IDTSStore extends IDTS {
//
// /**
// * 开启事务
// *
// * @param activityEntity
// * @return
// */
// public ResultBase<DTSContext> openTransaction(ActivityEntity activityEntity);
//
// /**
// * @param actionEntity
// * @return
// */
// public ResultBase<String> getAndCreateAction(ActionEntity actionEntity);
//
// /**
// * 一阶commit时调用
// *
// * @param activityId
// * @return
// */
// public ResultBase<String> commitActivity(String activityId);
//
// /**
// * 一阶rollback时调用
// *
// * @param activityId
// * @return
// */
// public ResultBase<String> rollbackActivity(String activityId);
//
// /**
// * 更新action
// *
// * @param actionEntity
// * @return
// */
// public ResultBase<String> updateAction(ActionEntity actionEntity);
//
// }
| import org.github.dtsopensource.core.protocol.StoreProtocolManager;
import org.github.dtsopensource.core.store.impl.RemoteDTSStore;
import org.github.dtsopensource.server.share.exception.DTSRuntimeException;
import org.github.dtsopensource.server.share.store.IDTSStore;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
| package org.github.dtsopensource.core.manager;
/**
* @author ligaofeng 2016年12月3日 下午4:28:49
*/
@Slf4j
@Setter
public class RemoteDTSManager extends DTSManager {
private StoreProtocolManager remoteProtocol;
@Override
protected void check() {
if (remoteProtocol == null) {
throw new DTSRuntimeException("remote模式下必须指定IStoreProtocol协议");
}
log.info("--->RemoteDTSManager check ok");
}
@Override
protected IDTSStore initStore() {
| // Path: dts-parent/dts-core/src/main/java/org/github/dtsopensource/core/store/impl/RemoteDTSStore.java
// public class RemoteDTSStore implements IDTSStore {
//
// @Getter
// private final StoreProtocolManager remoteProtocol;
//
// /**
// * @param remoteProtocol
// */
// public RemoteDTSStore(StoreProtocolManager remoteProtocol) {
// this.remoteProtocol = remoteProtocol;
// }
//
// @Override
// public ResultBase<DTSContext> openTransaction(ActivityEntity activityEntity) {
// return remoteProtocol.openTransaction(activityEntity);
// }
//
// @Override
// public ResultBase<String> getAndCreateAction(ActionEntity actionEntity) {
// return remoteProtocol.getAndCreateAction(actionEntity);
// }
//
// @Override
// public ResultBase<String> updateAction(ActionEntity actionEntity) {
// return remoteProtocol.updateAction(actionEntity);
// }
//
// @Override
// public ResultBase<String> commitActivity(String activityId) {
// return remoteProtocol.commitActivity(activityId);
// }
//
// @Override
// public ResultBase<String> rollbackActivity(String activityId) {
// return remoteProtocol.rollbackActivity(activityId);
// }
//
// @Override
// public ResultBase<List<ActionEntity>> getActionEntities(String activityId) {
// return remoteProtocol.getActionEntities(activityId);
// }
//
// }
//
// Path: dts-parent/dts-server-share/src/main/java/org/github/dtsopensource/server/share/exception/DTSRuntimeException.java
// public class DTSRuntimeException extends RuntimeException {
//
// private static final long serialVersionUID = 4328158740883926572L;
//
// /**
// * init DTSRuntimeException
// */
// public DTSRuntimeException() {
// super();
// }
//
// /**
// * init DTSRuntimeException
// *
// * @param message
// */
// public DTSRuntimeException(String message) {
// super(message);
// }
//
// /**
// * init DTSRuntimeException
// *
// * @param message
// * @param cause
// */
// public DTSRuntimeException(String message, Throwable cause) {
// super(message, cause);
// }
//
// /**
// * init DTSRuntimeException
// *
// * @param cause
// */
// public DTSRuntimeException(Throwable cause) {
// super(cause);
// }
//
// /**
// * init DTSRuntimeException
// *
// * @param message
// * @param cause
// * @param enableSuppression
// * @param writableStackTrace
// */
// public DTSRuntimeException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
// super(message, cause, enableSuppression, writableStackTrace);
// }
// }
//
// Path: dts-parent/dts-server-share/src/main/java/org/github/dtsopensource/server/share/store/IDTSStore.java
// public interface IDTSStore extends IDTS {
//
// /**
// * 开启事务
// *
// * @param activityEntity
// * @return
// */
// public ResultBase<DTSContext> openTransaction(ActivityEntity activityEntity);
//
// /**
// * @param actionEntity
// * @return
// */
// public ResultBase<String> getAndCreateAction(ActionEntity actionEntity);
//
// /**
// * 一阶commit时调用
// *
// * @param activityId
// * @return
// */
// public ResultBase<String> commitActivity(String activityId);
//
// /**
// * 一阶rollback时调用
// *
// * @param activityId
// * @return
// */
// public ResultBase<String> rollbackActivity(String activityId);
//
// /**
// * 更新action
// *
// * @param actionEntity
// * @return
// */
// public ResultBase<String> updateAction(ActionEntity actionEntity);
//
// }
// Path: dts-parent/dts-core/src/main/java/org/github/dtsopensource/core/manager/RemoteDTSManager.java
import org.github.dtsopensource.core.protocol.StoreProtocolManager;
import org.github.dtsopensource.core.store.impl.RemoteDTSStore;
import org.github.dtsopensource.server.share.exception.DTSRuntimeException;
import org.github.dtsopensource.server.share.store.IDTSStore;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
package org.github.dtsopensource.core.manager;
/**
* @author ligaofeng 2016年12月3日 下午4:28:49
*/
@Slf4j
@Setter
public class RemoteDTSManager extends DTSManager {
private StoreProtocolManager remoteProtocol;
@Override
protected void check() {
if (remoteProtocol == null) {
throw new DTSRuntimeException("remote模式下必须指定IStoreProtocol协议");
}
log.info("--->RemoteDTSManager check ok");
}
@Override
protected IDTSStore initStore() {
| return new RemoteDTSStore(remoteProtocol);
|
adealjason/dtsopensource | dts-parent/dts-server-share/src/main/java/org/github/dtsopensource/server/share/DTSConfig.java | // Path: dts-parent/dts-server-share/src/main/java/org/github/dtsopensource/server/share/exception/DTSRuntimeException.java
// public class DTSRuntimeException extends RuntimeException {
//
// private static final long serialVersionUID = 4328158740883926572L;
//
// /**
// * init DTSRuntimeException
// */
// public DTSRuntimeException() {
// super();
// }
//
// /**
// * init DTSRuntimeException
// *
// * @param message
// */
// public DTSRuntimeException(String message) {
// super(message);
// }
//
// /**
// * init DTSRuntimeException
// *
// * @param message
// * @param cause
// */
// public DTSRuntimeException(String message, Throwable cause) {
// super(message, cause);
// }
//
// /**
// * init DTSRuntimeException
// *
// * @param cause
// */
// public DTSRuntimeException(Throwable cause) {
// super(cause);
// }
//
// /**
// * init DTSRuntimeException
// *
// * @param message
// * @param cause
// * @param enableSuppression
// * @param writableStackTrace
// */
// public DTSRuntimeException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
// super(message, cause, enableSuppression, writableStackTrace);
// }
// }
| import java.io.Serializable;
import javax.annotation.PostConstruct;
import org.github.dtsopensource.server.share.exception.DTSRuntimeException;
import com.alibaba.fastjson.JSON;
import lombok.Getter;
import lombok.Setter;
| package org.github.dtsopensource.server.share;
/**
* @author ligaofeng 2016年11月29日 上午11:30:46
*/
@Getter
@Setter
public class DTSConfig implements Serializable {
private static final long serialVersionUID = -2408123274907783162L;
private DTSManageType dtsManageType;
private String app;
//dts业务规则请求地址
private String requestActivityRuleURL;
@PostConstruct
public void checkConfig() {
if (dtsManageType == null) {
| // Path: dts-parent/dts-server-share/src/main/java/org/github/dtsopensource/server/share/exception/DTSRuntimeException.java
// public class DTSRuntimeException extends RuntimeException {
//
// private static final long serialVersionUID = 4328158740883926572L;
//
// /**
// * init DTSRuntimeException
// */
// public DTSRuntimeException() {
// super();
// }
//
// /**
// * init DTSRuntimeException
// *
// * @param message
// */
// public DTSRuntimeException(String message) {
// super(message);
// }
//
// /**
// * init DTSRuntimeException
// *
// * @param message
// * @param cause
// */
// public DTSRuntimeException(String message, Throwable cause) {
// super(message, cause);
// }
//
// /**
// * init DTSRuntimeException
// *
// * @param cause
// */
// public DTSRuntimeException(Throwable cause) {
// super(cause);
// }
//
// /**
// * init DTSRuntimeException
// *
// * @param message
// * @param cause
// * @param enableSuppression
// * @param writableStackTrace
// */
// public DTSRuntimeException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
// super(message, cause, enableSuppression, writableStackTrace);
// }
// }
// Path: dts-parent/dts-server-share/src/main/java/org/github/dtsopensource/server/share/DTSConfig.java
import java.io.Serializable;
import javax.annotation.PostConstruct;
import org.github.dtsopensource.server.share.exception.DTSRuntimeException;
import com.alibaba.fastjson.JSON;
import lombok.Getter;
import lombok.Setter;
package org.github.dtsopensource.server.share;
/**
* @author ligaofeng 2016年11月29日 上午11:30:46
*/
@Getter
@Setter
public class DTSConfig implements Serializable {
private static final long serialVersionUID = -2408123274907783162L;
private DTSManageType dtsManageType;
private String app;
//dts业务规则请求地址
private String requestActivityRuleURL;
@PostConstruct
public void checkConfig() {
if (dtsManageType == null) {
| throw new DTSRuntimeException("dts连接方式dtsManageType未定义");
|
adealjason/dtsopensource | dts-parent/dts-server/src/main/java/org/github/dtsopensource/server/rule/HttpServerRuleProtocol.java | // Path: dts-parent/dts-server-share/src/main/java/org/github/dtsopensource/server/share/ResultBase.java
// @Data
// public class ResultBase<T> implements Serializable {
//
// private static final long serialVersionUID = 2297155012372998859L;
//
// private DTSResultCode dtsResultCode;
//
// private String message;
//
// private T value;
//
// /**
// * @return
// */
// public boolean isSucess() {
// return DTSResultCode.SUCCESS == this.getDtsResultCode();
// }
//
// /**
// * @param errorMessage
// */
// public void addMessage(String errorMessage) {
// if (message != null && message.trim().length() > 0) {
// message = message.concat("|").concat(errorMessage);
// } else {
// message = errorMessage;
// }
// }
// }
//
// Path: dts-parent/dts-server-share/src/main/java/org/github/dtsopensource/server/share/rule/IDTSRule.java
// public interface IDTSRule {
//
// /**
// * 校验业务规则
// *
// * @param bizType
// * @return
// */
// public ResultBase<ActivityRuleEntity> checkBizType(String bizType);
//
// /**
// * 获取该业务规则的配置信息<br>
// * 返回业务action的配置
// *
// * @param bizType
// * @return
// */
// public ResultBase<ActivityRuleEntity> getBizTypeRule(String bizType);
//
// }
//
// Path: dts-parent/dts-server-share/src/main/java/org/github/dtsopensource/server/share/rule/entity/ActivityRuleEntity.java
// @Getter
// @Setter
// public class ActivityRuleEntity implements Serializable {
//
// private static final long serialVersionUID = 106899067427742570L;
//
// private String bizType;
//
// private String bizTypeName;
//
// private String app;
//
// private String appCname;
//
// private List<ActivityActionRuleEntity> activityActionRules;
//
// /**
// * 根据clazzName获取bizAction配置
// *
// * @param clazzName dts-server配置的信息
// * @return
// */
// public ActivityActionRuleEntity getActivityActionRuleEntity(String clazzName) {
// if (activityActionRules == null || activityActionRules.isEmpty()) {
// throw new DTSRuntimeException("尚未配置" + clazzName + "的bizAction,请联系dts-server管理员配置");
// }
// for (ActivityActionRuleEntity an : activityActionRules) {
// if (an.getClazzName().equals(clazzName)) {
// return an;
// }
// }
// throw new DTSRuntimeException("尚未配置" + clazzName + "的bizAction,请联系dts-server管理员配置");
// }
//
// @Override
// public String toString() {
// return JSON.toJSONString(this);
// }
//
// /**
// * ActivityRuleEntity.builder
// *
// * @param builder
// */
// public ActivityRuleEntity(Builder builder) {
// this.app = builder.app;
// this.appCname = builder.appCname;
// this.bizType = builder.bizType;
// this.bizTypeName = builder.bizTypeName;
// }
//
// /**
// * used for fastjson
// */
// public ActivityRuleEntity() {
// }
//
// @Getter
// public static class Builder {
// private String bizType;
//
// private String bizTypeName;
//
// private String app;
//
// private String appCname;
//
// public Builder(String bizType) {
// this.bizType = bizType;
// }
//
// public Builder setBizTypeName(String bizTypeName) {
// this.bizTypeName = bizTypeName;
// return this;
// }
//
// public Builder setApp(String app) {
// this.app = app;
// return this;
// }
//
// public Builder setAppCname(String appCname) {
// this.appCname = appCname;
// return this;
// }
//
// public ActivityRuleEntity build() {
// return new ActivityRuleEntity(this);
// }
// }
//
// }
| import javax.annotation.Resource;
import org.github.dtsopensource.server.share.ResultBase;
import org.github.dtsopensource.server.share.rule.IDTSRule;
import org.github.dtsopensource.server.share.rule.entity.ActivityRuleEntity;
import org.springframework.stereotype.Service;
| package org.github.dtsopensource.server.rule;
/**
* @author ligaofeng 2016年12月16日 下午3:49:47
*/
@Service
public class HttpServerRuleProtocol implements IDTSRule {
@Resource
private IDTSRule localDTSRule;
@Override
| // Path: dts-parent/dts-server-share/src/main/java/org/github/dtsopensource/server/share/ResultBase.java
// @Data
// public class ResultBase<T> implements Serializable {
//
// private static final long serialVersionUID = 2297155012372998859L;
//
// private DTSResultCode dtsResultCode;
//
// private String message;
//
// private T value;
//
// /**
// * @return
// */
// public boolean isSucess() {
// return DTSResultCode.SUCCESS == this.getDtsResultCode();
// }
//
// /**
// * @param errorMessage
// */
// public void addMessage(String errorMessage) {
// if (message != null && message.trim().length() > 0) {
// message = message.concat("|").concat(errorMessage);
// } else {
// message = errorMessage;
// }
// }
// }
//
// Path: dts-parent/dts-server-share/src/main/java/org/github/dtsopensource/server/share/rule/IDTSRule.java
// public interface IDTSRule {
//
// /**
// * 校验业务规则
// *
// * @param bizType
// * @return
// */
// public ResultBase<ActivityRuleEntity> checkBizType(String bizType);
//
// /**
// * 获取该业务规则的配置信息<br>
// * 返回业务action的配置
// *
// * @param bizType
// * @return
// */
// public ResultBase<ActivityRuleEntity> getBizTypeRule(String bizType);
//
// }
//
// Path: dts-parent/dts-server-share/src/main/java/org/github/dtsopensource/server/share/rule/entity/ActivityRuleEntity.java
// @Getter
// @Setter
// public class ActivityRuleEntity implements Serializable {
//
// private static final long serialVersionUID = 106899067427742570L;
//
// private String bizType;
//
// private String bizTypeName;
//
// private String app;
//
// private String appCname;
//
// private List<ActivityActionRuleEntity> activityActionRules;
//
// /**
// * 根据clazzName获取bizAction配置
// *
// * @param clazzName dts-server配置的信息
// * @return
// */
// public ActivityActionRuleEntity getActivityActionRuleEntity(String clazzName) {
// if (activityActionRules == null || activityActionRules.isEmpty()) {
// throw new DTSRuntimeException("尚未配置" + clazzName + "的bizAction,请联系dts-server管理员配置");
// }
// for (ActivityActionRuleEntity an : activityActionRules) {
// if (an.getClazzName().equals(clazzName)) {
// return an;
// }
// }
// throw new DTSRuntimeException("尚未配置" + clazzName + "的bizAction,请联系dts-server管理员配置");
// }
//
// @Override
// public String toString() {
// return JSON.toJSONString(this);
// }
//
// /**
// * ActivityRuleEntity.builder
// *
// * @param builder
// */
// public ActivityRuleEntity(Builder builder) {
// this.app = builder.app;
// this.appCname = builder.appCname;
// this.bizType = builder.bizType;
// this.bizTypeName = builder.bizTypeName;
// }
//
// /**
// * used for fastjson
// */
// public ActivityRuleEntity() {
// }
//
// @Getter
// public static class Builder {
// private String bizType;
//
// private String bizTypeName;
//
// private String app;
//
// private String appCname;
//
// public Builder(String bizType) {
// this.bizType = bizType;
// }
//
// public Builder setBizTypeName(String bizTypeName) {
// this.bizTypeName = bizTypeName;
// return this;
// }
//
// public Builder setApp(String app) {
// this.app = app;
// return this;
// }
//
// public Builder setAppCname(String appCname) {
// this.appCname = appCname;
// return this;
// }
//
// public ActivityRuleEntity build() {
// return new ActivityRuleEntity(this);
// }
// }
//
// }
// Path: dts-parent/dts-server/src/main/java/org/github/dtsopensource/server/rule/HttpServerRuleProtocol.java
import javax.annotation.Resource;
import org.github.dtsopensource.server.share.ResultBase;
import org.github.dtsopensource.server.share.rule.IDTSRule;
import org.github.dtsopensource.server.share.rule.entity.ActivityRuleEntity;
import org.springframework.stereotype.Service;
package org.github.dtsopensource.server.rule;
/**
* @author ligaofeng 2016年12月16日 下午3:49:47
*/
@Service
public class HttpServerRuleProtocol implements IDTSRule {
@Resource
private IDTSRule localDTSRule;
@Override
| public ResultBase<ActivityRuleEntity> checkBizType(String bizType) {
|
adealjason/dtsopensource | dts-parent/dts-server/src/main/java/org/github/dtsopensource/server/rule/HttpServerRuleProtocol.java | // Path: dts-parent/dts-server-share/src/main/java/org/github/dtsopensource/server/share/ResultBase.java
// @Data
// public class ResultBase<T> implements Serializable {
//
// private static final long serialVersionUID = 2297155012372998859L;
//
// private DTSResultCode dtsResultCode;
//
// private String message;
//
// private T value;
//
// /**
// * @return
// */
// public boolean isSucess() {
// return DTSResultCode.SUCCESS == this.getDtsResultCode();
// }
//
// /**
// * @param errorMessage
// */
// public void addMessage(String errorMessage) {
// if (message != null && message.trim().length() > 0) {
// message = message.concat("|").concat(errorMessage);
// } else {
// message = errorMessage;
// }
// }
// }
//
// Path: dts-parent/dts-server-share/src/main/java/org/github/dtsopensource/server/share/rule/IDTSRule.java
// public interface IDTSRule {
//
// /**
// * 校验业务规则
// *
// * @param bizType
// * @return
// */
// public ResultBase<ActivityRuleEntity> checkBizType(String bizType);
//
// /**
// * 获取该业务规则的配置信息<br>
// * 返回业务action的配置
// *
// * @param bizType
// * @return
// */
// public ResultBase<ActivityRuleEntity> getBizTypeRule(String bizType);
//
// }
//
// Path: dts-parent/dts-server-share/src/main/java/org/github/dtsopensource/server/share/rule/entity/ActivityRuleEntity.java
// @Getter
// @Setter
// public class ActivityRuleEntity implements Serializable {
//
// private static final long serialVersionUID = 106899067427742570L;
//
// private String bizType;
//
// private String bizTypeName;
//
// private String app;
//
// private String appCname;
//
// private List<ActivityActionRuleEntity> activityActionRules;
//
// /**
// * 根据clazzName获取bizAction配置
// *
// * @param clazzName dts-server配置的信息
// * @return
// */
// public ActivityActionRuleEntity getActivityActionRuleEntity(String clazzName) {
// if (activityActionRules == null || activityActionRules.isEmpty()) {
// throw new DTSRuntimeException("尚未配置" + clazzName + "的bizAction,请联系dts-server管理员配置");
// }
// for (ActivityActionRuleEntity an : activityActionRules) {
// if (an.getClazzName().equals(clazzName)) {
// return an;
// }
// }
// throw new DTSRuntimeException("尚未配置" + clazzName + "的bizAction,请联系dts-server管理员配置");
// }
//
// @Override
// public String toString() {
// return JSON.toJSONString(this);
// }
//
// /**
// * ActivityRuleEntity.builder
// *
// * @param builder
// */
// public ActivityRuleEntity(Builder builder) {
// this.app = builder.app;
// this.appCname = builder.appCname;
// this.bizType = builder.bizType;
// this.bizTypeName = builder.bizTypeName;
// }
//
// /**
// * used for fastjson
// */
// public ActivityRuleEntity() {
// }
//
// @Getter
// public static class Builder {
// private String bizType;
//
// private String bizTypeName;
//
// private String app;
//
// private String appCname;
//
// public Builder(String bizType) {
// this.bizType = bizType;
// }
//
// public Builder setBizTypeName(String bizTypeName) {
// this.bizTypeName = bizTypeName;
// return this;
// }
//
// public Builder setApp(String app) {
// this.app = app;
// return this;
// }
//
// public Builder setAppCname(String appCname) {
// this.appCname = appCname;
// return this;
// }
//
// public ActivityRuleEntity build() {
// return new ActivityRuleEntity(this);
// }
// }
//
// }
| import javax.annotation.Resource;
import org.github.dtsopensource.server.share.ResultBase;
import org.github.dtsopensource.server.share.rule.IDTSRule;
import org.github.dtsopensource.server.share.rule.entity.ActivityRuleEntity;
import org.springframework.stereotype.Service;
| package org.github.dtsopensource.server.rule;
/**
* @author ligaofeng 2016年12月16日 下午3:49:47
*/
@Service
public class HttpServerRuleProtocol implements IDTSRule {
@Resource
private IDTSRule localDTSRule;
@Override
| // Path: dts-parent/dts-server-share/src/main/java/org/github/dtsopensource/server/share/ResultBase.java
// @Data
// public class ResultBase<T> implements Serializable {
//
// private static final long serialVersionUID = 2297155012372998859L;
//
// private DTSResultCode dtsResultCode;
//
// private String message;
//
// private T value;
//
// /**
// * @return
// */
// public boolean isSucess() {
// return DTSResultCode.SUCCESS == this.getDtsResultCode();
// }
//
// /**
// * @param errorMessage
// */
// public void addMessage(String errorMessage) {
// if (message != null && message.trim().length() > 0) {
// message = message.concat("|").concat(errorMessage);
// } else {
// message = errorMessage;
// }
// }
// }
//
// Path: dts-parent/dts-server-share/src/main/java/org/github/dtsopensource/server/share/rule/IDTSRule.java
// public interface IDTSRule {
//
// /**
// * 校验业务规则
// *
// * @param bizType
// * @return
// */
// public ResultBase<ActivityRuleEntity> checkBizType(String bizType);
//
// /**
// * 获取该业务规则的配置信息<br>
// * 返回业务action的配置
// *
// * @param bizType
// * @return
// */
// public ResultBase<ActivityRuleEntity> getBizTypeRule(String bizType);
//
// }
//
// Path: dts-parent/dts-server-share/src/main/java/org/github/dtsopensource/server/share/rule/entity/ActivityRuleEntity.java
// @Getter
// @Setter
// public class ActivityRuleEntity implements Serializable {
//
// private static final long serialVersionUID = 106899067427742570L;
//
// private String bizType;
//
// private String bizTypeName;
//
// private String app;
//
// private String appCname;
//
// private List<ActivityActionRuleEntity> activityActionRules;
//
// /**
// * 根据clazzName获取bizAction配置
// *
// * @param clazzName dts-server配置的信息
// * @return
// */
// public ActivityActionRuleEntity getActivityActionRuleEntity(String clazzName) {
// if (activityActionRules == null || activityActionRules.isEmpty()) {
// throw new DTSRuntimeException("尚未配置" + clazzName + "的bizAction,请联系dts-server管理员配置");
// }
// for (ActivityActionRuleEntity an : activityActionRules) {
// if (an.getClazzName().equals(clazzName)) {
// return an;
// }
// }
// throw new DTSRuntimeException("尚未配置" + clazzName + "的bizAction,请联系dts-server管理员配置");
// }
//
// @Override
// public String toString() {
// return JSON.toJSONString(this);
// }
//
// /**
// * ActivityRuleEntity.builder
// *
// * @param builder
// */
// public ActivityRuleEntity(Builder builder) {
// this.app = builder.app;
// this.appCname = builder.appCname;
// this.bizType = builder.bizType;
// this.bizTypeName = builder.bizTypeName;
// }
//
// /**
// * used for fastjson
// */
// public ActivityRuleEntity() {
// }
//
// @Getter
// public static class Builder {
// private String bizType;
//
// private String bizTypeName;
//
// private String app;
//
// private String appCname;
//
// public Builder(String bizType) {
// this.bizType = bizType;
// }
//
// public Builder setBizTypeName(String bizTypeName) {
// this.bizTypeName = bizTypeName;
// return this;
// }
//
// public Builder setApp(String app) {
// this.app = app;
// return this;
// }
//
// public Builder setAppCname(String appCname) {
// this.appCname = appCname;
// return this;
// }
//
// public ActivityRuleEntity build() {
// return new ActivityRuleEntity(this);
// }
// }
//
// }
// Path: dts-parent/dts-server/src/main/java/org/github/dtsopensource/server/rule/HttpServerRuleProtocol.java
import javax.annotation.Resource;
import org.github.dtsopensource.server.share.ResultBase;
import org.github.dtsopensource.server.share.rule.IDTSRule;
import org.github.dtsopensource.server.share.rule.entity.ActivityRuleEntity;
import org.springframework.stereotype.Service;
package org.github.dtsopensource.server.rule;
/**
* @author ligaofeng 2016年12月16日 下午3:49:47
*/
@Service
public class HttpServerRuleProtocol implements IDTSRule {
@Resource
private IDTSRule localDTSRule;
@Override
| public ResultBase<ActivityRuleEntity> checkBizType(String bizType) {
|
adealjason/dtsopensource | dts-parent/dts-core/src/main/java/org/github/dtsopensource/core/manager/LocalDTSManager.java | // Path: dts-parent/dts-server-share/src/main/java/org/github/dtsopensource/server/share/exception/DTSRuntimeException.java
// public class DTSRuntimeException extends RuntimeException {
//
// private static final long serialVersionUID = 4328158740883926572L;
//
// /**
// * init DTSRuntimeException
// */
// public DTSRuntimeException() {
// super();
// }
//
// /**
// * init DTSRuntimeException
// *
// * @param message
// */
// public DTSRuntimeException(String message) {
// super(message);
// }
//
// /**
// * init DTSRuntimeException
// *
// * @param message
// * @param cause
// */
// public DTSRuntimeException(String message, Throwable cause) {
// super(message, cause);
// }
//
// /**
// * init DTSRuntimeException
// *
// * @param cause
// */
// public DTSRuntimeException(Throwable cause) {
// super(cause);
// }
//
// /**
// * init DTSRuntimeException
// *
// * @param message
// * @param cause
// * @param enableSuppression
// * @param writableStackTrace
// */
// public DTSRuntimeException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
// super(message, cause, enableSuppression, writableStackTrace);
// }
// }
//
// Path: dts-parent/dts-server-share/src/main/java/org/github/dtsopensource/server/share/store/IDTSStore.java
// public interface IDTSStore extends IDTS {
//
// /**
// * 开启事务
// *
// * @param activityEntity
// * @return
// */
// public ResultBase<DTSContext> openTransaction(ActivityEntity activityEntity);
//
// /**
// * @param actionEntity
// * @return
// */
// public ResultBase<String> getAndCreateAction(ActionEntity actionEntity);
//
// /**
// * 一阶commit时调用
// *
// * @param activityId
// * @return
// */
// public ResultBase<String> commitActivity(String activityId);
//
// /**
// * 一阶rollback时调用
// *
// * @param activityId
// * @return
// */
// public ResultBase<String> rollbackActivity(String activityId);
//
// /**
// * 更新action
// *
// * @param actionEntity
// * @return
// */
// public ResultBase<String> updateAction(ActionEntity actionEntity);
//
// }
| import javax.sql.DataSource;
import org.github.dtsopensource.core.store.impl.LocalDTSStore;
import org.github.dtsopensource.server.share.exception.DTSRuntimeException;
import org.github.dtsopensource.server.share.store.IDTSStore;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import org.springframework.transaction.TransactionDefinition;
import org.springframework.transaction.support.TransactionTemplate;
import lombok.Setter;
import lombok.ToString;
import lombok.extern.slf4j.Slf4j;
| package org.github.dtsopensource.core.manager;
/**
* Created by ligaofeng on 2016/10/31.
*/
@Slf4j
@ToString
public class LocalDTSManager extends DTSManager {
@Setter
private DataSource dataSource;
private JdbcTemplate jdbcTemplate;
private TransactionTemplate transactionTemplate;
@Override
protected void check() {
if (dataSource == null) {
| // Path: dts-parent/dts-server-share/src/main/java/org/github/dtsopensource/server/share/exception/DTSRuntimeException.java
// public class DTSRuntimeException extends RuntimeException {
//
// private static final long serialVersionUID = 4328158740883926572L;
//
// /**
// * init DTSRuntimeException
// */
// public DTSRuntimeException() {
// super();
// }
//
// /**
// * init DTSRuntimeException
// *
// * @param message
// */
// public DTSRuntimeException(String message) {
// super(message);
// }
//
// /**
// * init DTSRuntimeException
// *
// * @param message
// * @param cause
// */
// public DTSRuntimeException(String message, Throwable cause) {
// super(message, cause);
// }
//
// /**
// * init DTSRuntimeException
// *
// * @param cause
// */
// public DTSRuntimeException(Throwable cause) {
// super(cause);
// }
//
// /**
// * init DTSRuntimeException
// *
// * @param message
// * @param cause
// * @param enableSuppression
// * @param writableStackTrace
// */
// public DTSRuntimeException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
// super(message, cause, enableSuppression, writableStackTrace);
// }
// }
//
// Path: dts-parent/dts-server-share/src/main/java/org/github/dtsopensource/server/share/store/IDTSStore.java
// public interface IDTSStore extends IDTS {
//
// /**
// * 开启事务
// *
// * @param activityEntity
// * @return
// */
// public ResultBase<DTSContext> openTransaction(ActivityEntity activityEntity);
//
// /**
// * @param actionEntity
// * @return
// */
// public ResultBase<String> getAndCreateAction(ActionEntity actionEntity);
//
// /**
// * 一阶commit时调用
// *
// * @param activityId
// * @return
// */
// public ResultBase<String> commitActivity(String activityId);
//
// /**
// * 一阶rollback时调用
// *
// * @param activityId
// * @return
// */
// public ResultBase<String> rollbackActivity(String activityId);
//
// /**
// * 更新action
// *
// * @param actionEntity
// * @return
// */
// public ResultBase<String> updateAction(ActionEntity actionEntity);
//
// }
// Path: dts-parent/dts-core/src/main/java/org/github/dtsopensource/core/manager/LocalDTSManager.java
import javax.sql.DataSource;
import org.github.dtsopensource.core.store.impl.LocalDTSStore;
import org.github.dtsopensource.server.share.exception.DTSRuntimeException;
import org.github.dtsopensource.server.share.store.IDTSStore;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import org.springframework.transaction.TransactionDefinition;
import org.springframework.transaction.support.TransactionTemplate;
import lombok.Setter;
import lombok.ToString;
import lombok.extern.slf4j.Slf4j;
package org.github.dtsopensource.core.manager;
/**
* Created by ligaofeng on 2016/10/31.
*/
@Slf4j
@ToString
public class LocalDTSManager extends DTSManager {
@Setter
private DataSource dataSource;
private JdbcTemplate jdbcTemplate;
private TransactionTemplate transactionTemplate;
@Override
protected void check() {
if (dataSource == null) {
| throw new DTSRuntimeException("local模式下必须指定DataSource数据源");
|
adealjason/dtsopensource | dts-parent/dts-core/src/main/java/org/github/dtsopensource/core/manager/LocalDTSManager.java | // Path: dts-parent/dts-server-share/src/main/java/org/github/dtsopensource/server/share/exception/DTSRuntimeException.java
// public class DTSRuntimeException extends RuntimeException {
//
// private static final long serialVersionUID = 4328158740883926572L;
//
// /**
// * init DTSRuntimeException
// */
// public DTSRuntimeException() {
// super();
// }
//
// /**
// * init DTSRuntimeException
// *
// * @param message
// */
// public DTSRuntimeException(String message) {
// super(message);
// }
//
// /**
// * init DTSRuntimeException
// *
// * @param message
// * @param cause
// */
// public DTSRuntimeException(String message, Throwable cause) {
// super(message, cause);
// }
//
// /**
// * init DTSRuntimeException
// *
// * @param cause
// */
// public DTSRuntimeException(Throwable cause) {
// super(cause);
// }
//
// /**
// * init DTSRuntimeException
// *
// * @param message
// * @param cause
// * @param enableSuppression
// * @param writableStackTrace
// */
// public DTSRuntimeException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
// super(message, cause, enableSuppression, writableStackTrace);
// }
// }
//
// Path: dts-parent/dts-server-share/src/main/java/org/github/dtsopensource/server/share/store/IDTSStore.java
// public interface IDTSStore extends IDTS {
//
// /**
// * 开启事务
// *
// * @param activityEntity
// * @return
// */
// public ResultBase<DTSContext> openTransaction(ActivityEntity activityEntity);
//
// /**
// * @param actionEntity
// * @return
// */
// public ResultBase<String> getAndCreateAction(ActionEntity actionEntity);
//
// /**
// * 一阶commit时调用
// *
// * @param activityId
// * @return
// */
// public ResultBase<String> commitActivity(String activityId);
//
// /**
// * 一阶rollback时调用
// *
// * @param activityId
// * @return
// */
// public ResultBase<String> rollbackActivity(String activityId);
//
// /**
// * 更新action
// *
// * @param actionEntity
// * @return
// */
// public ResultBase<String> updateAction(ActionEntity actionEntity);
//
// }
| import javax.sql.DataSource;
import org.github.dtsopensource.core.store.impl.LocalDTSStore;
import org.github.dtsopensource.server.share.exception.DTSRuntimeException;
import org.github.dtsopensource.server.share.store.IDTSStore;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import org.springframework.transaction.TransactionDefinition;
import org.springframework.transaction.support.TransactionTemplate;
import lombok.Setter;
import lombok.ToString;
import lombok.extern.slf4j.Slf4j;
| package org.github.dtsopensource.core.manager;
/**
* Created by ligaofeng on 2016/10/31.
*/
@Slf4j
@ToString
public class LocalDTSManager extends DTSManager {
@Setter
private DataSource dataSource;
private JdbcTemplate jdbcTemplate;
private TransactionTemplate transactionTemplate;
@Override
protected void check() {
if (dataSource == null) {
throw new DTSRuntimeException("local模式下必须指定DataSource数据源");
}
log.info("--->LocalDTSManager check ok...");
}
@Override
| // Path: dts-parent/dts-server-share/src/main/java/org/github/dtsopensource/server/share/exception/DTSRuntimeException.java
// public class DTSRuntimeException extends RuntimeException {
//
// private static final long serialVersionUID = 4328158740883926572L;
//
// /**
// * init DTSRuntimeException
// */
// public DTSRuntimeException() {
// super();
// }
//
// /**
// * init DTSRuntimeException
// *
// * @param message
// */
// public DTSRuntimeException(String message) {
// super(message);
// }
//
// /**
// * init DTSRuntimeException
// *
// * @param message
// * @param cause
// */
// public DTSRuntimeException(String message, Throwable cause) {
// super(message, cause);
// }
//
// /**
// * init DTSRuntimeException
// *
// * @param cause
// */
// public DTSRuntimeException(Throwable cause) {
// super(cause);
// }
//
// /**
// * init DTSRuntimeException
// *
// * @param message
// * @param cause
// * @param enableSuppression
// * @param writableStackTrace
// */
// public DTSRuntimeException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
// super(message, cause, enableSuppression, writableStackTrace);
// }
// }
//
// Path: dts-parent/dts-server-share/src/main/java/org/github/dtsopensource/server/share/store/IDTSStore.java
// public interface IDTSStore extends IDTS {
//
// /**
// * 开启事务
// *
// * @param activityEntity
// * @return
// */
// public ResultBase<DTSContext> openTransaction(ActivityEntity activityEntity);
//
// /**
// * @param actionEntity
// * @return
// */
// public ResultBase<String> getAndCreateAction(ActionEntity actionEntity);
//
// /**
// * 一阶commit时调用
// *
// * @param activityId
// * @return
// */
// public ResultBase<String> commitActivity(String activityId);
//
// /**
// * 一阶rollback时调用
// *
// * @param activityId
// * @return
// */
// public ResultBase<String> rollbackActivity(String activityId);
//
// /**
// * 更新action
// *
// * @param actionEntity
// * @return
// */
// public ResultBase<String> updateAction(ActionEntity actionEntity);
//
// }
// Path: dts-parent/dts-core/src/main/java/org/github/dtsopensource/core/manager/LocalDTSManager.java
import javax.sql.DataSource;
import org.github.dtsopensource.core.store.impl.LocalDTSStore;
import org.github.dtsopensource.server.share.exception.DTSRuntimeException;
import org.github.dtsopensource.server.share.store.IDTSStore;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import org.springframework.transaction.TransactionDefinition;
import org.springframework.transaction.support.TransactionTemplate;
import lombok.Setter;
import lombok.ToString;
import lombok.extern.slf4j.Slf4j;
package org.github.dtsopensource.core.manager;
/**
* Created by ligaofeng on 2016/10/31.
*/
@Slf4j
@ToString
public class LocalDTSManager extends DTSManager {
@Setter
private DataSource dataSource;
private JdbcTemplate jdbcTemplate;
private TransactionTemplate transactionTemplate;
@Override
protected void check() {
if (dataSource == null) {
throw new DTSRuntimeException("local模式下必须指定DataSource数据源");
}
log.info("--->LocalDTSManager check ok...");
}
@Override
| public IDTSStore initStore() {
|
adealjason/dtsopensource | dts-parent/dts-core/src/main/java/org/github/dtsopensource/core/protocol/http/protocol/impl/HttpProtocolTemplate.java | // Path: dts-parent/dts-server-share/src/main/java/org/github/dtsopensource/server/share/exception/DTSBizException.java
// public class DTSBizException extends Exception {
//
// private static final long serialVersionUID = 3473398255173602638L;
//
// /**
// * init BizException
// */
// public DTSBizException() {
// super();
// }
//
// /**
// * init BizException
// *
// * @param message
// */
// public DTSBizException(String message) {
// super(message);
// }
//
// /**
// * init BizException
// *
// * @param message
// * @param cause
// */
// public DTSBizException(String message, Throwable cause) {
// super(message, cause);
// }
//
// /**
// * init BizException
// *
// * @param cause
// */
// public DTSBizException(Throwable cause) {
// super(cause);
// }
//
// /**
// * init BizException
// *
// * @param message
// * @param cause
// * @param enableSuppression
// * @param writableStackTrace
// */
// public DTSBizException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
// super(message, cause, enableSuppression, writableStackTrace);
// }
// }
| import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import org.apache.http.HttpEntity;
import org.apache.http.NameValuePair;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.methods.HttpRequestBase;
import org.apache.http.client.protocol.HttpClientContext;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;
import org.github.dtsopensource.server.share.exception.DTSBizException;
import org.github.dtsopensource.server.share.protocol.ProtocolConstance;
import com.alibaba.fastjson.JSON;
import lombok.extern.slf4j.Slf4j;
| package org.github.dtsopensource.core.protocol.http.protocol.impl;
/**
* http 请求模板
*
* @author ligaofeng 2016年12月12日 下午7:08:40
*/
@Slf4j
public class HttpProtocolTemplate {
private String serverURL;
//超时时间
private int timeOut;
private final CloseableHttpClient httpClient;
public HttpProtocolTemplate(String serverURL, int timeOut, CloseableHttpClient httpClient) {
this.serverURL = serverURL;
this.timeOut = timeOut;
this.httpClient = httpClient;
}
| // Path: dts-parent/dts-server-share/src/main/java/org/github/dtsopensource/server/share/exception/DTSBizException.java
// public class DTSBizException extends Exception {
//
// private static final long serialVersionUID = 3473398255173602638L;
//
// /**
// * init BizException
// */
// public DTSBizException() {
// super();
// }
//
// /**
// * init BizException
// *
// * @param message
// */
// public DTSBizException(String message) {
// super(message);
// }
//
// /**
// * init BizException
// *
// * @param message
// * @param cause
// */
// public DTSBizException(String message, Throwable cause) {
// super(message, cause);
// }
//
// /**
// * init BizException
// *
// * @param cause
// */
// public DTSBizException(Throwable cause) {
// super(cause);
// }
//
// /**
// * init BizException
// *
// * @param message
// * @param cause
// * @param enableSuppression
// * @param writableStackTrace
// */
// public DTSBizException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
// super(message, cause, enableSuppression, writableStackTrace);
// }
// }
// Path: dts-parent/dts-core/src/main/java/org/github/dtsopensource/core/protocol/http/protocol/impl/HttpProtocolTemplate.java
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import org.apache.http.HttpEntity;
import org.apache.http.NameValuePair;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.methods.HttpRequestBase;
import org.apache.http.client.protocol.HttpClientContext;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;
import org.github.dtsopensource.server.share.exception.DTSBizException;
import org.github.dtsopensource.server.share.protocol.ProtocolConstance;
import com.alibaba.fastjson.JSON;
import lombok.extern.slf4j.Slf4j;
package org.github.dtsopensource.core.protocol.http.protocol.impl;
/**
* http 请求模板
*
* @author ligaofeng 2016年12月12日 下午7:08:40
*/
@Slf4j
public class HttpProtocolTemplate {
private String serverURL;
//超时时间
private int timeOut;
private final CloseableHttpClient httpClient;
public HttpProtocolTemplate(String serverURL, int timeOut, CloseableHttpClient httpClient) {
this.serverURL = serverURL;
this.timeOut = timeOut;
this.httpClient = httpClient;
}
| public String execute(HttpProtoclCallback httpCallback) throws DTSBizException {
|
adealjason/dtsopensource | dts-parent/dts-server-share/src/main/java/org/github/dtsopensource/server/share/store/Status.java | // Path: dts-parent/dts-server-share/src/main/java/org/github/dtsopensource/server/share/exception/DTSRuntimeException.java
// public class DTSRuntimeException extends RuntimeException {
//
// private static final long serialVersionUID = 4328158740883926572L;
//
// /**
// * init DTSRuntimeException
// */
// public DTSRuntimeException() {
// super();
// }
//
// /**
// * init DTSRuntimeException
// *
// * @param message
// */
// public DTSRuntimeException(String message) {
// super(message);
// }
//
// /**
// * init DTSRuntimeException
// *
// * @param message
// * @param cause
// */
// public DTSRuntimeException(String message, Throwable cause) {
// super(message, cause);
// }
//
// /**
// * init DTSRuntimeException
// *
// * @param cause
// */
// public DTSRuntimeException(Throwable cause) {
// super(cause);
// }
//
// /**
// * init DTSRuntimeException
// *
// * @param message
// * @param cause
// * @param enableSuppression
// * @param writableStackTrace
// */
// public DTSRuntimeException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
// super(message, cause, enableSuppression, writableStackTrace);
// }
// }
| import org.github.dtsopensource.server.share.exception.DTSRuntimeException;
| package org.github.dtsopensource.server.share.store;
/**
* @author ligaofeng 2016年12月4日 上午11:43:05
*/
public enum Status {
S("start"),
T("success"),
F("fail"),
R("rollback"),
E("exception");
private String name;
Status(String name) {
this.name = name;
}
public String getName() {
return name;
}
/**
* get status
*
* @param name
* @return
*/
public static Status getStatus(String name) {
for (Status s : Status.values()) {
if (s.getName().equals(name)) {
return s;
}
}
| // Path: dts-parent/dts-server-share/src/main/java/org/github/dtsopensource/server/share/exception/DTSRuntimeException.java
// public class DTSRuntimeException extends RuntimeException {
//
// private static final long serialVersionUID = 4328158740883926572L;
//
// /**
// * init DTSRuntimeException
// */
// public DTSRuntimeException() {
// super();
// }
//
// /**
// * init DTSRuntimeException
// *
// * @param message
// */
// public DTSRuntimeException(String message) {
// super(message);
// }
//
// /**
// * init DTSRuntimeException
// *
// * @param message
// * @param cause
// */
// public DTSRuntimeException(String message, Throwable cause) {
// super(message, cause);
// }
//
// /**
// * init DTSRuntimeException
// *
// * @param cause
// */
// public DTSRuntimeException(Throwable cause) {
// super(cause);
// }
//
// /**
// * init DTSRuntimeException
// *
// * @param message
// * @param cause
// * @param enableSuppression
// * @param writableStackTrace
// */
// public DTSRuntimeException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
// super(message, cause, enableSuppression, writableStackTrace);
// }
// }
// Path: dts-parent/dts-server-share/src/main/java/org/github/dtsopensource/server/share/store/Status.java
import org.github.dtsopensource.server.share.exception.DTSRuntimeException;
package org.github.dtsopensource.server.share.store;
/**
* @author ligaofeng 2016年12月4日 上午11:43:05
*/
public enum Status {
S("start"),
T("success"),
F("fail"),
R("rollback"),
E("exception");
private String name;
Status(String name) {
this.name = name;
}
public String getName() {
return name;
}
/**
* get status
*
* @param name
* @return
*/
public static Status getStatus(String name) {
for (Status s : Status.values()) {
if (s.getName().equals(name)) {
return s;
}
}
| throw new DTSRuntimeException("Invalid status !" + " name=" + name);
|
adealjason/dtsopensource | dts-parent/dts-server-share/src/main/java/org/github/dtsopensource/server/share/rule/entity/ActivityRuleEntity.java | // Path: dts-parent/dts-server-share/src/main/java/org/github/dtsopensource/server/share/exception/DTSRuntimeException.java
// public class DTSRuntimeException extends RuntimeException {
//
// private static final long serialVersionUID = 4328158740883926572L;
//
// /**
// * init DTSRuntimeException
// */
// public DTSRuntimeException() {
// super();
// }
//
// /**
// * init DTSRuntimeException
// *
// * @param message
// */
// public DTSRuntimeException(String message) {
// super(message);
// }
//
// /**
// * init DTSRuntimeException
// *
// * @param message
// * @param cause
// */
// public DTSRuntimeException(String message, Throwable cause) {
// super(message, cause);
// }
//
// /**
// * init DTSRuntimeException
// *
// * @param cause
// */
// public DTSRuntimeException(Throwable cause) {
// super(cause);
// }
//
// /**
// * init DTSRuntimeException
// *
// * @param message
// * @param cause
// * @param enableSuppression
// * @param writableStackTrace
// */
// public DTSRuntimeException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
// super(message, cause, enableSuppression, writableStackTrace);
// }
// }
| import java.io.Serializable;
import java.util.List;
import org.github.dtsopensource.server.share.exception.DTSRuntimeException;
import com.alibaba.fastjson.JSON;
import lombok.Getter;
import lombok.Setter;
| package org.github.dtsopensource.server.share.rule.entity;
/**
* @author ligaofeng 2016年12月17日 下午2:01:19
*/
@Getter
@Setter
public class ActivityRuleEntity implements Serializable {
private static final long serialVersionUID = 106899067427742570L;
private String bizType;
private String bizTypeName;
private String app;
private String appCname;
private List<ActivityActionRuleEntity> activityActionRules;
/**
* 根据clazzName获取bizAction配置
*
* @param clazzName dts-server配置的信息
* @return
*/
public ActivityActionRuleEntity getActivityActionRuleEntity(String clazzName) {
if (activityActionRules == null || activityActionRules.isEmpty()) {
| // Path: dts-parent/dts-server-share/src/main/java/org/github/dtsopensource/server/share/exception/DTSRuntimeException.java
// public class DTSRuntimeException extends RuntimeException {
//
// private static final long serialVersionUID = 4328158740883926572L;
//
// /**
// * init DTSRuntimeException
// */
// public DTSRuntimeException() {
// super();
// }
//
// /**
// * init DTSRuntimeException
// *
// * @param message
// */
// public DTSRuntimeException(String message) {
// super(message);
// }
//
// /**
// * init DTSRuntimeException
// *
// * @param message
// * @param cause
// */
// public DTSRuntimeException(String message, Throwable cause) {
// super(message, cause);
// }
//
// /**
// * init DTSRuntimeException
// *
// * @param cause
// */
// public DTSRuntimeException(Throwable cause) {
// super(cause);
// }
//
// /**
// * init DTSRuntimeException
// *
// * @param message
// * @param cause
// * @param enableSuppression
// * @param writableStackTrace
// */
// public DTSRuntimeException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
// super(message, cause, enableSuppression, writableStackTrace);
// }
// }
// Path: dts-parent/dts-server-share/src/main/java/org/github/dtsopensource/server/share/rule/entity/ActivityRuleEntity.java
import java.io.Serializable;
import java.util.List;
import org.github.dtsopensource.server.share.exception.DTSRuntimeException;
import com.alibaba.fastjson.JSON;
import lombok.Getter;
import lombok.Setter;
package org.github.dtsopensource.server.share.rule.entity;
/**
* @author ligaofeng 2016年12月17日 下午2:01:19
*/
@Getter
@Setter
public class ActivityRuleEntity implements Serializable {
private static final long serialVersionUID = 106899067427742570L;
private String bizType;
private String bizTypeName;
private String app;
private String appCname;
private List<ActivityActionRuleEntity> activityActionRules;
/**
* 根据clazzName获取bizAction配置
*
* @param clazzName dts-server配置的信息
* @return
*/
public ActivityActionRuleEntity getActivityActionRuleEntity(String clazzName) {
if (activityActionRules == null || activityActionRules.isEmpty()) {
| throw new DTSRuntimeException("尚未配置" + clazzName + "的bizAction,请联系dts-server管理员配置");
|
adealjason/dtsopensource | dts-parent/dts-core/src/main/java/org/github/dtsopensource/core/rule/help/ActivityActionRuleHelper.java | // Path: dts-parent/dts-core/src/main/java/org/github/dtsopensource/core/dao/dataobject/DtsActivityActionRuleDO.java
// @Data
// public class DtsActivityActionRuleDO {
//
// private String bizAction;
//
// private String bizActionName;
//
// private String bizType;
//
// private String service;
//
// private String clazzName;
//
// private String transRecoveryId;
//
// private String isDeleted;
//
// private Date gmtCreated;
//
// private Date gmtModified;
//
// private String creator;
//
// private String modifier;
//
// }
//
// Path: dts-parent/dts-server-share/src/main/java/org/github/dtsopensource/server/share/rule/entity/ActivityActionRuleEntity.java
// @Getter
// @Setter
// public class ActivityActionRuleEntity implements Serializable {
//
// private static final long serialVersionUID = -4294822530381109974L;
//
// private String bizAction;
//
// private String bizActionName;
//
// private String bizType;
//
// private String service;
//
// private String clazzName;
//
// private String transRecoveryId;
//
// /**
// * used for fastjson
// */
// public ActivityActionRuleEntity() {
// }
//
// /**
// * @param builder
// */
// public ActivityActionRuleEntity(Builder builder) {
// this.bizAction = builder.bizAction;
// this.bizActionName = builder.bizActionName;
// this.bizType = builder.bizType;
// this.clazzName = builder.clazzName;
// this.service = builder.service;
// this.transRecoveryId = builder.transRecoveryId;
// }
//
// @Override
// public String toString() {
// return JSON.toJSONString(this);
// }
//
// /**
// * ActivityActionRuleEntity.builder
// *
// * @author ligaofeng 2016年12月17日 下午3:04:39
// */
// @Getter
// public static class Builder {
// private String bizAction;
//
// private String bizActionName;
//
// private String bizType;
//
// private String service;
//
// private String clazzName;
//
// private String transRecoveryId;
//
// public Builder(String bizAction) {
// this.bizAction = bizAction;
// }
//
// public Builder setBizActionName(String bizActionName) {
// this.bizActionName = bizActionName;
// return this;
// }
//
// public Builder setBizType(String bizType) {
// this.bizType = bizType;
// return this;
// }
//
// public Builder setService(String service) {
// this.service = service;
// return this;
// }
//
// public Builder setClazzName(String clazzName) {
// this.clazzName = clazzName;
// return this;
// }
//
// public Builder setTransRecoveryId(String transRecoveryId) {
// this.transRecoveryId = transRecoveryId;
// return this;
// }
//
// public ActivityActionRuleEntity build() {
// return new ActivityActionRuleEntity(this);
// }
// }
//
// }
| import org.github.dtsopensource.core.dao.dataobject.DtsActivityActionRuleDO;
import org.github.dtsopensource.server.share.rule.entity.ActivityActionRuleEntity;
| package org.github.dtsopensource.core.rule.help;
/**
* @author ligaofeng 2016年12月17日 下午2:59:23
*/
public class ActivityActionRuleHelper {
private ActivityActionRuleHelper() {
}
/**
* @param actionRuleDO
* @return
*/
| // Path: dts-parent/dts-core/src/main/java/org/github/dtsopensource/core/dao/dataobject/DtsActivityActionRuleDO.java
// @Data
// public class DtsActivityActionRuleDO {
//
// private String bizAction;
//
// private String bizActionName;
//
// private String bizType;
//
// private String service;
//
// private String clazzName;
//
// private String transRecoveryId;
//
// private String isDeleted;
//
// private Date gmtCreated;
//
// private Date gmtModified;
//
// private String creator;
//
// private String modifier;
//
// }
//
// Path: dts-parent/dts-server-share/src/main/java/org/github/dtsopensource/server/share/rule/entity/ActivityActionRuleEntity.java
// @Getter
// @Setter
// public class ActivityActionRuleEntity implements Serializable {
//
// private static final long serialVersionUID = -4294822530381109974L;
//
// private String bizAction;
//
// private String bizActionName;
//
// private String bizType;
//
// private String service;
//
// private String clazzName;
//
// private String transRecoveryId;
//
// /**
// * used for fastjson
// */
// public ActivityActionRuleEntity() {
// }
//
// /**
// * @param builder
// */
// public ActivityActionRuleEntity(Builder builder) {
// this.bizAction = builder.bizAction;
// this.bizActionName = builder.bizActionName;
// this.bizType = builder.bizType;
// this.clazzName = builder.clazzName;
// this.service = builder.service;
// this.transRecoveryId = builder.transRecoveryId;
// }
//
// @Override
// public String toString() {
// return JSON.toJSONString(this);
// }
//
// /**
// * ActivityActionRuleEntity.builder
// *
// * @author ligaofeng 2016年12月17日 下午3:04:39
// */
// @Getter
// public static class Builder {
// private String bizAction;
//
// private String bizActionName;
//
// private String bizType;
//
// private String service;
//
// private String clazzName;
//
// private String transRecoveryId;
//
// public Builder(String bizAction) {
// this.bizAction = bizAction;
// }
//
// public Builder setBizActionName(String bizActionName) {
// this.bizActionName = bizActionName;
// return this;
// }
//
// public Builder setBizType(String bizType) {
// this.bizType = bizType;
// return this;
// }
//
// public Builder setService(String service) {
// this.service = service;
// return this;
// }
//
// public Builder setClazzName(String clazzName) {
// this.clazzName = clazzName;
// return this;
// }
//
// public Builder setTransRecoveryId(String transRecoveryId) {
// this.transRecoveryId = transRecoveryId;
// return this;
// }
//
// public ActivityActionRuleEntity build() {
// return new ActivityActionRuleEntity(this);
// }
// }
//
// }
// Path: dts-parent/dts-core/src/main/java/org/github/dtsopensource/core/rule/help/ActivityActionRuleHelper.java
import org.github.dtsopensource.core.dao.dataobject.DtsActivityActionRuleDO;
import org.github.dtsopensource.server.share.rule.entity.ActivityActionRuleEntity;
package org.github.dtsopensource.core.rule.help;
/**
* @author ligaofeng 2016年12月17日 下午2:59:23
*/
public class ActivityActionRuleHelper {
private ActivityActionRuleHelper() {
}
/**
* @param actionRuleDO
* @return
*/
| public static ActivityActionRuleEntity toActivityActionRuleEntity(DtsActivityActionRuleDO actionRuleDO) {
|
adealjason/dtsopensource | dts-parent/dts-core/src/main/java/org/github/dtsopensource/core/rule/help/ActivityActionRuleHelper.java | // Path: dts-parent/dts-core/src/main/java/org/github/dtsopensource/core/dao/dataobject/DtsActivityActionRuleDO.java
// @Data
// public class DtsActivityActionRuleDO {
//
// private String bizAction;
//
// private String bizActionName;
//
// private String bizType;
//
// private String service;
//
// private String clazzName;
//
// private String transRecoveryId;
//
// private String isDeleted;
//
// private Date gmtCreated;
//
// private Date gmtModified;
//
// private String creator;
//
// private String modifier;
//
// }
//
// Path: dts-parent/dts-server-share/src/main/java/org/github/dtsopensource/server/share/rule/entity/ActivityActionRuleEntity.java
// @Getter
// @Setter
// public class ActivityActionRuleEntity implements Serializable {
//
// private static final long serialVersionUID = -4294822530381109974L;
//
// private String bizAction;
//
// private String bizActionName;
//
// private String bizType;
//
// private String service;
//
// private String clazzName;
//
// private String transRecoveryId;
//
// /**
// * used for fastjson
// */
// public ActivityActionRuleEntity() {
// }
//
// /**
// * @param builder
// */
// public ActivityActionRuleEntity(Builder builder) {
// this.bizAction = builder.bizAction;
// this.bizActionName = builder.bizActionName;
// this.bizType = builder.bizType;
// this.clazzName = builder.clazzName;
// this.service = builder.service;
// this.transRecoveryId = builder.transRecoveryId;
// }
//
// @Override
// public String toString() {
// return JSON.toJSONString(this);
// }
//
// /**
// * ActivityActionRuleEntity.builder
// *
// * @author ligaofeng 2016年12月17日 下午3:04:39
// */
// @Getter
// public static class Builder {
// private String bizAction;
//
// private String bizActionName;
//
// private String bizType;
//
// private String service;
//
// private String clazzName;
//
// private String transRecoveryId;
//
// public Builder(String bizAction) {
// this.bizAction = bizAction;
// }
//
// public Builder setBizActionName(String bizActionName) {
// this.bizActionName = bizActionName;
// return this;
// }
//
// public Builder setBizType(String bizType) {
// this.bizType = bizType;
// return this;
// }
//
// public Builder setService(String service) {
// this.service = service;
// return this;
// }
//
// public Builder setClazzName(String clazzName) {
// this.clazzName = clazzName;
// return this;
// }
//
// public Builder setTransRecoveryId(String transRecoveryId) {
// this.transRecoveryId = transRecoveryId;
// return this;
// }
//
// public ActivityActionRuleEntity build() {
// return new ActivityActionRuleEntity(this);
// }
// }
//
// }
| import org.github.dtsopensource.core.dao.dataobject.DtsActivityActionRuleDO;
import org.github.dtsopensource.server.share.rule.entity.ActivityActionRuleEntity;
| package org.github.dtsopensource.core.rule.help;
/**
* @author ligaofeng 2016年12月17日 下午2:59:23
*/
public class ActivityActionRuleHelper {
private ActivityActionRuleHelper() {
}
/**
* @param actionRuleDO
* @return
*/
| // Path: dts-parent/dts-core/src/main/java/org/github/dtsopensource/core/dao/dataobject/DtsActivityActionRuleDO.java
// @Data
// public class DtsActivityActionRuleDO {
//
// private String bizAction;
//
// private String bizActionName;
//
// private String bizType;
//
// private String service;
//
// private String clazzName;
//
// private String transRecoveryId;
//
// private String isDeleted;
//
// private Date gmtCreated;
//
// private Date gmtModified;
//
// private String creator;
//
// private String modifier;
//
// }
//
// Path: dts-parent/dts-server-share/src/main/java/org/github/dtsopensource/server/share/rule/entity/ActivityActionRuleEntity.java
// @Getter
// @Setter
// public class ActivityActionRuleEntity implements Serializable {
//
// private static final long serialVersionUID = -4294822530381109974L;
//
// private String bizAction;
//
// private String bizActionName;
//
// private String bizType;
//
// private String service;
//
// private String clazzName;
//
// private String transRecoveryId;
//
// /**
// * used for fastjson
// */
// public ActivityActionRuleEntity() {
// }
//
// /**
// * @param builder
// */
// public ActivityActionRuleEntity(Builder builder) {
// this.bizAction = builder.bizAction;
// this.bizActionName = builder.bizActionName;
// this.bizType = builder.bizType;
// this.clazzName = builder.clazzName;
// this.service = builder.service;
// this.transRecoveryId = builder.transRecoveryId;
// }
//
// @Override
// public String toString() {
// return JSON.toJSONString(this);
// }
//
// /**
// * ActivityActionRuleEntity.builder
// *
// * @author ligaofeng 2016年12月17日 下午3:04:39
// */
// @Getter
// public static class Builder {
// private String bizAction;
//
// private String bizActionName;
//
// private String bizType;
//
// private String service;
//
// private String clazzName;
//
// private String transRecoveryId;
//
// public Builder(String bizAction) {
// this.bizAction = bizAction;
// }
//
// public Builder setBizActionName(String bizActionName) {
// this.bizActionName = bizActionName;
// return this;
// }
//
// public Builder setBizType(String bizType) {
// this.bizType = bizType;
// return this;
// }
//
// public Builder setService(String service) {
// this.service = service;
// return this;
// }
//
// public Builder setClazzName(String clazzName) {
// this.clazzName = clazzName;
// return this;
// }
//
// public Builder setTransRecoveryId(String transRecoveryId) {
// this.transRecoveryId = transRecoveryId;
// return this;
// }
//
// public ActivityActionRuleEntity build() {
// return new ActivityActionRuleEntity(this);
// }
// }
//
// }
// Path: dts-parent/dts-core/src/main/java/org/github/dtsopensource/core/rule/help/ActivityActionRuleHelper.java
import org.github.dtsopensource.core.dao.dataobject.DtsActivityActionRuleDO;
import org.github.dtsopensource.server.share.rule.entity.ActivityActionRuleEntity;
package org.github.dtsopensource.core.rule.help;
/**
* @author ligaofeng 2016年12月17日 下午2:59:23
*/
public class ActivityActionRuleHelper {
private ActivityActionRuleHelper() {
}
/**
* @param actionRuleDO
* @return
*/
| public static ActivityActionRuleEntity toActivityActionRuleEntity(DtsActivityActionRuleDO actionRuleDO) {
|
adealjason/dtsopensource | dts-parent/dts-core/src/main/java/org/github/dtsopensource/core/DTS.java | // Path: dts-parent/dts-core/src/main/java/org/github/dtsopensource/core/store/help/ActionHelper.java
// public class ActionHelper {
//
// private ActionHelper() {
// }
//
// /**
// * @param actionDO
// * @return
// */
// public static ActionEntity toActionEntity(DtsActionDO actionDO) {
// if (actionDO == null) {
// return null;
// }
// return new ActionEntity.Builder(actionDO.getActionId()).setAction(actionDO.getAction())
// .setActivityId(actionDO.getActivityId()).setContext(actionDO.getContext())
// .setProtocol(actionDO.getProtocol()).setService(actionDO.getService())
// .setClazzName(actionDO.getClazzName()).setStatus(actionDO.getStatus()).setVersion(actionDO.getVersion())
// .build();
// }
//
// /**
// * @param actionEntity
// * @return
// * @throws SequenceException
// */
// public static DtsActionDO toDtsActionDO(ActionEntity actionEntity) {
// if (actionEntity == null) {
// return new DtsActionDO();
// }
// Date now = new Date();
// DtsActionDO actionDO = new DtsActionDO();
// actionDO.setAction(actionEntity.getAction());
// actionDO.setActivityId(actionEntity.getActivityId());
// actionDO.setActionId(actionEntity.getActionId());
// actionDO.setContext(JSON.toJSONString(actionEntity.getContext()));
// actionDO.setProtocol(actionEntity.protocol());
// actionDO.setService(actionEntity.getService());
// actionDO.setClazzName(actionEntity.getClazzName());
// actionDO.setStatus(actionEntity.status());
// actionDO.setVersion(actionEntity.getVersion());
// actionDO.setIsDeleted("N");
// actionDO.setGmtCreated(now);
// actionDO.setGmtModified(now);
// actionDO.setCreator("system");
// actionDO.setModifier("system");
// return actionDO;
// }
//
// }
//
// Path: dts-parent/dts-server-share/src/main/java/org/github/dtsopensource/server/share/IDTS.java
// public interface IDTS {
//
// /**
// * 获取指定业务活动的action
// *
// * @param activityId
// * @return
// */
// public ResultBase<List<ActionEntity>> getActionEntities(String activityId);
// }
//
// Path: dts-parent/dts-server-share/src/main/java/org/github/dtsopensource/server/share/ResultBase.java
// @Data
// public class ResultBase<T> implements Serializable {
//
// private static final long serialVersionUID = 2297155012372998859L;
//
// private DTSResultCode dtsResultCode;
//
// private String message;
//
// private T value;
//
// /**
// * @return
// */
// public boolean isSucess() {
// return DTSResultCode.SUCCESS == this.getDtsResultCode();
// }
//
// /**
// * @param errorMessage
// */
// public void addMessage(String errorMessage) {
// if (message != null && message.trim().length() > 0) {
// message = message.concat("|").concat(errorMessage);
// } else {
// message = errorMessage;
// }
// }
// }
| import java.util.List;
import org.github.dtsopensource.core.dao.ActionSqlConstance;
import org.github.dtsopensource.core.dao.dataobject.DtsActionDO;
import org.github.dtsopensource.core.dao.rowMapper.DtsActionRowMapper;
import org.github.dtsopensource.core.store.help.ActionHelper;
import org.github.dtsopensource.server.share.DTSResultCode;
import org.github.dtsopensource.server.share.IDTS;
import org.github.dtsopensource.server.share.ResultBase;
import org.github.dtsopensource.server.share.store.entity.ActionEntity;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.transaction.support.TransactionTemplate;
import com.google.common.collect.Lists;
import lombok.extern.slf4j.Slf4j;
| package org.github.dtsopensource.core;
/**
* @author ligaofeng 2016年12月16日 上午11:07:30
*/
@Slf4j
public class DTS implements IDTS {
protected final JdbcTemplate jdbcTemplate;
protected final TransactionTemplate transactionTemplate;
public DTS(JdbcTemplate jdbcTemplate, TransactionTemplate transactionTemplate) {
this.jdbcTemplate = jdbcTemplate;
this.transactionTemplate = transactionTemplate;
}
@Override
| // Path: dts-parent/dts-core/src/main/java/org/github/dtsopensource/core/store/help/ActionHelper.java
// public class ActionHelper {
//
// private ActionHelper() {
// }
//
// /**
// * @param actionDO
// * @return
// */
// public static ActionEntity toActionEntity(DtsActionDO actionDO) {
// if (actionDO == null) {
// return null;
// }
// return new ActionEntity.Builder(actionDO.getActionId()).setAction(actionDO.getAction())
// .setActivityId(actionDO.getActivityId()).setContext(actionDO.getContext())
// .setProtocol(actionDO.getProtocol()).setService(actionDO.getService())
// .setClazzName(actionDO.getClazzName()).setStatus(actionDO.getStatus()).setVersion(actionDO.getVersion())
// .build();
// }
//
// /**
// * @param actionEntity
// * @return
// * @throws SequenceException
// */
// public static DtsActionDO toDtsActionDO(ActionEntity actionEntity) {
// if (actionEntity == null) {
// return new DtsActionDO();
// }
// Date now = new Date();
// DtsActionDO actionDO = new DtsActionDO();
// actionDO.setAction(actionEntity.getAction());
// actionDO.setActivityId(actionEntity.getActivityId());
// actionDO.setActionId(actionEntity.getActionId());
// actionDO.setContext(JSON.toJSONString(actionEntity.getContext()));
// actionDO.setProtocol(actionEntity.protocol());
// actionDO.setService(actionEntity.getService());
// actionDO.setClazzName(actionEntity.getClazzName());
// actionDO.setStatus(actionEntity.status());
// actionDO.setVersion(actionEntity.getVersion());
// actionDO.setIsDeleted("N");
// actionDO.setGmtCreated(now);
// actionDO.setGmtModified(now);
// actionDO.setCreator("system");
// actionDO.setModifier("system");
// return actionDO;
// }
//
// }
//
// Path: dts-parent/dts-server-share/src/main/java/org/github/dtsopensource/server/share/IDTS.java
// public interface IDTS {
//
// /**
// * 获取指定业务活动的action
// *
// * @param activityId
// * @return
// */
// public ResultBase<List<ActionEntity>> getActionEntities(String activityId);
// }
//
// Path: dts-parent/dts-server-share/src/main/java/org/github/dtsopensource/server/share/ResultBase.java
// @Data
// public class ResultBase<T> implements Serializable {
//
// private static final long serialVersionUID = 2297155012372998859L;
//
// private DTSResultCode dtsResultCode;
//
// private String message;
//
// private T value;
//
// /**
// * @return
// */
// public boolean isSucess() {
// return DTSResultCode.SUCCESS == this.getDtsResultCode();
// }
//
// /**
// * @param errorMessage
// */
// public void addMessage(String errorMessage) {
// if (message != null && message.trim().length() > 0) {
// message = message.concat("|").concat(errorMessage);
// } else {
// message = errorMessage;
// }
// }
// }
// Path: dts-parent/dts-core/src/main/java/org/github/dtsopensource/core/DTS.java
import java.util.List;
import org.github.dtsopensource.core.dao.ActionSqlConstance;
import org.github.dtsopensource.core.dao.dataobject.DtsActionDO;
import org.github.dtsopensource.core.dao.rowMapper.DtsActionRowMapper;
import org.github.dtsopensource.core.store.help.ActionHelper;
import org.github.dtsopensource.server.share.DTSResultCode;
import org.github.dtsopensource.server.share.IDTS;
import org.github.dtsopensource.server.share.ResultBase;
import org.github.dtsopensource.server.share.store.entity.ActionEntity;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.transaction.support.TransactionTemplate;
import com.google.common.collect.Lists;
import lombok.extern.slf4j.Slf4j;
package org.github.dtsopensource.core;
/**
* @author ligaofeng 2016年12月16日 上午11:07:30
*/
@Slf4j
public class DTS implements IDTS {
protected final JdbcTemplate jdbcTemplate;
protected final TransactionTemplate transactionTemplate;
public DTS(JdbcTemplate jdbcTemplate, TransactionTemplate transactionTemplate) {
this.jdbcTemplate = jdbcTemplate;
this.transactionTemplate = transactionTemplate;
}
@Override
| public ResultBase<List<ActionEntity>> getActionEntities(String activityId) {
|
adealjason/dtsopensource | dts-parent/dts-core/src/main/java/org/github/dtsopensource/core/DTS.java | // Path: dts-parent/dts-core/src/main/java/org/github/dtsopensource/core/store/help/ActionHelper.java
// public class ActionHelper {
//
// private ActionHelper() {
// }
//
// /**
// * @param actionDO
// * @return
// */
// public static ActionEntity toActionEntity(DtsActionDO actionDO) {
// if (actionDO == null) {
// return null;
// }
// return new ActionEntity.Builder(actionDO.getActionId()).setAction(actionDO.getAction())
// .setActivityId(actionDO.getActivityId()).setContext(actionDO.getContext())
// .setProtocol(actionDO.getProtocol()).setService(actionDO.getService())
// .setClazzName(actionDO.getClazzName()).setStatus(actionDO.getStatus()).setVersion(actionDO.getVersion())
// .build();
// }
//
// /**
// * @param actionEntity
// * @return
// * @throws SequenceException
// */
// public static DtsActionDO toDtsActionDO(ActionEntity actionEntity) {
// if (actionEntity == null) {
// return new DtsActionDO();
// }
// Date now = new Date();
// DtsActionDO actionDO = new DtsActionDO();
// actionDO.setAction(actionEntity.getAction());
// actionDO.setActivityId(actionEntity.getActivityId());
// actionDO.setActionId(actionEntity.getActionId());
// actionDO.setContext(JSON.toJSONString(actionEntity.getContext()));
// actionDO.setProtocol(actionEntity.protocol());
// actionDO.setService(actionEntity.getService());
// actionDO.setClazzName(actionEntity.getClazzName());
// actionDO.setStatus(actionEntity.status());
// actionDO.setVersion(actionEntity.getVersion());
// actionDO.setIsDeleted("N");
// actionDO.setGmtCreated(now);
// actionDO.setGmtModified(now);
// actionDO.setCreator("system");
// actionDO.setModifier("system");
// return actionDO;
// }
//
// }
//
// Path: dts-parent/dts-server-share/src/main/java/org/github/dtsopensource/server/share/IDTS.java
// public interface IDTS {
//
// /**
// * 获取指定业务活动的action
// *
// * @param activityId
// * @return
// */
// public ResultBase<List<ActionEntity>> getActionEntities(String activityId);
// }
//
// Path: dts-parent/dts-server-share/src/main/java/org/github/dtsopensource/server/share/ResultBase.java
// @Data
// public class ResultBase<T> implements Serializable {
//
// private static final long serialVersionUID = 2297155012372998859L;
//
// private DTSResultCode dtsResultCode;
//
// private String message;
//
// private T value;
//
// /**
// * @return
// */
// public boolean isSucess() {
// return DTSResultCode.SUCCESS == this.getDtsResultCode();
// }
//
// /**
// * @param errorMessage
// */
// public void addMessage(String errorMessage) {
// if (message != null && message.trim().length() > 0) {
// message = message.concat("|").concat(errorMessage);
// } else {
// message = errorMessage;
// }
// }
// }
| import java.util.List;
import org.github.dtsopensource.core.dao.ActionSqlConstance;
import org.github.dtsopensource.core.dao.dataobject.DtsActionDO;
import org.github.dtsopensource.core.dao.rowMapper.DtsActionRowMapper;
import org.github.dtsopensource.core.store.help.ActionHelper;
import org.github.dtsopensource.server.share.DTSResultCode;
import org.github.dtsopensource.server.share.IDTS;
import org.github.dtsopensource.server.share.ResultBase;
import org.github.dtsopensource.server.share.store.entity.ActionEntity;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.transaction.support.TransactionTemplate;
import com.google.common.collect.Lists;
import lombok.extern.slf4j.Slf4j;
| package org.github.dtsopensource.core;
/**
* @author ligaofeng 2016年12月16日 上午11:07:30
*/
@Slf4j
public class DTS implements IDTS {
protected final JdbcTemplate jdbcTemplate;
protected final TransactionTemplate transactionTemplate;
public DTS(JdbcTemplate jdbcTemplate, TransactionTemplate transactionTemplate) {
this.jdbcTemplate = jdbcTemplate;
this.transactionTemplate = transactionTemplate;
}
@Override
public ResultBase<List<ActionEntity>> getActionEntities(String activityId) {
ResultBase<List<ActionEntity>> actionListBase = new ResultBase<List<ActionEntity>>();
List<ActionEntity> actionEntityList = Lists.newArrayList();
actionListBase.setValue(actionEntityList);
try {
Object[] params = new Object[] { activityId };
List<DtsActionDO> actionList = jdbcTemplate.query(ActionSqlConstance.select_dts_action_by_activity_id,
params, new DtsActionRowMapper());
actionListBase.setDtsResultCode(DTSResultCode.SUCCESS);
for (DtsActionDO actionDO : actionList) {
| // Path: dts-parent/dts-core/src/main/java/org/github/dtsopensource/core/store/help/ActionHelper.java
// public class ActionHelper {
//
// private ActionHelper() {
// }
//
// /**
// * @param actionDO
// * @return
// */
// public static ActionEntity toActionEntity(DtsActionDO actionDO) {
// if (actionDO == null) {
// return null;
// }
// return new ActionEntity.Builder(actionDO.getActionId()).setAction(actionDO.getAction())
// .setActivityId(actionDO.getActivityId()).setContext(actionDO.getContext())
// .setProtocol(actionDO.getProtocol()).setService(actionDO.getService())
// .setClazzName(actionDO.getClazzName()).setStatus(actionDO.getStatus()).setVersion(actionDO.getVersion())
// .build();
// }
//
// /**
// * @param actionEntity
// * @return
// * @throws SequenceException
// */
// public static DtsActionDO toDtsActionDO(ActionEntity actionEntity) {
// if (actionEntity == null) {
// return new DtsActionDO();
// }
// Date now = new Date();
// DtsActionDO actionDO = new DtsActionDO();
// actionDO.setAction(actionEntity.getAction());
// actionDO.setActivityId(actionEntity.getActivityId());
// actionDO.setActionId(actionEntity.getActionId());
// actionDO.setContext(JSON.toJSONString(actionEntity.getContext()));
// actionDO.setProtocol(actionEntity.protocol());
// actionDO.setService(actionEntity.getService());
// actionDO.setClazzName(actionEntity.getClazzName());
// actionDO.setStatus(actionEntity.status());
// actionDO.setVersion(actionEntity.getVersion());
// actionDO.setIsDeleted("N");
// actionDO.setGmtCreated(now);
// actionDO.setGmtModified(now);
// actionDO.setCreator("system");
// actionDO.setModifier("system");
// return actionDO;
// }
//
// }
//
// Path: dts-parent/dts-server-share/src/main/java/org/github/dtsopensource/server/share/IDTS.java
// public interface IDTS {
//
// /**
// * 获取指定业务活动的action
// *
// * @param activityId
// * @return
// */
// public ResultBase<List<ActionEntity>> getActionEntities(String activityId);
// }
//
// Path: dts-parent/dts-server-share/src/main/java/org/github/dtsopensource/server/share/ResultBase.java
// @Data
// public class ResultBase<T> implements Serializable {
//
// private static final long serialVersionUID = 2297155012372998859L;
//
// private DTSResultCode dtsResultCode;
//
// private String message;
//
// private T value;
//
// /**
// * @return
// */
// public boolean isSucess() {
// return DTSResultCode.SUCCESS == this.getDtsResultCode();
// }
//
// /**
// * @param errorMessage
// */
// public void addMessage(String errorMessage) {
// if (message != null && message.trim().length() > 0) {
// message = message.concat("|").concat(errorMessage);
// } else {
// message = errorMessage;
// }
// }
// }
// Path: dts-parent/dts-core/src/main/java/org/github/dtsopensource/core/DTS.java
import java.util.List;
import org.github.dtsopensource.core.dao.ActionSqlConstance;
import org.github.dtsopensource.core.dao.dataobject.DtsActionDO;
import org.github.dtsopensource.core.dao.rowMapper.DtsActionRowMapper;
import org.github.dtsopensource.core.store.help.ActionHelper;
import org.github.dtsopensource.server.share.DTSResultCode;
import org.github.dtsopensource.server.share.IDTS;
import org.github.dtsopensource.server.share.ResultBase;
import org.github.dtsopensource.server.share.store.entity.ActionEntity;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.transaction.support.TransactionTemplate;
import com.google.common.collect.Lists;
import lombok.extern.slf4j.Slf4j;
package org.github.dtsopensource.core;
/**
* @author ligaofeng 2016年12月16日 上午11:07:30
*/
@Slf4j
public class DTS implements IDTS {
protected final JdbcTemplate jdbcTemplate;
protected final TransactionTemplate transactionTemplate;
public DTS(JdbcTemplate jdbcTemplate, TransactionTemplate transactionTemplate) {
this.jdbcTemplate = jdbcTemplate;
this.transactionTemplate = transactionTemplate;
}
@Override
public ResultBase<List<ActionEntity>> getActionEntities(String activityId) {
ResultBase<List<ActionEntity>> actionListBase = new ResultBase<List<ActionEntity>>();
List<ActionEntity> actionEntityList = Lists.newArrayList();
actionListBase.setValue(actionEntityList);
try {
Object[] params = new Object[] { activityId };
List<DtsActionDO> actionList = jdbcTemplate.query(ActionSqlConstance.select_dts_action_by_activity_id,
params, new DtsActionRowMapper());
actionListBase.setDtsResultCode(DTSResultCode.SUCCESS);
for (DtsActionDO actionDO : actionList) {
| actionEntityList.add(ActionHelper.toActionEntity(actionDO));
|
adealjason/dtsopensource | dts-parent/dts-schedule/src/main/java/org/github/dtsopensource/schedule/register/zookeeper/ZookeeperJobRegister.java | // Path: dts-parent/dts-schedule/src/main/java/org/github/dtsopensource/schedule/IJobRegister.java
// public interface IJobRegister {
//
// /**
// * @return
// */
// public boolean register();
//
// /**
// *
// */
// public void stop();
//
// /**
// *
// */
// public void destroy();
// }
//
// Path: dts-parent/dts-server-share/src/main/java/org/github/dtsopensource/server/share/exception/DTSRuntimeException.java
// public class DTSRuntimeException extends RuntimeException {
//
// private static final long serialVersionUID = 4328158740883926572L;
//
// /**
// * init DTSRuntimeException
// */
// public DTSRuntimeException() {
// super();
// }
//
// /**
// * init DTSRuntimeException
// *
// * @param message
// */
// public DTSRuntimeException(String message) {
// super(message);
// }
//
// /**
// * init DTSRuntimeException
// *
// * @param message
// * @param cause
// */
// public DTSRuntimeException(String message, Throwable cause) {
// super(message, cause);
// }
//
// /**
// * init DTSRuntimeException
// *
// * @param cause
// */
// public DTSRuntimeException(Throwable cause) {
// super(cause);
// }
//
// /**
// * init DTSRuntimeException
// *
// * @param message
// * @param cause
// * @param enableSuppression
// * @param writableStackTrace
// */
// public DTSRuntimeException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
// super(message, cause, enableSuppression, writableStackTrace);
// }
// }
| import javax.annotation.PostConstruct;
import org.apache.commons.lang.StringUtils;
import org.github.dtsopensource.schedule.IJobRegister;
import org.github.dtsopensource.server.share.exception.DTSRuntimeException;
import com.alibaba.fastjson.JSON;
import lombok.Getter;
import lombok.Setter;
| package org.github.dtsopensource.schedule.register.zookeeper;
/**
* @author ligaofeng 2016年12月14日 下午3:51:14
*/
public class ZookeeperJobRegister implements IJobRegister {
@Getter
@Setter
private String zkConnectionString;
@Getter
@Setter
private int zkSessionTimeout = 60000;
@Getter
@Setter
private String ephemeralZnodeParent;
@Getter
@Setter
private String ephemeralZnodeNamePrefix;
private LeaderElector leaderElector;
/**
* 初始化
*/
@PostConstruct
public void initLeaderElector() {
if (StringUtils.isEmpty(zkConnectionString)) {
| // Path: dts-parent/dts-schedule/src/main/java/org/github/dtsopensource/schedule/IJobRegister.java
// public interface IJobRegister {
//
// /**
// * @return
// */
// public boolean register();
//
// /**
// *
// */
// public void stop();
//
// /**
// *
// */
// public void destroy();
// }
//
// Path: dts-parent/dts-server-share/src/main/java/org/github/dtsopensource/server/share/exception/DTSRuntimeException.java
// public class DTSRuntimeException extends RuntimeException {
//
// private static final long serialVersionUID = 4328158740883926572L;
//
// /**
// * init DTSRuntimeException
// */
// public DTSRuntimeException() {
// super();
// }
//
// /**
// * init DTSRuntimeException
// *
// * @param message
// */
// public DTSRuntimeException(String message) {
// super(message);
// }
//
// /**
// * init DTSRuntimeException
// *
// * @param message
// * @param cause
// */
// public DTSRuntimeException(String message, Throwable cause) {
// super(message, cause);
// }
//
// /**
// * init DTSRuntimeException
// *
// * @param cause
// */
// public DTSRuntimeException(Throwable cause) {
// super(cause);
// }
//
// /**
// * init DTSRuntimeException
// *
// * @param message
// * @param cause
// * @param enableSuppression
// * @param writableStackTrace
// */
// public DTSRuntimeException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
// super(message, cause, enableSuppression, writableStackTrace);
// }
// }
// Path: dts-parent/dts-schedule/src/main/java/org/github/dtsopensource/schedule/register/zookeeper/ZookeeperJobRegister.java
import javax.annotation.PostConstruct;
import org.apache.commons.lang.StringUtils;
import org.github.dtsopensource.schedule.IJobRegister;
import org.github.dtsopensource.server.share.exception.DTSRuntimeException;
import com.alibaba.fastjson.JSON;
import lombok.Getter;
import lombok.Setter;
package org.github.dtsopensource.schedule.register.zookeeper;
/**
* @author ligaofeng 2016年12月14日 下午3:51:14
*/
public class ZookeeperJobRegister implements IJobRegister {
@Getter
@Setter
private String zkConnectionString;
@Getter
@Setter
private int zkSessionTimeout = 60000;
@Getter
@Setter
private String ephemeralZnodeParent;
@Getter
@Setter
private String ephemeralZnodeNamePrefix;
private LeaderElector leaderElector;
/**
* 初始化
*/
@PostConstruct
public void initLeaderElector() {
if (StringUtils.isEmpty(zkConnectionString)) {
| throw new DTSRuntimeException("zkConnectionString尚未配置");
|
adealjason/dtsopensource | dts-parent/dts-schedule/src/main/java/org/github/dtsopensource/schedule/jobTracker/RemoteJobTrackerDelegate.java | // Path: dts-parent/dts-server-share/src/main/java/org/github/dtsopensource/server/share/exception/DTSRuntimeException.java
// public class DTSRuntimeException extends RuntimeException {
//
// private static final long serialVersionUID = 4328158740883926572L;
//
// /**
// * init DTSRuntimeException
// */
// public DTSRuntimeException() {
// super();
// }
//
// /**
// * init DTSRuntimeException
// *
// * @param message
// */
// public DTSRuntimeException(String message) {
// super(message);
// }
//
// /**
// * init DTSRuntimeException
// *
// * @param message
// * @param cause
// */
// public DTSRuntimeException(String message, Throwable cause) {
// super(message, cause);
// }
//
// /**
// * init DTSRuntimeException
// *
// * @param cause
// */
// public DTSRuntimeException(Throwable cause) {
// super(cause);
// }
//
// /**
// * init DTSRuntimeException
// *
// * @param message
// * @param cause
// * @param enableSuppression
// * @param writableStackTrace
// */
// public DTSRuntimeException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
// super(message, cause, enableSuppression, writableStackTrace);
// }
// }
//
// Path: dts-parent/dts-server-share/src/main/java/org/github/dtsopensource/server/share/schedule/TaskTrackerContext.java
// @Getter
// @Setter
// public class TaskTrackerContext implements Serializable {
//
// private static final long serialVersionUID = 1612166307850489500L;
//
// private DTSConfig dtsConfig;
//
// @JSONField(serialize = false)
// private IDTSTaskTracker taskTracker;
//
// @JSONField(serialize = false)
// private IDTSSchedule dtsSchedule;
//
// private String taskTrackerType;
//
// @Override
// public String toString() {
// return JSON.toJSONString(this);
// }
//
// }
| import org.apache.commons.lang.StringUtils;
import org.github.dtsopensource.schedule.taskTracker.RemoteTaskTrackerDelegate;
import org.github.dtsopensource.server.share.exception.DTSRuntimeException;
import org.github.dtsopensource.server.share.schedule.IDTSTaskTracker;
import org.github.dtsopensource.server.share.schedule.TaskTrackerContext;
import com.alibaba.fastjson.JSON;
import lombok.Getter;
import lombok.Setter;
| package org.github.dtsopensource.schedule.jobTracker;
/**
* @author ligaofeng 2016年12月14日 下午1:05:34
*/
public class RemoteJobTrackerDelegate extends DTSJobTrackerDelegate {
@Getter
@Setter
private String taskTrackerType;
@Getter
@Setter
private String requestScheduleURL;
@Getter
@Setter
private int timeOut = 10 * 1000;
@Override
protected void check() {
if (jobRegister == null) {
| // Path: dts-parent/dts-server-share/src/main/java/org/github/dtsopensource/server/share/exception/DTSRuntimeException.java
// public class DTSRuntimeException extends RuntimeException {
//
// private static final long serialVersionUID = 4328158740883926572L;
//
// /**
// * init DTSRuntimeException
// */
// public DTSRuntimeException() {
// super();
// }
//
// /**
// * init DTSRuntimeException
// *
// * @param message
// */
// public DTSRuntimeException(String message) {
// super(message);
// }
//
// /**
// * init DTSRuntimeException
// *
// * @param message
// * @param cause
// */
// public DTSRuntimeException(String message, Throwable cause) {
// super(message, cause);
// }
//
// /**
// * init DTSRuntimeException
// *
// * @param cause
// */
// public DTSRuntimeException(Throwable cause) {
// super(cause);
// }
//
// /**
// * init DTSRuntimeException
// *
// * @param message
// * @param cause
// * @param enableSuppression
// * @param writableStackTrace
// */
// public DTSRuntimeException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
// super(message, cause, enableSuppression, writableStackTrace);
// }
// }
//
// Path: dts-parent/dts-server-share/src/main/java/org/github/dtsopensource/server/share/schedule/TaskTrackerContext.java
// @Getter
// @Setter
// public class TaskTrackerContext implements Serializable {
//
// private static final long serialVersionUID = 1612166307850489500L;
//
// private DTSConfig dtsConfig;
//
// @JSONField(serialize = false)
// private IDTSTaskTracker taskTracker;
//
// @JSONField(serialize = false)
// private IDTSSchedule dtsSchedule;
//
// private String taskTrackerType;
//
// @Override
// public String toString() {
// return JSON.toJSONString(this);
// }
//
// }
// Path: dts-parent/dts-schedule/src/main/java/org/github/dtsopensource/schedule/jobTracker/RemoteJobTrackerDelegate.java
import org.apache.commons.lang.StringUtils;
import org.github.dtsopensource.schedule.taskTracker.RemoteTaskTrackerDelegate;
import org.github.dtsopensource.server.share.exception.DTSRuntimeException;
import org.github.dtsopensource.server.share.schedule.IDTSTaskTracker;
import org.github.dtsopensource.server.share.schedule.TaskTrackerContext;
import com.alibaba.fastjson.JSON;
import lombok.Getter;
import lombok.Setter;
package org.github.dtsopensource.schedule.jobTracker;
/**
* @author ligaofeng 2016年12月14日 下午1:05:34
*/
public class RemoteJobTrackerDelegate extends DTSJobTrackerDelegate {
@Getter
@Setter
private String taskTrackerType;
@Getter
@Setter
private String requestScheduleURL;
@Getter
@Setter
private int timeOut = 10 * 1000;
@Override
protected void check() {
if (jobRegister == null) {
| throw new DTSRuntimeException("尚未设置任务注册器jobRegister");
|
adealjason/dtsopensource | dts-parent/dts-schedule/src/main/java/org/github/dtsopensource/schedule/jobTracker/RemoteJobTrackerDelegate.java | // Path: dts-parent/dts-server-share/src/main/java/org/github/dtsopensource/server/share/exception/DTSRuntimeException.java
// public class DTSRuntimeException extends RuntimeException {
//
// private static final long serialVersionUID = 4328158740883926572L;
//
// /**
// * init DTSRuntimeException
// */
// public DTSRuntimeException() {
// super();
// }
//
// /**
// * init DTSRuntimeException
// *
// * @param message
// */
// public DTSRuntimeException(String message) {
// super(message);
// }
//
// /**
// * init DTSRuntimeException
// *
// * @param message
// * @param cause
// */
// public DTSRuntimeException(String message, Throwable cause) {
// super(message, cause);
// }
//
// /**
// * init DTSRuntimeException
// *
// * @param cause
// */
// public DTSRuntimeException(Throwable cause) {
// super(cause);
// }
//
// /**
// * init DTSRuntimeException
// *
// * @param message
// * @param cause
// * @param enableSuppression
// * @param writableStackTrace
// */
// public DTSRuntimeException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
// super(message, cause, enableSuppression, writableStackTrace);
// }
// }
//
// Path: dts-parent/dts-server-share/src/main/java/org/github/dtsopensource/server/share/schedule/TaskTrackerContext.java
// @Getter
// @Setter
// public class TaskTrackerContext implements Serializable {
//
// private static final long serialVersionUID = 1612166307850489500L;
//
// private DTSConfig dtsConfig;
//
// @JSONField(serialize = false)
// private IDTSTaskTracker taskTracker;
//
// @JSONField(serialize = false)
// private IDTSSchedule dtsSchedule;
//
// private String taskTrackerType;
//
// @Override
// public String toString() {
// return JSON.toJSONString(this);
// }
//
// }
| import org.apache.commons.lang.StringUtils;
import org.github.dtsopensource.schedule.taskTracker.RemoteTaskTrackerDelegate;
import org.github.dtsopensource.server.share.exception.DTSRuntimeException;
import org.github.dtsopensource.server.share.schedule.IDTSTaskTracker;
import org.github.dtsopensource.server.share.schedule.TaskTrackerContext;
import com.alibaba.fastjson.JSON;
import lombok.Getter;
import lombok.Setter;
| private String requestScheduleURL;
@Getter
@Setter
private int timeOut = 10 * 1000;
@Override
protected void check() {
if (jobRegister == null) {
throw new DTSRuntimeException("尚未设置任务注册器jobRegister");
}
if (timerParse == null) {
throw new DTSRuntimeException("尚未设置计时器timerParse");
}
if (dtsConfig == null) {
throw new DTSRuntimeException("尚未设置系统配置dtsConfig");
}
if (taskTrackerType == null) {
throw new DTSRuntimeException("尚未设置要执行的任务类型taskTrackerType");
}
if (StringUtils.isEmpty(requestScheduleURL)) {
throw new DTSRuntimeException("REMOTE模式下请设置要请求的dts-server地址requestScheduleURL");
}
}
@Override
protected IDTSTaskTracker initTaskTrackerDelegate() {
return new RemoteTaskTrackerDelegate(requestScheduleURL, timeOut);
}
@Override
| // Path: dts-parent/dts-server-share/src/main/java/org/github/dtsopensource/server/share/exception/DTSRuntimeException.java
// public class DTSRuntimeException extends RuntimeException {
//
// private static final long serialVersionUID = 4328158740883926572L;
//
// /**
// * init DTSRuntimeException
// */
// public DTSRuntimeException() {
// super();
// }
//
// /**
// * init DTSRuntimeException
// *
// * @param message
// */
// public DTSRuntimeException(String message) {
// super(message);
// }
//
// /**
// * init DTSRuntimeException
// *
// * @param message
// * @param cause
// */
// public DTSRuntimeException(String message, Throwable cause) {
// super(message, cause);
// }
//
// /**
// * init DTSRuntimeException
// *
// * @param cause
// */
// public DTSRuntimeException(Throwable cause) {
// super(cause);
// }
//
// /**
// * init DTSRuntimeException
// *
// * @param message
// * @param cause
// * @param enableSuppression
// * @param writableStackTrace
// */
// public DTSRuntimeException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
// super(message, cause, enableSuppression, writableStackTrace);
// }
// }
//
// Path: dts-parent/dts-server-share/src/main/java/org/github/dtsopensource/server/share/schedule/TaskTrackerContext.java
// @Getter
// @Setter
// public class TaskTrackerContext implements Serializable {
//
// private static final long serialVersionUID = 1612166307850489500L;
//
// private DTSConfig dtsConfig;
//
// @JSONField(serialize = false)
// private IDTSTaskTracker taskTracker;
//
// @JSONField(serialize = false)
// private IDTSSchedule dtsSchedule;
//
// private String taskTrackerType;
//
// @Override
// public String toString() {
// return JSON.toJSONString(this);
// }
//
// }
// Path: dts-parent/dts-schedule/src/main/java/org/github/dtsopensource/schedule/jobTracker/RemoteJobTrackerDelegate.java
import org.apache.commons.lang.StringUtils;
import org.github.dtsopensource.schedule.taskTracker.RemoteTaskTrackerDelegate;
import org.github.dtsopensource.server.share.exception.DTSRuntimeException;
import org.github.dtsopensource.server.share.schedule.IDTSTaskTracker;
import org.github.dtsopensource.server.share.schedule.TaskTrackerContext;
import com.alibaba.fastjson.JSON;
import lombok.Getter;
import lombok.Setter;
private String requestScheduleURL;
@Getter
@Setter
private int timeOut = 10 * 1000;
@Override
protected void check() {
if (jobRegister == null) {
throw new DTSRuntimeException("尚未设置任务注册器jobRegister");
}
if (timerParse == null) {
throw new DTSRuntimeException("尚未设置计时器timerParse");
}
if (dtsConfig == null) {
throw new DTSRuntimeException("尚未设置系统配置dtsConfig");
}
if (taskTrackerType == null) {
throw new DTSRuntimeException("尚未设置要执行的任务类型taskTrackerType");
}
if (StringUtils.isEmpty(requestScheduleURL)) {
throw new DTSRuntimeException("REMOTE模式下请设置要请求的dts-server地址requestScheduleURL");
}
}
@Override
protected IDTSTaskTracker initTaskTrackerDelegate() {
return new RemoteTaskTrackerDelegate(requestScheduleURL, timeOut);
}
@Override
| protected TaskTrackerContext initTaskTrackerContext() {
|
adealjason/dtsopensource | dts-parent/dts-server-share/src/main/java/org/github/dtsopensource/server/share/schedule/TaskTrackerContext.java | // Path: dts-parent/dts-server-share/src/main/java/org/github/dtsopensource/server/share/DTSConfig.java
// @Getter
// @Setter
// public class DTSConfig implements Serializable {
//
// private static final long serialVersionUID = -2408123274907783162L;
//
// private DTSManageType dtsManageType;
//
// private String app;
//
// //dts业务规则请求地址
// private String requestActivityRuleURL;
//
// @PostConstruct
// public void checkConfig() {
// if (dtsManageType == null) {
// throw new DTSRuntimeException("dts连接方式dtsManageType未定义");
// }
// if (app == null || app.trim().length() == 0) {
// throw new DTSRuntimeException("业务系统名称app未定义");
// }
// if (requestActivityRuleURL == null || requestActivityRuleURL.trim().length() == 0) {
// throw new DTSRuntimeException("dts业务规则请求地址requestActivityRuleURL尚未配置");
// }
// }
//
// @Override
// public String toString() {
// return JSON.toJSONString(this);
// }
// }
| import java.io.Serializable;
import org.github.dtsopensource.server.share.DTSConfig;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.annotation.JSONField;
import lombok.Getter;
import lombok.Setter;
| package org.github.dtsopensource.server.share.schedule;
/**
* @author ligaofeng 2016年12月14日 上午11:10:45
*/
@Getter
@Setter
public class TaskTrackerContext implements Serializable {
private static final long serialVersionUID = 1612166307850489500L;
| // Path: dts-parent/dts-server-share/src/main/java/org/github/dtsopensource/server/share/DTSConfig.java
// @Getter
// @Setter
// public class DTSConfig implements Serializable {
//
// private static final long serialVersionUID = -2408123274907783162L;
//
// private DTSManageType dtsManageType;
//
// private String app;
//
// //dts业务规则请求地址
// private String requestActivityRuleURL;
//
// @PostConstruct
// public void checkConfig() {
// if (dtsManageType == null) {
// throw new DTSRuntimeException("dts连接方式dtsManageType未定义");
// }
// if (app == null || app.trim().length() == 0) {
// throw new DTSRuntimeException("业务系统名称app未定义");
// }
// if (requestActivityRuleURL == null || requestActivityRuleURL.trim().length() == 0) {
// throw new DTSRuntimeException("dts业务规则请求地址requestActivityRuleURL尚未配置");
// }
// }
//
// @Override
// public String toString() {
// return JSON.toJSONString(this);
// }
// }
// Path: dts-parent/dts-server-share/src/main/java/org/github/dtsopensource/server/share/schedule/TaskTrackerContext.java
import java.io.Serializable;
import org.github.dtsopensource.server.share.DTSConfig;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.annotation.JSONField;
import lombok.Getter;
import lombok.Setter;
package org.github.dtsopensource.server.share.schedule;
/**
* @author ligaofeng 2016年12月14日 上午11:10:45
*/
@Getter
@Setter
public class TaskTrackerContext implements Serializable {
private static final long serialVersionUID = 1612166307850489500L;
| private DTSConfig dtsConfig;
|
adealjason/dtsopensource | dts-parent/dts-schedule/src/main/java/org/github/dtsopensource/schedule/timerParse/springcron/SpringCronParse.java | // Path: dts-parent/dts-server-share/src/main/java/org/github/dtsopensource/server/share/exception/DTSRuntimeException.java
// public class DTSRuntimeException extends RuntimeException {
//
// private static final long serialVersionUID = 4328158740883926572L;
//
// /**
// * init DTSRuntimeException
// */
// public DTSRuntimeException() {
// super();
// }
//
// /**
// * init DTSRuntimeException
// *
// * @param message
// */
// public DTSRuntimeException(String message) {
// super(message);
// }
//
// /**
// * init DTSRuntimeException
// *
// * @param message
// * @param cause
// */
// public DTSRuntimeException(String message, Throwable cause) {
// super(message, cause);
// }
//
// /**
// * init DTSRuntimeException
// *
// * @param cause
// */
// public DTSRuntimeException(Throwable cause) {
// super(cause);
// }
//
// /**
// * init DTSRuntimeException
// *
// * @param message
// * @param cause
// * @param enableSuppression
// * @param writableStackTrace
// */
// public DTSRuntimeException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
// super(message, cause, enableSuppression, writableStackTrace);
// }
// }
| import java.util.Date;
import javax.annotation.PostConstruct;
import org.apache.commons.lang.StringUtils;
import org.github.dtsopensource.schedule.IJobTimerParse;
import org.github.dtsopensource.server.share.exception.DTSRuntimeException;
import com.alibaba.fastjson.JSON;
import lombok.Getter;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
| package org.github.dtsopensource.schedule.timerParse.springcron;
/**
* @author ligaofeng 2016年12月14日 下午2:59:12
*/
@Slf4j
public class SpringCronParse implements IJobTimerParse {
private Object lock = new Object();
private Date lastExecuteDate = null;
private CronExpressionEx exp;
@Getter
@Setter
private String cron;
@PostConstruct
public void initCronExpression() {
if (StringUtils.isEmpty(cron)) {
| // Path: dts-parent/dts-server-share/src/main/java/org/github/dtsopensource/server/share/exception/DTSRuntimeException.java
// public class DTSRuntimeException extends RuntimeException {
//
// private static final long serialVersionUID = 4328158740883926572L;
//
// /**
// * init DTSRuntimeException
// */
// public DTSRuntimeException() {
// super();
// }
//
// /**
// * init DTSRuntimeException
// *
// * @param message
// */
// public DTSRuntimeException(String message) {
// super(message);
// }
//
// /**
// * init DTSRuntimeException
// *
// * @param message
// * @param cause
// */
// public DTSRuntimeException(String message, Throwable cause) {
// super(message, cause);
// }
//
// /**
// * init DTSRuntimeException
// *
// * @param cause
// */
// public DTSRuntimeException(Throwable cause) {
// super(cause);
// }
//
// /**
// * init DTSRuntimeException
// *
// * @param message
// * @param cause
// * @param enableSuppression
// * @param writableStackTrace
// */
// public DTSRuntimeException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
// super(message, cause, enableSuppression, writableStackTrace);
// }
// }
// Path: dts-parent/dts-schedule/src/main/java/org/github/dtsopensource/schedule/timerParse/springcron/SpringCronParse.java
import java.util.Date;
import javax.annotation.PostConstruct;
import org.apache.commons.lang.StringUtils;
import org.github.dtsopensource.schedule.IJobTimerParse;
import org.github.dtsopensource.server.share.exception.DTSRuntimeException;
import com.alibaba.fastjson.JSON;
import lombok.Getter;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
package org.github.dtsopensource.schedule.timerParse.springcron;
/**
* @author ligaofeng 2016年12月14日 下午2:59:12
*/
@Slf4j
public class SpringCronParse implements IJobTimerParse {
private Object lock = new Object();
private Date lastExecuteDate = null;
private CronExpressionEx exp;
@Getter
@Setter
private String cron;
@PostConstruct
public void initCronExpression() {
if (StringUtils.isEmpty(cron)) {
| throw new DTSRuntimeException("spring cron表达式尚未配置");
|
adealjason/dtsopensource | dts-parent/dts-server-web/src/main/java/org/github/dtsopensource/server/web/handler/HttpAdapterManager.java | // Path: dts-parent/dts-server-share/src/main/java/org/github/dtsopensource/server/share/ResultBase.java
// @Data
// public class ResultBase<T> implements Serializable {
//
// private static final long serialVersionUID = 2297155012372998859L;
//
// private DTSResultCode dtsResultCode;
//
// private String message;
//
// private T value;
//
// /**
// * @return
// */
// public boolean isSucess() {
// return DTSResultCode.SUCCESS == this.getDtsResultCode();
// }
//
// /**
// * @param errorMessage
// */
// public void addMessage(String errorMessage) {
// if (message != null && message.trim().length() > 0) {
// message = message.concat("|").concat(errorMessage);
// } else {
// message = errorMessage;
// }
// }
// }
//
// Path: dts-parent/dts-server-share/src/main/java/org/github/dtsopensource/server/share/exception/DTSBizException.java
// public class DTSBizException extends Exception {
//
// private static final long serialVersionUID = 3473398255173602638L;
//
// /**
// * init BizException
// */
// public DTSBizException() {
// super();
// }
//
// /**
// * init BizException
// *
// * @param message
// */
// public DTSBizException(String message) {
// super(message);
// }
//
// /**
// * init BizException
// *
// * @param message
// * @param cause
// */
// public DTSBizException(String message, Throwable cause) {
// super(message, cause);
// }
//
// /**
// * init BizException
// *
// * @param cause
// */
// public DTSBizException(Throwable cause) {
// super(cause);
// }
//
// /**
// * init BizException
// *
// * @param message
// * @param cause
// * @param enableSuppression
// * @param writableStackTrace
// */
// public DTSBizException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
// super(message, cause, enableSuppression, writableStackTrace);
// }
// }
| import java.util.Map;
import org.github.dtsopensource.server.share.DTSResultCode;
import org.github.dtsopensource.server.share.ResultBase;
import org.github.dtsopensource.server.share.exception.DTSBizException;
import org.github.dtsopensource.server.share.protocol.ProtocolConstance;
import org.github.dtsopensource.server.share.protocol.ProtocolMethod;
| package org.github.dtsopensource.server.web.handler;
/**
* @author ligaofeng 2016年12月18日 上午1:53:38
*/
public abstract class HttpAdapterManager {
/**
* 路由处理
*
* @param params
* @throws DTSBizException
*/
public void adapter(Map<String, Object> params) throws DTSBizException {
String operation = (String) params.get(ProtocolConstance.requestStoreOperation);
ProtocolMethod protocolmethod = ProtocolMethod.valueOf(operation);
this.handle(protocolmethod, params);
}
/**
* @param protocolmethod
* @param params
*/
protected abstract void handle(ProtocolMethod protocolmethod, Map<String, Object> params);
protected void unsupprotMethod(Map<String, Object> params) {
| // Path: dts-parent/dts-server-share/src/main/java/org/github/dtsopensource/server/share/ResultBase.java
// @Data
// public class ResultBase<T> implements Serializable {
//
// private static final long serialVersionUID = 2297155012372998859L;
//
// private DTSResultCode dtsResultCode;
//
// private String message;
//
// private T value;
//
// /**
// * @return
// */
// public boolean isSucess() {
// return DTSResultCode.SUCCESS == this.getDtsResultCode();
// }
//
// /**
// * @param errorMessage
// */
// public void addMessage(String errorMessage) {
// if (message != null && message.trim().length() > 0) {
// message = message.concat("|").concat(errorMessage);
// } else {
// message = errorMessage;
// }
// }
// }
//
// Path: dts-parent/dts-server-share/src/main/java/org/github/dtsopensource/server/share/exception/DTSBizException.java
// public class DTSBizException extends Exception {
//
// private static final long serialVersionUID = 3473398255173602638L;
//
// /**
// * init BizException
// */
// public DTSBizException() {
// super();
// }
//
// /**
// * init BizException
// *
// * @param message
// */
// public DTSBizException(String message) {
// super(message);
// }
//
// /**
// * init BizException
// *
// * @param message
// * @param cause
// */
// public DTSBizException(String message, Throwable cause) {
// super(message, cause);
// }
//
// /**
// * init BizException
// *
// * @param cause
// */
// public DTSBizException(Throwable cause) {
// super(cause);
// }
//
// /**
// * init BizException
// *
// * @param message
// * @param cause
// * @param enableSuppression
// * @param writableStackTrace
// */
// public DTSBizException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
// super(message, cause, enableSuppression, writableStackTrace);
// }
// }
// Path: dts-parent/dts-server-web/src/main/java/org/github/dtsopensource/server/web/handler/HttpAdapterManager.java
import java.util.Map;
import org.github.dtsopensource.server.share.DTSResultCode;
import org.github.dtsopensource.server.share.ResultBase;
import org.github.dtsopensource.server.share.exception.DTSBizException;
import org.github.dtsopensource.server.share.protocol.ProtocolConstance;
import org.github.dtsopensource.server.share.protocol.ProtocolMethod;
package org.github.dtsopensource.server.web.handler;
/**
* @author ligaofeng 2016年12月18日 上午1:53:38
*/
public abstract class HttpAdapterManager {
/**
* 路由处理
*
* @param params
* @throws DTSBizException
*/
public void adapter(Map<String, Object> params) throws DTSBizException {
String operation = (String) params.get(ProtocolConstance.requestStoreOperation);
ProtocolMethod protocolmethod = ProtocolMethod.valueOf(operation);
this.handle(protocolmethod, params);
}
/**
* @param protocolmethod
* @param params
*/
protected abstract void handle(ProtocolMethod protocolmethod, Map<String, Object> params);
protected void unsupprotMethod(Map<String, Object> params) {
| ResultBase<String> resultBase = new ResultBase<String>();
|
adealjason/dtsopensource | dts-parent/dts-server-share/src/main/java/org/github/dtsopensource/server/share/DTSContext.java | // Path: dts-parent/dts-server-share/src/main/java/org/github/dtsopensource/server/share/exception/DTSRuntimeException.java
// public class DTSRuntimeException extends RuntimeException {
//
// private static final long serialVersionUID = 4328158740883926572L;
//
// /**
// * init DTSRuntimeException
// */
// public DTSRuntimeException() {
// super();
// }
//
// /**
// * init DTSRuntimeException
// *
// * @param message
// */
// public DTSRuntimeException(String message) {
// super(message);
// }
//
// /**
// * init DTSRuntimeException
// *
// * @param message
// * @param cause
// */
// public DTSRuntimeException(String message, Throwable cause) {
// super(message, cause);
// }
//
// /**
// * init DTSRuntimeException
// *
// * @param cause
// */
// public DTSRuntimeException(Throwable cause) {
// super(cause);
// }
//
// /**
// * init DTSRuntimeException
// *
// * @param message
// * @param cause
// * @param enableSuppression
// * @param writableStackTrace
// */
// public DTSRuntimeException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
// super(message, cause, enableSuppression, writableStackTrace);
// }
// }
//
// Path: dts-parent/dts-server-share/src/main/java/org/github/dtsopensource/server/share/rule/entity/ActivityRuleEntity.java
// @Getter
// @Setter
// public class ActivityRuleEntity implements Serializable {
//
// private static final long serialVersionUID = 106899067427742570L;
//
// private String bizType;
//
// private String bizTypeName;
//
// private String app;
//
// private String appCname;
//
// private List<ActivityActionRuleEntity> activityActionRules;
//
// /**
// * 根据clazzName获取bizAction配置
// *
// * @param clazzName dts-server配置的信息
// * @return
// */
// public ActivityActionRuleEntity getActivityActionRuleEntity(String clazzName) {
// if (activityActionRules == null || activityActionRules.isEmpty()) {
// throw new DTSRuntimeException("尚未配置" + clazzName + "的bizAction,请联系dts-server管理员配置");
// }
// for (ActivityActionRuleEntity an : activityActionRules) {
// if (an.getClazzName().equals(clazzName)) {
// return an;
// }
// }
// throw new DTSRuntimeException("尚未配置" + clazzName + "的bizAction,请联系dts-server管理员配置");
// }
//
// @Override
// public String toString() {
// return JSON.toJSONString(this);
// }
//
// /**
// * ActivityRuleEntity.builder
// *
// * @param builder
// */
// public ActivityRuleEntity(Builder builder) {
// this.app = builder.app;
// this.appCname = builder.appCname;
// this.bizType = builder.bizType;
// this.bizTypeName = builder.bizTypeName;
// }
//
// /**
// * used for fastjson
// */
// public ActivityRuleEntity() {
// }
//
// @Getter
// public static class Builder {
// private String bizType;
//
// private String bizTypeName;
//
// private String app;
//
// private String appCname;
//
// public Builder(String bizType) {
// this.bizType = bizType;
// }
//
// public Builder setBizTypeName(String bizTypeName) {
// this.bizTypeName = bizTypeName;
// return this;
// }
//
// public Builder setApp(String app) {
// this.app = app;
// return this;
// }
//
// public Builder setAppCname(String appCname) {
// this.appCname = appCname;
// return this;
// }
//
// public ActivityRuleEntity build() {
// return new ActivityRuleEntity(this);
// }
// }
//
// }
| import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;
import org.github.dtsopensource.server.share.exception.DTSRuntimeException;
import org.github.dtsopensource.server.share.rule.entity.ActivityRuleEntity;
import com.alibaba.fastjson.JSON;
import lombok.Getter;
import lombok.Setter;
| package org.github.dtsopensource.server.share;
/**
* @author ligaofeng 2016年12月11日 上午11:42:49
*/
@Getter
@Setter
public class DTSContext implements Serializable {
private static final long serialVersionUID = -6560080158776388882L;
private static final ThreadLocal<DTSContext> LOCAL = new ThreadLocal<DTSContext>() {
@Override
protected DTSContext initialValue() {
return new DTSContext();
}
};
private String activityId;
| // Path: dts-parent/dts-server-share/src/main/java/org/github/dtsopensource/server/share/exception/DTSRuntimeException.java
// public class DTSRuntimeException extends RuntimeException {
//
// private static final long serialVersionUID = 4328158740883926572L;
//
// /**
// * init DTSRuntimeException
// */
// public DTSRuntimeException() {
// super();
// }
//
// /**
// * init DTSRuntimeException
// *
// * @param message
// */
// public DTSRuntimeException(String message) {
// super(message);
// }
//
// /**
// * init DTSRuntimeException
// *
// * @param message
// * @param cause
// */
// public DTSRuntimeException(String message, Throwable cause) {
// super(message, cause);
// }
//
// /**
// * init DTSRuntimeException
// *
// * @param cause
// */
// public DTSRuntimeException(Throwable cause) {
// super(cause);
// }
//
// /**
// * init DTSRuntimeException
// *
// * @param message
// * @param cause
// * @param enableSuppression
// * @param writableStackTrace
// */
// public DTSRuntimeException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
// super(message, cause, enableSuppression, writableStackTrace);
// }
// }
//
// Path: dts-parent/dts-server-share/src/main/java/org/github/dtsopensource/server/share/rule/entity/ActivityRuleEntity.java
// @Getter
// @Setter
// public class ActivityRuleEntity implements Serializable {
//
// private static final long serialVersionUID = 106899067427742570L;
//
// private String bizType;
//
// private String bizTypeName;
//
// private String app;
//
// private String appCname;
//
// private List<ActivityActionRuleEntity> activityActionRules;
//
// /**
// * 根据clazzName获取bizAction配置
// *
// * @param clazzName dts-server配置的信息
// * @return
// */
// public ActivityActionRuleEntity getActivityActionRuleEntity(String clazzName) {
// if (activityActionRules == null || activityActionRules.isEmpty()) {
// throw new DTSRuntimeException("尚未配置" + clazzName + "的bizAction,请联系dts-server管理员配置");
// }
// for (ActivityActionRuleEntity an : activityActionRules) {
// if (an.getClazzName().equals(clazzName)) {
// return an;
// }
// }
// throw new DTSRuntimeException("尚未配置" + clazzName + "的bizAction,请联系dts-server管理员配置");
// }
//
// @Override
// public String toString() {
// return JSON.toJSONString(this);
// }
//
// /**
// * ActivityRuleEntity.builder
// *
// * @param builder
// */
// public ActivityRuleEntity(Builder builder) {
// this.app = builder.app;
// this.appCname = builder.appCname;
// this.bizType = builder.bizType;
// this.bizTypeName = builder.bizTypeName;
// }
//
// /**
// * used for fastjson
// */
// public ActivityRuleEntity() {
// }
//
// @Getter
// public static class Builder {
// private String bizType;
//
// private String bizTypeName;
//
// private String app;
//
// private String appCname;
//
// public Builder(String bizType) {
// this.bizType = bizType;
// }
//
// public Builder setBizTypeName(String bizTypeName) {
// this.bizTypeName = bizTypeName;
// return this;
// }
//
// public Builder setApp(String app) {
// this.app = app;
// return this;
// }
//
// public Builder setAppCname(String appCname) {
// this.appCname = appCname;
// return this;
// }
//
// public ActivityRuleEntity build() {
// return new ActivityRuleEntity(this);
// }
// }
//
// }
// Path: dts-parent/dts-server-share/src/main/java/org/github/dtsopensource/server/share/DTSContext.java
import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;
import org.github.dtsopensource.server.share.exception.DTSRuntimeException;
import org.github.dtsopensource.server.share.rule.entity.ActivityRuleEntity;
import com.alibaba.fastjson.JSON;
import lombok.Getter;
import lombok.Setter;
package org.github.dtsopensource.server.share;
/**
* @author ligaofeng 2016年12月11日 上午11:42:49
*/
@Getter
@Setter
public class DTSContext implements Serializable {
private static final long serialVersionUID = -6560080158776388882L;
private static final ThreadLocal<DTSContext> LOCAL = new ThreadLocal<DTSContext>() {
@Override
protected DTSContext initialValue() {
return new DTSContext();
}
};
private String activityId;
| private ActivityRuleEntity activityRuleEntity;
|
opentok/opentok-android-sdk-samples | Archiving-Java/app/src/main/java/com/tokbox/sample/archiving/MainActivity.java | // Path: Archiving-Java/app/src/main/java/com/tokbox/sample/archiving/network/APIService.java
// public interface APIService {
//
// @GET("session")
// Call<GetSessionResponse> getSession();
//
// @POST("archive/start")
// @Headers("Content-Type: application/json")
// Call<Void> startArchive(@Body StartArchiveRequest startArchiveRequest);
//
// @POST("archive/{archiveId}/stop")
// Call<Void> stopArchive(@Path("archiveId") String archiveId);
// }
//
// Path: Archiving-Java/app/src/main/java/com/tokbox/sample/archiving/network/EmptyCallback.java
// public class EmptyCallback<T> implements Callback<T> {
// @Override
// public void onResponse(Call<T> call, Response<T> response) {
//
// }
//
// @Override
// public void onFailure(Call<T> call, Throwable t) {
//
// }
// }
//
// Path: Archiving-Java/app/src/main/java/com/tokbox/sample/archiving/network/GetSessionResponse.java
// public class GetSessionResponse {
// @Json(name = "apiKey") public String apiKey;
// @Json(name = "sessionId") public String sessionId;
// @Json(name = "token") public String token;
// }
//
// Path: Archiving-Java/app/src/main/java/com/tokbox/sample/archiving/network/StartArchiveRequest.java
// public class StartArchiveRequest {
// @Json(name = "sessionId") public String sessionId;
// }
| import android.Manifest;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import com.opentok.android.BaseVideoRenderer;
import com.opentok.android.OpentokError;
import com.opentok.android.Publisher;
import com.opentok.android.PublisherKit;
import com.opentok.android.Session;
import com.opentok.android.Stream;
import com.opentok.android.Subscriber;
import com.opentok.android.SubscriberKit;
import com.tokbox.sample.archiving.network.APIService;
import com.tokbox.sample.archiving.network.EmptyCallback;
import com.tokbox.sample.archiving.network.GetSessionResponse;
import com.tokbox.sample.archiving.network.StartArchiveRequest;
import okhttp3.OkHttpClient;
import okhttp3.logging.HttpLoggingInterceptor;
import okhttp3.logging.HttpLoggingInterceptor.Level;
import pub.devrel.easypermissions.AfterPermissionGranted;
import pub.devrel.easypermissions.EasyPermissions;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.moshi.MoshiConverterFactory;
import java.util.List; | package com.tokbox.sample.archiving;
public class MainActivity extends AppCompatActivity implements EasyPermissions.PermissionCallbacks {
private static final String TAG = MainActivity.class.getSimpleName();
private static final int PERMISSIONS_REQUEST_CODE = 124;
private Retrofit retrofit; | // Path: Archiving-Java/app/src/main/java/com/tokbox/sample/archiving/network/APIService.java
// public interface APIService {
//
// @GET("session")
// Call<GetSessionResponse> getSession();
//
// @POST("archive/start")
// @Headers("Content-Type: application/json")
// Call<Void> startArchive(@Body StartArchiveRequest startArchiveRequest);
//
// @POST("archive/{archiveId}/stop")
// Call<Void> stopArchive(@Path("archiveId") String archiveId);
// }
//
// Path: Archiving-Java/app/src/main/java/com/tokbox/sample/archiving/network/EmptyCallback.java
// public class EmptyCallback<T> implements Callback<T> {
// @Override
// public void onResponse(Call<T> call, Response<T> response) {
//
// }
//
// @Override
// public void onFailure(Call<T> call, Throwable t) {
//
// }
// }
//
// Path: Archiving-Java/app/src/main/java/com/tokbox/sample/archiving/network/GetSessionResponse.java
// public class GetSessionResponse {
// @Json(name = "apiKey") public String apiKey;
// @Json(name = "sessionId") public String sessionId;
// @Json(name = "token") public String token;
// }
//
// Path: Archiving-Java/app/src/main/java/com/tokbox/sample/archiving/network/StartArchiveRequest.java
// public class StartArchiveRequest {
// @Json(name = "sessionId") public String sessionId;
// }
// Path: Archiving-Java/app/src/main/java/com/tokbox/sample/archiving/MainActivity.java
import android.Manifest;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import com.opentok.android.BaseVideoRenderer;
import com.opentok.android.OpentokError;
import com.opentok.android.Publisher;
import com.opentok.android.PublisherKit;
import com.opentok.android.Session;
import com.opentok.android.Stream;
import com.opentok.android.Subscriber;
import com.opentok.android.SubscriberKit;
import com.tokbox.sample.archiving.network.APIService;
import com.tokbox.sample.archiving.network.EmptyCallback;
import com.tokbox.sample.archiving.network.GetSessionResponse;
import com.tokbox.sample.archiving.network.StartArchiveRequest;
import okhttp3.OkHttpClient;
import okhttp3.logging.HttpLoggingInterceptor;
import okhttp3.logging.HttpLoggingInterceptor.Level;
import pub.devrel.easypermissions.AfterPermissionGranted;
import pub.devrel.easypermissions.EasyPermissions;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.moshi.MoshiConverterFactory;
import java.util.List;
package com.tokbox.sample.archiving;
public class MainActivity extends AppCompatActivity implements EasyPermissions.PermissionCallbacks {
private static final String TAG = MainActivity.class.getSimpleName();
private static final int PERMISSIONS_REQUEST_CODE = 124;
private Retrofit retrofit; | private APIService apiService; |
opentok/opentok-android-sdk-samples | Archiving-Java/app/src/main/java/com/tokbox/sample/archiving/MainActivity.java | // Path: Archiving-Java/app/src/main/java/com/tokbox/sample/archiving/network/APIService.java
// public interface APIService {
//
// @GET("session")
// Call<GetSessionResponse> getSession();
//
// @POST("archive/start")
// @Headers("Content-Type: application/json")
// Call<Void> startArchive(@Body StartArchiveRequest startArchiveRequest);
//
// @POST("archive/{archiveId}/stop")
// Call<Void> stopArchive(@Path("archiveId") String archiveId);
// }
//
// Path: Archiving-Java/app/src/main/java/com/tokbox/sample/archiving/network/EmptyCallback.java
// public class EmptyCallback<T> implements Callback<T> {
// @Override
// public void onResponse(Call<T> call, Response<T> response) {
//
// }
//
// @Override
// public void onFailure(Call<T> call, Throwable t) {
//
// }
// }
//
// Path: Archiving-Java/app/src/main/java/com/tokbox/sample/archiving/network/GetSessionResponse.java
// public class GetSessionResponse {
// @Json(name = "apiKey") public String apiKey;
// @Json(name = "sessionId") public String sessionId;
// @Json(name = "token") public String token;
// }
//
// Path: Archiving-Java/app/src/main/java/com/tokbox/sample/archiving/network/StartArchiveRequest.java
// public class StartArchiveRequest {
// @Json(name = "sessionId") public String sessionId;
// }
| import android.Manifest;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import com.opentok.android.BaseVideoRenderer;
import com.opentok.android.OpentokError;
import com.opentok.android.Publisher;
import com.opentok.android.PublisherKit;
import com.opentok.android.Session;
import com.opentok.android.Stream;
import com.opentok.android.Subscriber;
import com.opentok.android.SubscriberKit;
import com.tokbox.sample.archiving.network.APIService;
import com.tokbox.sample.archiving.network.EmptyCallback;
import com.tokbox.sample.archiving.network.GetSessionResponse;
import com.tokbox.sample.archiving.network.StartArchiveRequest;
import okhttp3.OkHttpClient;
import okhttp3.logging.HttpLoggingInterceptor;
import okhttp3.logging.HttpLoggingInterceptor.Level;
import pub.devrel.easypermissions.AfterPermissionGranted;
import pub.devrel.easypermissions.EasyPermissions;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.moshi.MoshiConverterFactory;
import java.util.List; | super.onRequestPermissionsResult(requestCode, permissions, grantResults);
EasyPermissions.onRequestPermissionsResult(requestCode, permissions, grantResults, this);
}
@Override
public void onPermissionsGranted(int requestCode, List<String> perms) {
Log.d(TAG, "onPermissionsGranted:" + requestCode + ": " + perms);
}
@Override
public void onPermissionsDenied(int requestCode, List<String> perms) {
finishWithMessage("onPermissionsDenied: " + requestCode + ": " + perms);
}
@AfterPermissionGranted(PERMISSIONS_REQUEST_CODE)
private void requestPermissions() {
String[] perms = {Manifest.permission.INTERNET, Manifest.permission.CAMERA, Manifest.permission.RECORD_AUDIO};
if (EasyPermissions.hasPermissions(this, perms)) {
initRetrofit();
getSession();
} else {
EasyPermissions.requestPermissions(this, getString(R.string.rationale_video_app), PERMISSIONS_REQUEST_CODE, perms);
}
}
/* Make a request for session data */
private void getSession() {
Log.i(TAG, "getSession");
| // Path: Archiving-Java/app/src/main/java/com/tokbox/sample/archiving/network/APIService.java
// public interface APIService {
//
// @GET("session")
// Call<GetSessionResponse> getSession();
//
// @POST("archive/start")
// @Headers("Content-Type: application/json")
// Call<Void> startArchive(@Body StartArchiveRequest startArchiveRequest);
//
// @POST("archive/{archiveId}/stop")
// Call<Void> stopArchive(@Path("archiveId") String archiveId);
// }
//
// Path: Archiving-Java/app/src/main/java/com/tokbox/sample/archiving/network/EmptyCallback.java
// public class EmptyCallback<T> implements Callback<T> {
// @Override
// public void onResponse(Call<T> call, Response<T> response) {
//
// }
//
// @Override
// public void onFailure(Call<T> call, Throwable t) {
//
// }
// }
//
// Path: Archiving-Java/app/src/main/java/com/tokbox/sample/archiving/network/GetSessionResponse.java
// public class GetSessionResponse {
// @Json(name = "apiKey") public String apiKey;
// @Json(name = "sessionId") public String sessionId;
// @Json(name = "token") public String token;
// }
//
// Path: Archiving-Java/app/src/main/java/com/tokbox/sample/archiving/network/StartArchiveRequest.java
// public class StartArchiveRequest {
// @Json(name = "sessionId") public String sessionId;
// }
// Path: Archiving-Java/app/src/main/java/com/tokbox/sample/archiving/MainActivity.java
import android.Manifest;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import com.opentok.android.BaseVideoRenderer;
import com.opentok.android.OpentokError;
import com.opentok.android.Publisher;
import com.opentok.android.PublisherKit;
import com.opentok.android.Session;
import com.opentok.android.Stream;
import com.opentok.android.Subscriber;
import com.opentok.android.SubscriberKit;
import com.tokbox.sample.archiving.network.APIService;
import com.tokbox.sample.archiving.network.EmptyCallback;
import com.tokbox.sample.archiving.network.GetSessionResponse;
import com.tokbox.sample.archiving.network.StartArchiveRequest;
import okhttp3.OkHttpClient;
import okhttp3.logging.HttpLoggingInterceptor;
import okhttp3.logging.HttpLoggingInterceptor.Level;
import pub.devrel.easypermissions.AfterPermissionGranted;
import pub.devrel.easypermissions.EasyPermissions;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.moshi.MoshiConverterFactory;
import java.util.List;
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
EasyPermissions.onRequestPermissionsResult(requestCode, permissions, grantResults, this);
}
@Override
public void onPermissionsGranted(int requestCode, List<String> perms) {
Log.d(TAG, "onPermissionsGranted:" + requestCode + ": " + perms);
}
@Override
public void onPermissionsDenied(int requestCode, List<String> perms) {
finishWithMessage("onPermissionsDenied: " + requestCode + ": " + perms);
}
@AfterPermissionGranted(PERMISSIONS_REQUEST_CODE)
private void requestPermissions() {
String[] perms = {Manifest.permission.INTERNET, Manifest.permission.CAMERA, Manifest.permission.RECORD_AUDIO};
if (EasyPermissions.hasPermissions(this, perms)) {
initRetrofit();
getSession();
} else {
EasyPermissions.requestPermissions(this, getString(R.string.rationale_video_app), PERMISSIONS_REQUEST_CODE, perms);
}
}
/* Make a request for session data */
private void getSession() {
Log.i(TAG, "getSession");
| Call<GetSessionResponse> call = apiService.getSession(); |
opentok/opentok-android-sdk-samples | Archiving-Java/app/src/main/java/com/tokbox/sample/archiving/MainActivity.java | // Path: Archiving-Java/app/src/main/java/com/tokbox/sample/archiving/network/APIService.java
// public interface APIService {
//
// @GET("session")
// Call<GetSessionResponse> getSession();
//
// @POST("archive/start")
// @Headers("Content-Type: application/json")
// Call<Void> startArchive(@Body StartArchiveRequest startArchiveRequest);
//
// @POST("archive/{archiveId}/stop")
// Call<Void> stopArchive(@Path("archiveId") String archiveId);
// }
//
// Path: Archiving-Java/app/src/main/java/com/tokbox/sample/archiving/network/EmptyCallback.java
// public class EmptyCallback<T> implements Callback<T> {
// @Override
// public void onResponse(Call<T> call, Response<T> response) {
//
// }
//
// @Override
// public void onFailure(Call<T> call, Throwable t) {
//
// }
// }
//
// Path: Archiving-Java/app/src/main/java/com/tokbox/sample/archiving/network/GetSessionResponse.java
// public class GetSessionResponse {
// @Json(name = "apiKey") public String apiKey;
// @Json(name = "sessionId") public String sessionId;
// @Json(name = "token") public String token;
// }
//
// Path: Archiving-Java/app/src/main/java/com/tokbox/sample/archiving/network/StartArchiveRequest.java
// public class StartArchiveRequest {
// @Json(name = "sessionId") public String sessionId;
// }
| import android.Manifest;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import com.opentok.android.BaseVideoRenderer;
import com.opentok.android.OpentokError;
import com.opentok.android.Publisher;
import com.opentok.android.PublisherKit;
import com.opentok.android.Session;
import com.opentok.android.Stream;
import com.opentok.android.Subscriber;
import com.opentok.android.SubscriberKit;
import com.tokbox.sample.archiving.network.APIService;
import com.tokbox.sample.archiving.network.EmptyCallback;
import com.tokbox.sample.archiving.network.GetSessionResponse;
import com.tokbox.sample.archiving.network.StartArchiveRequest;
import okhttp3.OkHttpClient;
import okhttp3.logging.HttpLoggingInterceptor;
import okhttp3.logging.HttpLoggingInterceptor.Level;
import pub.devrel.easypermissions.AfterPermissionGranted;
import pub.devrel.easypermissions.EasyPermissions;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.moshi.MoshiConverterFactory;
import java.util.List; | @Override
public void onResponse(Call<GetSessionResponse> call, Response<GetSessionResponse> response) {
GetSessionResponse body = response.body();
initializeSession(body.apiKey, body.sessionId, body.token);
}
@Override
public void onFailure(Call<GetSessionResponse> call, Throwable t) {
throw new RuntimeException(t.getMessage());
}
});
}
private void initializeSession(String apiKey, String sessionId, String token) {
Log.i(TAG, "apiKey: " + apiKey);
Log.i(TAG, "sessionId: " + sessionId);
Log.i(TAG, "token: " + token);
this.sessionId = sessionId;
session = new Session.Builder(this, apiKey, sessionId).build();
session.setSessionListener(sessionListener);
session.setArchiveListener(archiveListener);
session.connect(token);
}
private void startArchive() {
Log.i(TAG, "startArchive");
if (session != null) { | // Path: Archiving-Java/app/src/main/java/com/tokbox/sample/archiving/network/APIService.java
// public interface APIService {
//
// @GET("session")
// Call<GetSessionResponse> getSession();
//
// @POST("archive/start")
// @Headers("Content-Type: application/json")
// Call<Void> startArchive(@Body StartArchiveRequest startArchiveRequest);
//
// @POST("archive/{archiveId}/stop")
// Call<Void> stopArchive(@Path("archiveId") String archiveId);
// }
//
// Path: Archiving-Java/app/src/main/java/com/tokbox/sample/archiving/network/EmptyCallback.java
// public class EmptyCallback<T> implements Callback<T> {
// @Override
// public void onResponse(Call<T> call, Response<T> response) {
//
// }
//
// @Override
// public void onFailure(Call<T> call, Throwable t) {
//
// }
// }
//
// Path: Archiving-Java/app/src/main/java/com/tokbox/sample/archiving/network/GetSessionResponse.java
// public class GetSessionResponse {
// @Json(name = "apiKey") public String apiKey;
// @Json(name = "sessionId") public String sessionId;
// @Json(name = "token") public String token;
// }
//
// Path: Archiving-Java/app/src/main/java/com/tokbox/sample/archiving/network/StartArchiveRequest.java
// public class StartArchiveRequest {
// @Json(name = "sessionId") public String sessionId;
// }
// Path: Archiving-Java/app/src/main/java/com/tokbox/sample/archiving/MainActivity.java
import android.Manifest;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import com.opentok.android.BaseVideoRenderer;
import com.opentok.android.OpentokError;
import com.opentok.android.Publisher;
import com.opentok.android.PublisherKit;
import com.opentok.android.Session;
import com.opentok.android.Stream;
import com.opentok.android.Subscriber;
import com.opentok.android.SubscriberKit;
import com.tokbox.sample.archiving.network.APIService;
import com.tokbox.sample.archiving.network.EmptyCallback;
import com.tokbox.sample.archiving.network.GetSessionResponse;
import com.tokbox.sample.archiving.network.StartArchiveRequest;
import okhttp3.OkHttpClient;
import okhttp3.logging.HttpLoggingInterceptor;
import okhttp3.logging.HttpLoggingInterceptor.Level;
import pub.devrel.easypermissions.AfterPermissionGranted;
import pub.devrel.easypermissions.EasyPermissions;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.moshi.MoshiConverterFactory;
import java.util.List;
@Override
public void onResponse(Call<GetSessionResponse> call, Response<GetSessionResponse> response) {
GetSessionResponse body = response.body();
initializeSession(body.apiKey, body.sessionId, body.token);
}
@Override
public void onFailure(Call<GetSessionResponse> call, Throwable t) {
throw new RuntimeException(t.getMessage());
}
});
}
private void initializeSession(String apiKey, String sessionId, String token) {
Log.i(TAG, "apiKey: " + apiKey);
Log.i(TAG, "sessionId: " + sessionId);
Log.i(TAG, "token: " + token);
this.sessionId = sessionId;
session = new Session.Builder(this, apiKey, sessionId).build();
session.setSessionListener(sessionListener);
session.setArchiveListener(archiveListener);
session.connect(token);
}
private void startArchive() {
Log.i(TAG, "startArchive");
if (session != null) { | StartArchiveRequest startArchiveRequest = new StartArchiveRequest(); |
opentok/opentok-android-sdk-samples | Archiving-Java/app/src/main/java/com/tokbox/sample/archiving/MainActivity.java | // Path: Archiving-Java/app/src/main/java/com/tokbox/sample/archiving/network/APIService.java
// public interface APIService {
//
// @GET("session")
// Call<GetSessionResponse> getSession();
//
// @POST("archive/start")
// @Headers("Content-Type: application/json")
// Call<Void> startArchive(@Body StartArchiveRequest startArchiveRequest);
//
// @POST("archive/{archiveId}/stop")
// Call<Void> stopArchive(@Path("archiveId") String archiveId);
// }
//
// Path: Archiving-Java/app/src/main/java/com/tokbox/sample/archiving/network/EmptyCallback.java
// public class EmptyCallback<T> implements Callback<T> {
// @Override
// public void onResponse(Call<T> call, Response<T> response) {
//
// }
//
// @Override
// public void onFailure(Call<T> call, Throwable t) {
//
// }
// }
//
// Path: Archiving-Java/app/src/main/java/com/tokbox/sample/archiving/network/GetSessionResponse.java
// public class GetSessionResponse {
// @Json(name = "apiKey") public String apiKey;
// @Json(name = "sessionId") public String sessionId;
// @Json(name = "token") public String token;
// }
//
// Path: Archiving-Java/app/src/main/java/com/tokbox/sample/archiving/network/StartArchiveRequest.java
// public class StartArchiveRequest {
// @Json(name = "sessionId") public String sessionId;
// }
| import android.Manifest;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import com.opentok.android.BaseVideoRenderer;
import com.opentok.android.OpentokError;
import com.opentok.android.Publisher;
import com.opentok.android.PublisherKit;
import com.opentok.android.Session;
import com.opentok.android.Stream;
import com.opentok.android.Subscriber;
import com.opentok.android.SubscriberKit;
import com.tokbox.sample.archiving.network.APIService;
import com.tokbox.sample.archiving.network.EmptyCallback;
import com.tokbox.sample.archiving.network.GetSessionResponse;
import com.tokbox.sample.archiving.network.StartArchiveRequest;
import okhttp3.OkHttpClient;
import okhttp3.logging.HttpLoggingInterceptor;
import okhttp3.logging.HttpLoggingInterceptor.Level;
import pub.devrel.easypermissions.AfterPermissionGranted;
import pub.devrel.easypermissions.EasyPermissions;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.moshi.MoshiConverterFactory;
import java.util.List; |
@Override
public void onFailure(Call<GetSessionResponse> call, Throwable t) {
throw new RuntimeException(t.getMessage());
}
});
}
private void initializeSession(String apiKey, String sessionId, String token) {
Log.i(TAG, "apiKey: " + apiKey);
Log.i(TAG, "sessionId: " + sessionId);
Log.i(TAG, "token: " + token);
this.sessionId = sessionId;
session = new Session.Builder(this, apiKey, sessionId).build();
session.setSessionListener(sessionListener);
session.setArchiveListener(archiveListener);
session.connect(token);
}
private void startArchive() {
Log.i(TAG, "startArchive");
if (session != null) {
StartArchiveRequest startArchiveRequest = new StartArchiveRequest();
startArchiveRequest.sessionId = sessionId;
setStartArchiveEnabled(false);
Call call = apiService.startArchive(startArchiveRequest); | // Path: Archiving-Java/app/src/main/java/com/tokbox/sample/archiving/network/APIService.java
// public interface APIService {
//
// @GET("session")
// Call<GetSessionResponse> getSession();
//
// @POST("archive/start")
// @Headers("Content-Type: application/json")
// Call<Void> startArchive(@Body StartArchiveRequest startArchiveRequest);
//
// @POST("archive/{archiveId}/stop")
// Call<Void> stopArchive(@Path("archiveId") String archiveId);
// }
//
// Path: Archiving-Java/app/src/main/java/com/tokbox/sample/archiving/network/EmptyCallback.java
// public class EmptyCallback<T> implements Callback<T> {
// @Override
// public void onResponse(Call<T> call, Response<T> response) {
//
// }
//
// @Override
// public void onFailure(Call<T> call, Throwable t) {
//
// }
// }
//
// Path: Archiving-Java/app/src/main/java/com/tokbox/sample/archiving/network/GetSessionResponse.java
// public class GetSessionResponse {
// @Json(name = "apiKey") public String apiKey;
// @Json(name = "sessionId") public String sessionId;
// @Json(name = "token") public String token;
// }
//
// Path: Archiving-Java/app/src/main/java/com/tokbox/sample/archiving/network/StartArchiveRequest.java
// public class StartArchiveRequest {
// @Json(name = "sessionId") public String sessionId;
// }
// Path: Archiving-Java/app/src/main/java/com/tokbox/sample/archiving/MainActivity.java
import android.Manifest;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import com.opentok.android.BaseVideoRenderer;
import com.opentok.android.OpentokError;
import com.opentok.android.Publisher;
import com.opentok.android.PublisherKit;
import com.opentok.android.Session;
import com.opentok.android.Stream;
import com.opentok.android.Subscriber;
import com.opentok.android.SubscriberKit;
import com.tokbox.sample.archiving.network.APIService;
import com.tokbox.sample.archiving.network.EmptyCallback;
import com.tokbox.sample.archiving.network.GetSessionResponse;
import com.tokbox.sample.archiving.network.StartArchiveRequest;
import okhttp3.OkHttpClient;
import okhttp3.logging.HttpLoggingInterceptor;
import okhttp3.logging.HttpLoggingInterceptor.Level;
import pub.devrel.easypermissions.AfterPermissionGranted;
import pub.devrel.easypermissions.EasyPermissions;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.moshi.MoshiConverterFactory;
import java.util.List;
@Override
public void onFailure(Call<GetSessionResponse> call, Throwable t) {
throw new RuntimeException(t.getMessage());
}
});
}
private void initializeSession(String apiKey, String sessionId, String token) {
Log.i(TAG, "apiKey: " + apiKey);
Log.i(TAG, "sessionId: " + sessionId);
Log.i(TAG, "token: " + token);
this.sessionId = sessionId;
session = new Session.Builder(this, apiKey, sessionId).build();
session.setSessionListener(sessionListener);
session.setArchiveListener(archiveListener);
session.connect(token);
}
private void startArchive() {
Log.i(TAG, "startArchive");
if (session != null) {
StartArchiveRequest startArchiveRequest = new StartArchiveRequest();
startArchiveRequest.sessionId = sessionId;
setStartArchiveEnabled(false);
Call call = apiService.startArchive(startArchiveRequest); | call.enqueue(new EmptyCallback()); |
opentok/opentok-android-sdk-samples | Basic-Video-Chat-Java/app/src/main/java/com/tokbox/sample/basicvideochat/MainActivity.java | // Path: Basic-Video-Chat-Java/app/src/main/java/com/tokbox/sample/basicvideochat/network/APIService.java
// public interface APIService {
//
// @GET("session")
// Call<GetSessionResponse> getSession();
// }
//
// Path: Basic-Video-Chat-Java/app/src/main/java/com/tokbox/sample/basicvideochat/network/GetSessionResponse.java
// public class GetSessionResponse {
// @Json(name = "apiKey") public String apiKey;
// @Json(name = "sessionId") public String sessionId;
// @Json(name = "token") public String token;
// }
| import android.Manifest;
import android.opengl.GLSurfaceView;
import android.os.Bundle;
import android.util.Log;
import android.widget.FrameLayout;
import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import com.opentok.android.BaseVideoRenderer;
import com.opentok.android.OpentokError;
import com.opentok.android.Publisher;
import com.opentok.android.PublisherKit;
import com.opentok.android.Session;
import com.opentok.android.Stream;
import com.opentok.android.Subscriber;
import com.opentok.android.SubscriberKit;
import com.tokbox.sample.basicvideochat.network.APIService;
import com.tokbox.sample.basicvideochat.network.GetSessionResponse;
import okhttp3.OkHttpClient;
import okhttp3.logging.HttpLoggingInterceptor;
import okhttp3.logging.HttpLoggingInterceptor.Level;
import pub.devrel.easypermissions.AfterPermissionGranted;
import pub.devrel.easypermissions.EasyPermissions;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.moshi.MoshiConverterFactory;
import java.util.List; | package com.tokbox.sample.basicvideochat;
public class MainActivity extends AppCompatActivity implements EasyPermissions.PermissionCallbacks {
private static final String TAG = MainActivity.class.getSimpleName();
private static final int PERMISSIONS_REQUEST_CODE = 124;
private Retrofit retrofit; | // Path: Basic-Video-Chat-Java/app/src/main/java/com/tokbox/sample/basicvideochat/network/APIService.java
// public interface APIService {
//
// @GET("session")
// Call<GetSessionResponse> getSession();
// }
//
// Path: Basic-Video-Chat-Java/app/src/main/java/com/tokbox/sample/basicvideochat/network/GetSessionResponse.java
// public class GetSessionResponse {
// @Json(name = "apiKey") public String apiKey;
// @Json(name = "sessionId") public String sessionId;
// @Json(name = "token") public String token;
// }
// Path: Basic-Video-Chat-Java/app/src/main/java/com/tokbox/sample/basicvideochat/MainActivity.java
import android.Manifest;
import android.opengl.GLSurfaceView;
import android.os.Bundle;
import android.util.Log;
import android.widget.FrameLayout;
import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import com.opentok.android.BaseVideoRenderer;
import com.opentok.android.OpentokError;
import com.opentok.android.Publisher;
import com.opentok.android.PublisherKit;
import com.opentok.android.Session;
import com.opentok.android.Stream;
import com.opentok.android.Subscriber;
import com.opentok.android.SubscriberKit;
import com.tokbox.sample.basicvideochat.network.APIService;
import com.tokbox.sample.basicvideochat.network.GetSessionResponse;
import okhttp3.OkHttpClient;
import okhttp3.logging.HttpLoggingInterceptor;
import okhttp3.logging.HttpLoggingInterceptor.Level;
import pub.devrel.easypermissions.AfterPermissionGranted;
import pub.devrel.easypermissions.EasyPermissions;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.moshi.MoshiConverterFactory;
import java.util.List;
package com.tokbox.sample.basicvideochat;
public class MainActivity extends AppCompatActivity implements EasyPermissions.PermissionCallbacks {
private static final String TAG = MainActivity.class.getSimpleName();
private static final int PERMISSIONS_REQUEST_CODE = 124;
private Retrofit retrofit; | private APIService apiService; |
opentok/opentok-android-sdk-samples | Basic-Video-Chat-Java/app/src/main/java/com/tokbox/sample/basicvideochat/MainActivity.java | // Path: Basic-Video-Chat-Java/app/src/main/java/com/tokbox/sample/basicvideochat/network/APIService.java
// public interface APIService {
//
// @GET("session")
// Call<GetSessionResponse> getSession();
// }
//
// Path: Basic-Video-Chat-Java/app/src/main/java/com/tokbox/sample/basicvideochat/network/GetSessionResponse.java
// public class GetSessionResponse {
// @Json(name = "apiKey") public String apiKey;
// @Json(name = "sessionId") public String sessionId;
// @Json(name = "token") public String token;
// }
| import android.Manifest;
import android.opengl.GLSurfaceView;
import android.os.Bundle;
import android.util.Log;
import android.widget.FrameLayout;
import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import com.opentok.android.BaseVideoRenderer;
import com.opentok.android.OpentokError;
import com.opentok.android.Publisher;
import com.opentok.android.PublisherKit;
import com.opentok.android.Session;
import com.opentok.android.Stream;
import com.opentok.android.Subscriber;
import com.opentok.android.SubscriberKit;
import com.tokbox.sample.basicvideochat.network.APIService;
import com.tokbox.sample.basicvideochat.network.GetSessionResponse;
import okhttp3.OkHttpClient;
import okhttp3.logging.HttpLoggingInterceptor;
import okhttp3.logging.HttpLoggingInterceptor.Level;
import pub.devrel.easypermissions.AfterPermissionGranted;
import pub.devrel.easypermissions.EasyPermissions;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.moshi.MoshiConverterFactory;
import java.util.List; |
if (EasyPermissions.hasPermissions(this, perms)) {
if (ServerConfig.hasChatServerUrl()) {
// Custom server URL exists - retrieve session config
if(!ServerConfig.isValid()) {
finishWithMessage("Invalid chat server url: " + ServerConfig.CHAT_SERVER_URL);
return;
}
initRetrofit();
getSession();
} else {
// Use hardcoded session config
if(!OpenTokConfig.isValid()) {
finishWithMessage("Invalid OpenTokConfig. " + OpenTokConfig.getDescription());
return;
}
initializeSession(OpenTokConfig.API_KEY, OpenTokConfig.SESSION_ID, OpenTokConfig.TOKEN);
}
} else {
EasyPermissions.requestPermissions(this, getString(R.string.rationale_video_app), PERMISSIONS_REQUEST_CODE, perms);
}
}
/* Make a request for session data */
private void getSession() {
Log.i(TAG, "getSession");
| // Path: Basic-Video-Chat-Java/app/src/main/java/com/tokbox/sample/basicvideochat/network/APIService.java
// public interface APIService {
//
// @GET("session")
// Call<GetSessionResponse> getSession();
// }
//
// Path: Basic-Video-Chat-Java/app/src/main/java/com/tokbox/sample/basicvideochat/network/GetSessionResponse.java
// public class GetSessionResponse {
// @Json(name = "apiKey") public String apiKey;
// @Json(name = "sessionId") public String sessionId;
// @Json(name = "token") public String token;
// }
// Path: Basic-Video-Chat-Java/app/src/main/java/com/tokbox/sample/basicvideochat/MainActivity.java
import android.Manifest;
import android.opengl.GLSurfaceView;
import android.os.Bundle;
import android.util.Log;
import android.widget.FrameLayout;
import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import com.opentok.android.BaseVideoRenderer;
import com.opentok.android.OpentokError;
import com.opentok.android.Publisher;
import com.opentok.android.PublisherKit;
import com.opentok.android.Session;
import com.opentok.android.Stream;
import com.opentok.android.Subscriber;
import com.opentok.android.SubscriberKit;
import com.tokbox.sample.basicvideochat.network.APIService;
import com.tokbox.sample.basicvideochat.network.GetSessionResponse;
import okhttp3.OkHttpClient;
import okhttp3.logging.HttpLoggingInterceptor;
import okhttp3.logging.HttpLoggingInterceptor.Level;
import pub.devrel.easypermissions.AfterPermissionGranted;
import pub.devrel.easypermissions.EasyPermissions;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.moshi.MoshiConverterFactory;
import java.util.List;
if (EasyPermissions.hasPermissions(this, perms)) {
if (ServerConfig.hasChatServerUrl()) {
// Custom server URL exists - retrieve session config
if(!ServerConfig.isValid()) {
finishWithMessage("Invalid chat server url: " + ServerConfig.CHAT_SERVER_URL);
return;
}
initRetrofit();
getSession();
} else {
// Use hardcoded session config
if(!OpenTokConfig.isValid()) {
finishWithMessage("Invalid OpenTokConfig. " + OpenTokConfig.getDescription());
return;
}
initializeSession(OpenTokConfig.API_KEY, OpenTokConfig.SESSION_ID, OpenTokConfig.TOKEN);
}
} else {
EasyPermissions.requestPermissions(this, getString(R.string.rationale_video_app), PERMISSIONS_REQUEST_CODE, perms);
}
}
/* Make a request for session data */
private void getSession() {
Log.i(TAG, "getSession");
| Call<GetSessionResponse> call = apiService.getSession(); |
opentok/opentok-android-sdk-samples | Signaling-Java/app/src/main/java/com/tokbox/sample/signaling/MainActivity.java | // Path: Signaling-Java/app/src/main/java/com/tokbox/sample/signaling/message/SignalMessage.java
// public class SignalMessage {
//
// private String messageText;
//
// private Boolean remote;
//
// public SignalMessage(String messageText) {
//
// this.messageText = messageText;
// this.remote = false;
// }
//
// public SignalMessage(String messageText, Boolean remote) {
//
// this.messageText = messageText;
// this.remote = remote;
// }
//
// public String getMessageText() {
// return this.messageText;
// }
//
// public void setMessageText(String mMessageText) {
// this.messageText = mMessageText;
// }
//
// public Boolean isRemote() {
// return this.remote;
// }
//
// public void setRemote(Boolean remote) {
// this.remote = remote;
// }
//
// }
//
// Path: Signaling-Java/app/src/main/java/com/tokbox/sample/signaling/message/SignalMessageAdapter.java
// public class SignalMessageAdapter extends ArrayAdapter<SignalMessage> {
//
// public static final int VIEW_TYPE_LOCAL = 0;
// public static final int VIEW_TYPE_REMOTE = 1;
// private static final Map<Integer, Integer> viewTypes;
//
// static {
// Map<Integer, Integer> aMap = new HashMap<>();
// aMap.put(VIEW_TYPE_LOCAL, R.layout.message_single_local);
// aMap.put(VIEW_TYPE_REMOTE, R.layout.message_single_remote);
// viewTypes = Collections.unmodifiableMap(aMap);
// }
//
// public SignalMessageAdapter(Context context) {
// super(context, 0);
// }
//
// @Override
// public View getView(int position, View convertView, ViewGroup parent) {
//
// SignalMessage message = getItem(position);
//
// if (convertView == null) {
// int type = getItemViewType(position);
// convertView = LayoutInflater.from(getContext()).inflate(viewTypes.get(type), null);
// }
//
// TextView messageTextView = (TextView) convertView.findViewById(R.id.message_text);
// if (messageTextView != null) {
// messageTextView.setText(message.getMessageText());
// }
//
// return convertView;
// }
//
// @Override
// public int getItemViewType(int position) {
//
// SignalMessage message = getItem(position);
// return message.isRemote() ? VIEW_TYPE_REMOTE : VIEW_TYPE_LOCAL;
// }
//
// @Override
// public int getViewTypeCount() {
// return viewTypes.size();
// }
// }
| import android.content.Context;
import android.os.Bundle;
import android.util.Log;
import android.view.KeyEvent;
import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
import com.opentok.android.Connection;
import com.opentok.android.OpentokError;
import com.opentok.android.Session;
import com.opentok.android.Stream;
import com.tokbox.sample.signaling.message.SignalMessage;
import com.tokbox.sample.signaling.message.SignalMessageAdapter; | package com.tokbox.sample.signaling;
public class MainActivity extends AppCompatActivity {
private static final String TAG = MainActivity.class.getSimpleName();
public static final String SIGNAL_TYPE = "text-signal";
private Session session; | // Path: Signaling-Java/app/src/main/java/com/tokbox/sample/signaling/message/SignalMessage.java
// public class SignalMessage {
//
// private String messageText;
//
// private Boolean remote;
//
// public SignalMessage(String messageText) {
//
// this.messageText = messageText;
// this.remote = false;
// }
//
// public SignalMessage(String messageText, Boolean remote) {
//
// this.messageText = messageText;
// this.remote = remote;
// }
//
// public String getMessageText() {
// return this.messageText;
// }
//
// public void setMessageText(String mMessageText) {
// this.messageText = mMessageText;
// }
//
// public Boolean isRemote() {
// return this.remote;
// }
//
// public void setRemote(Boolean remote) {
// this.remote = remote;
// }
//
// }
//
// Path: Signaling-Java/app/src/main/java/com/tokbox/sample/signaling/message/SignalMessageAdapter.java
// public class SignalMessageAdapter extends ArrayAdapter<SignalMessage> {
//
// public static final int VIEW_TYPE_LOCAL = 0;
// public static final int VIEW_TYPE_REMOTE = 1;
// private static final Map<Integer, Integer> viewTypes;
//
// static {
// Map<Integer, Integer> aMap = new HashMap<>();
// aMap.put(VIEW_TYPE_LOCAL, R.layout.message_single_local);
// aMap.put(VIEW_TYPE_REMOTE, R.layout.message_single_remote);
// viewTypes = Collections.unmodifiableMap(aMap);
// }
//
// public SignalMessageAdapter(Context context) {
// super(context, 0);
// }
//
// @Override
// public View getView(int position, View convertView, ViewGroup parent) {
//
// SignalMessage message = getItem(position);
//
// if (convertView == null) {
// int type = getItemViewType(position);
// convertView = LayoutInflater.from(getContext()).inflate(viewTypes.get(type), null);
// }
//
// TextView messageTextView = (TextView) convertView.findViewById(R.id.message_text);
// if (messageTextView != null) {
// messageTextView.setText(message.getMessageText());
// }
//
// return convertView;
// }
//
// @Override
// public int getItemViewType(int position) {
//
// SignalMessage message = getItem(position);
// return message.isRemote() ? VIEW_TYPE_REMOTE : VIEW_TYPE_LOCAL;
// }
//
// @Override
// public int getViewTypeCount() {
// return viewTypes.size();
// }
// }
// Path: Signaling-Java/app/src/main/java/com/tokbox/sample/signaling/MainActivity.java
import android.content.Context;
import android.os.Bundle;
import android.util.Log;
import android.view.KeyEvent;
import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
import com.opentok.android.Connection;
import com.opentok.android.OpentokError;
import com.opentok.android.Session;
import com.opentok.android.Stream;
import com.tokbox.sample.signaling.message.SignalMessage;
import com.tokbox.sample.signaling.message.SignalMessageAdapter;
package com.tokbox.sample.signaling;
public class MainActivity extends AppCompatActivity {
private static final String TAG = MainActivity.class.getSimpleName();
public static final String SIGNAL_TYPE = "text-signal";
private Session session; | private SignalMessageAdapter messageHistory; |
opentok/opentok-android-sdk-samples | Signaling-Java/app/src/main/java/com/tokbox/sample/signaling/MainActivity.java | // Path: Signaling-Java/app/src/main/java/com/tokbox/sample/signaling/message/SignalMessage.java
// public class SignalMessage {
//
// private String messageText;
//
// private Boolean remote;
//
// public SignalMessage(String messageText) {
//
// this.messageText = messageText;
// this.remote = false;
// }
//
// public SignalMessage(String messageText, Boolean remote) {
//
// this.messageText = messageText;
// this.remote = remote;
// }
//
// public String getMessageText() {
// return this.messageText;
// }
//
// public void setMessageText(String mMessageText) {
// this.messageText = mMessageText;
// }
//
// public Boolean isRemote() {
// return this.remote;
// }
//
// public void setRemote(Boolean remote) {
// this.remote = remote;
// }
//
// }
//
// Path: Signaling-Java/app/src/main/java/com/tokbox/sample/signaling/message/SignalMessageAdapter.java
// public class SignalMessageAdapter extends ArrayAdapter<SignalMessage> {
//
// public static final int VIEW_TYPE_LOCAL = 0;
// public static final int VIEW_TYPE_REMOTE = 1;
// private static final Map<Integer, Integer> viewTypes;
//
// static {
// Map<Integer, Integer> aMap = new HashMap<>();
// aMap.put(VIEW_TYPE_LOCAL, R.layout.message_single_local);
// aMap.put(VIEW_TYPE_REMOTE, R.layout.message_single_remote);
// viewTypes = Collections.unmodifiableMap(aMap);
// }
//
// public SignalMessageAdapter(Context context) {
// super(context, 0);
// }
//
// @Override
// public View getView(int position, View convertView, ViewGroup parent) {
//
// SignalMessage message = getItem(position);
//
// if (convertView == null) {
// int type = getItemViewType(position);
// convertView = LayoutInflater.from(getContext()).inflate(viewTypes.get(type), null);
// }
//
// TextView messageTextView = (TextView) convertView.findViewById(R.id.message_text);
// if (messageTextView != null) {
// messageTextView.setText(message.getMessageText());
// }
//
// return convertView;
// }
//
// @Override
// public int getItemViewType(int position) {
//
// SignalMessage message = getItem(position);
// return message.isRemote() ? VIEW_TYPE_REMOTE : VIEW_TYPE_LOCAL;
// }
//
// @Override
// public int getViewTypeCount() {
// return viewTypes.size();
// }
// }
| import android.content.Context;
import android.os.Bundle;
import android.util.Log;
import android.view.KeyEvent;
import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
import com.opentok.android.Connection;
import com.opentok.android.OpentokError;
import com.opentok.android.Session;
import com.opentok.android.Stream;
import com.tokbox.sample.signaling.message.SignalMessage;
import com.tokbox.sample.signaling.message.SignalMessageAdapter; |
messageEditTextView.setEnabled(false);
session = new Session.Builder(this, OpenTokConfig.API_KEY, OpenTokConfig.SESSION_ID).build();
session.setSessionListener(sessionListener);
session.setSignalListener(signalListener);
session.connect(OpenTokConfig.TOKEN);
}
@Override
protected void onPause() {
super.onPause();
if (session != null) {
session.onPause();
}
}
@Override
protected void onResume() {
super.onResume();
if (session != null) {
session.onResume();
}
}
private void sendMessage() {
Log.d(TAG, "Send Message");
| // Path: Signaling-Java/app/src/main/java/com/tokbox/sample/signaling/message/SignalMessage.java
// public class SignalMessage {
//
// private String messageText;
//
// private Boolean remote;
//
// public SignalMessage(String messageText) {
//
// this.messageText = messageText;
// this.remote = false;
// }
//
// public SignalMessage(String messageText, Boolean remote) {
//
// this.messageText = messageText;
// this.remote = remote;
// }
//
// public String getMessageText() {
// return this.messageText;
// }
//
// public void setMessageText(String mMessageText) {
// this.messageText = mMessageText;
// }
//
// public Boolean isRemote() {
// return this.remote;
// }
//
// public void setRemote(Boolean remote) {
// this.remote = remote;
// }
//
// }
//
// Path: Signaling-Java/app/src/main/java/com/tokbox/sample/signaling/message/SignalMessageAdapter.java
// public class SignalMessageAdapter extends ArrayAdapter<SignalMessage> {
//
// public static final int VIEW_TYPE_LOCAL = 0;
// public static final int VIEW_TYPE_REMOTE = 1;
// private static final Map<Integer, Integer> viewTypes;
//
// static {
// Map<Integer, Integer> aMap = new HashMap<>();
// aMap.put(VIEW_TYPE_LOCAL, R.layout.message_single_local);
// aMap.put(VIEW_TYPE_REMOTE, R.layout.message_single_remote);
// viewTypes = Collections.unmodifiableMap(aMap);
// }
//
// public SignalMessageAdapter(Context context) {
// super(context, 0);
// }
//
// @Override
// public View getView(int position, View convertView, ViewGroup parent) {
//
// SignalMessage message = getItem(position);
//
// if (convertView == null) {
// int type = getItemViewType(position);
// convertView = LayoutInflater.from(getContext()).inflate(viewTypes.get(type), null);
// }
//
// TextView messageTextView = (TextView) convertView.findViewById(R.id.message_text);
// if (messageTextView != null) {
// messageTextView.setText(message.getMessageText());
// }
//
// return convertView;
// }
//
// @Override
// public int getItemViewType(int position) {
//
// SignalMessage message = getItem(position);
// return message.isRemote() ? VIEW_TYPE_REMOTE : VIEW_TYPE_LOCAL;
// }
//
// @Override
// public int getViewTypeCount() {
// return viewTypes.size();
// }
// }
// Path: Signaling-Java/app/src/main/java/com/tokbox/sample/signaling/MainActivity.java
import android.content.Context;
import android.os.Bundle;
import android.util.Log;
import android.view.KeyEvent;
import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
import com.opentok.android.Connection;
import com.opentok.android.OpentokError;
import com.opentok.android.Session;
import com.opentok.android.Stream;
import com.tokbox.sample.signaling.message.SignalMessage;
import com.tokbox.sample.signaling.message.SignalMessageAdapter;
messageEditTextView.setEnabled(false);
session = new Session.Builder(this, OpenTokConfig.API_KEY, OpenTokConfig.SESSION_ID).build();
session.setSessionListener(sessionListener);
session.setSignalListener(signalListener);
session.connect(OpenTokConfig.TOKEN);
}
@Override
protected void onPause() {
super.onPause();
if (session != null) {
session.onPause();
}
}
@Override
protected void onResume() {
super.onResume();
if (session != null) {
session.onResume();
}
}
private void sendMessage() {
Log.d(TAG, "Send Message");
| SignalMessage signal = new SignalMessage(messageEditTextView.getText().toString()); |
codefollower/Cassandra-Java-Driver-Research | driver-core/src/main/java/com/datastax/driver/core/SessionManager.java | // Path: driver-core/src/main/java/com/datastax/driver/core/Message.java
// public static abstract class Request extends Message {
//
// public enum Type {
// STARTUP (1, Requests.Startup.coder),
// CREDENTIALS (4, Requests.Credentials.coder),
// OPTIONS (5, Requests.Options.coder),
// QUERY (7, Requests.Query.coder),
// PREPARE (9, Requests.Prepare.coder),
// EXECUTE (10, Requests.Execute.coder),
// REGISTER (11, Requests.Register.coder),
// BATCH (13, Requests.Batch.coder),
// AUTH_RESPONSE (15, Requests.AuthResponse.coder);
//
// public final int opcode;
// public final Coder<?> coder;
//
// private Type(int opcode, Coder<?> coder) {
// this.opcode = opcode;
// this.coder = coder;
// }
// }
//
// public final Type type;
// private final boolean tracingRequested;
//
// protected Request(Type type) {
// this(type, false);
// }
//
// protected Request(Type type, boolean tracingRequested) {
// this.type = type;
// this.tracingRequested = tracingRequested;
// }
//
// public boolean isTracingRequested() {
// return tracingRequested;
// }
//
// ConsistencyLevel consistency() {
// switch (this.type) {
// case QUERY: return ((Requests.Query)this).options.consistency;
// case EXECUTE: return ((Requests.Execute)this).options.consistency;
// case BATCH: return ((Requests.Batch)this).options.consistency;
// default: return null;
// }
// }
//
// ConsistencyLevel serialConsistency() {
// switch (this.type) {
// case QUERY: return ((Requests.Query)this).options.serialConsistency;
// case EXECUTE: return ((Requests.Execute)this).options.serialConsistency;
// case BATCH: return ((Requests.Batch)this).options.serialConsistency;
// default: return null;
// }
// }
//
// long defaultTimestamp() {
// switch (this.type) {
// case QUERY: return ((Requests.Query)this).options.defaultTimestamp;
// case EXECUTE: return ((Requests.Execute)this).options.defaultTimestamp;
// case BATCH: return ((Requests.Batch)this).options.defaultTimestamp;
// default: return 0;
// }
// }
//
// ByteBuffer pagingState() {
// switch (this.type) {
// case QUERY: return ((Requests.Query)this).options.pagingState;
// case EXECUTE: return ((Requests.Execute)this).options.pagingState;
// default: return null;
// }
// }
//
// Request copy() {
// throw new UnsupportedOperationException();
// }
//
// Request copy(ConsistencyLevel newConsistencyLevel) {
// throw new UnsupportedOperationException();
// }
// }
| import java.net.InetSocketAddress;
import java.nio.ByteBuffer;
import java.util.*;
import java.util.concurrent.*;
import java.util.concurrent.atomic.AtomicReference;
import com.google.common.base.Function;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;
import com.google.common.util.concurrent.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.datastax.driver.core.Message.Request;
import com.datastax.driver.core.exceptions.DriverInternalError;
import com.datastax.driver.core.exceptions.InvalidQueryException;
import com.datastax.driver.core.exceptions.UnsupportedFeatureException;
import com.datastax.driver.core.policies.LoadBalancingPolicy;
import com.datastax.driver.core.policies.ReconnectionPolicy;
import com.datastax.driver.core.policies.SpeculativeExecutionPolicy;
import com.datastax.driver.core.utils.MoreFutures; | List<ListenableFuture<Boolean>> futures = Lists.newArrayListWithCapacity(hosts.size());
for (Host host : hosts)
if (host.state != Host.State.DOWN)
futures.add(maybeAddPool(host, null));
try {
Futures.successfulAsList(futures).get();
} catch (ExecutionException e) {
// Won't happen because we used successfulAsList
// And if a particular pool failed, maybeAddPool already handled it
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
}
public String getLoggedKeyspace() {
return poolsState.keyspace;
}
public ResultSetFuture executeAsync(Statement statement) {
return executeQuery(makeRequestMessage(statement, null), statement);
}
public ListenableFuture<PreparedStatement> prepareAsync(String query) {
Connection.Future future = new Connection.Future(new Requests.Prepare(query));
execute(future, Statement.DEFAULT);
return toPreparedStatement(query, future);
}
//我加上的,这样prepare也能用Tracing
public ListenableFuture<PreparedStatement> prepareAsync(String query, Statement statement) { | // Path: driver-core/src/main/java/com/datastax/driver/core/Message.java
// public static abstract class Request extends Message {
//
// public enum Type {
// STARTUP (1, Requests.Startup.coder),
// CREDENTIALS (4, Requests.Credentials.coder),
// OPTIONS (5, Requests.Options.coder),
// QUERY (7, Requests.Query.coder),
// PREPARE (9, Requests.Prepare.coder),
// EXECUTE (10, Requests.Execute.coder),
// REGISTER (11, Requests.Register.coder),
// BATCH (13, Requests.Batch.coder),
// AUTH_RESPONSE (15, Requests.AuthResponse.coder);
//
// public final int opcode;
// public final Coder<?> coder;
//
// private Type(int opcode, Coder<?> coder) {
// this.opcode = opcode;
// this.coder = coder;
// }
// }
//
// public final Type type;
// private final boolean tracingRequested;
//
// protected Request(Type type) {
// this(type, false);
// }
//
// protected Request(Type type, boolean tracingRequested) {
// this.type = type;
// this.tracingRequested = tracingRequested;
// }
//
// public boolean isTracingRequested() {
// return tracingRequested;
// }
//
// ConsistencyLevel consistency() {
// switch (this.type) {
// case QUERY: return ((Requests.Query)this).options.consistency;
// case EXECUTE: return ((Requests.Execute)this).options.consistency;
// case BATCH: return ((Requests.Batch)this).options.consistency;
// default: return null;
// }
// }
//
// ConsistencyLevel serialConsistency() {
// switch (this.type) {
// case QUERY: return ((Requests.Query)this).options.serialConsistency;
// case EXECUTE: return ((Requests.Execute)this).options.serialConsistency;
// case BATCH: return ((Requests.Batch)this).options.serialConsistency;
// default: return null;
// }
// }
//
// long defaultTimestamp() {
// switch (this.type) {
// case QUERY: return ((Requests.Query)this).options.defaultTimestamp;
// case EXECUTE: return ((Requests.Execute)this).options.defaultTimestamp;
// case BATCH: return ((Requests.Batch)this).options.defaultTimestamp;
// default: return 0;
// }
// }
//
// ByteBuffer pagingState() {
// switch (this.type) {
// case QUERY: return ((Requests.Query)this).options.pagingState;
// case EXECUTE: return ((Requests.Execute)this).options.pagingState;
// default: return null;
// }
// }
//
// Request copy() {
// throw new UnsupportedOperationException();
// }
//
// Request copy(ConsistencyLevel newConsistencyLevel) {
// throw new UnsupportedOperationException();
// }
// }
// Path: driver-core/src/main/java/com/datastax/driver/core/SessionManager.java
import java.net.InetSocketAddress;
import java.nio.ByteBuffer;
import java.util.*;
import java.util.concurrent.*;
import java.util.concurrent.atomic.AtomicReference;
import com.google.common.base.Function;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;
import com.google.common.util.concurrent.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.datastax.driver.core.Message.Request;
import com.datastax.driver.core.exceptions.DriverInternalError;
import com.datastax.driver.core.exceptions.InvalidQueryException;
import com.datastax.driver.core.exceptions.UnsupportedFeatureException;
import com.datastax.driver.core.policies.LoadBalancingPolicy;
import com.datastax.driver.core.policies.ReconnectionPolicy;
import com.datastax.driver.core.policies.SpeculativeExecutionPolicy;
import com.datastax.driver.core.utils.MoreFutures;
List<ListenableFuture<Boolean>> futures = Lists.newArrayListWithCapacity(hosts.size());
for (Host host : hosts)
if (host.state != Host.State.DOWN)
futures.add(maybeAddPool(host, null));
try {
Futures.successfulAsList(futures).get();
} catch (ExecutionException e) {
// Won't happen because we used successfulAsList
// And if a particular pool failed, maybeAddPool already handled it
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
}
public String getLoggedKeyspace() {
return poolsState.keyspace;
}
public ResultSetFuture executeAsync(Statement statement) {
return executeQuery(makeRequestMessage(statement, null), statement);
}
public ListenableFuture<PreparedStatement> prepareAsync(String query) {
Connection.Future future = new Connection.Future(new Requests.Prepare(query));
execute(future, Statement.DEFAULT);
return toPreparedStatement(query, future);
}
//我加上的,这样prepare也能用Tracing
public ListenableFuture<PreparedStatement> prepareAsync(String query, Statement statement) { | Request msg = new Requests.Prepare(query); |
wangyeee/IBE-Secure-Message | server/key-dist-server/src/main/java/hamaster/gradesign/keydist/controller/ActivationController.java | // Path: server/key-dist-server/src/main/java/hamaster/gradesign/keydist/client/Encoder.java
// public interface Encoder {
//
// String encode(byte[] data);
//
// byte[] decode(String code);
//
// String name();
// }
//
// Path: server/key-dist-server/src/main/java/hamaster/gradesign/keydist/mail/IBEMailParameterGenerator.java
// @Component
// public class IBEMailParameterGenerator {
//
// public final static String CONTENT_KEY = "c";// content
// public final static String SIGNATURE_KEY = "s";//signature
//
// final private static long oneweek = 604800000L;
//
// private UserDAO userDAO;
// private IDRequestService requestDAO;
// private KeyGenClient system;
//
// @Autowired
// public IBEMailParameterGenerator(UserDAO userDAO, IDRequestService requestDAO, KeyGenClient system) {
// this.userDAO = requireNonNull(userDAO);
// this.requestDAO = requireNonNull(requestDAO);
// this.system = requireNonNull(system);
// }
//
// public Properties sign(ActivationContent content) {
// Properties props = new Properties();
// byte[] bs = ActivationContent.toBytes(content);
// byte[] digest = Hash.sha512(bs);
// IBSSignature signature = IBEEngine.sign(system.serverCertificate(), digest, "SHA-512");
// ByteArrayOutputStream out = new ByteArrayOutputStream();
// try {
// signature.writeExternal(out);
// out.flush();
// } catch (IOException e) {
// }
// byte[] sign = out.toByteArray();
//
// Encoder base64 = new Base64Encoder();
// String ct = base64.encode(bs);
// ct = ct.replace('+', '*');
// ct = ct.replace('/', '-');
// ct = StringUtils.replace(ct, "=", "%3D");
//
// String sg = base64.encode(sign);
// sg = sg.replace('+', '*');
// sg = sg.replace('/', '-');
// sg = StringUtils.replace(sg, "=", "%3D");
// props.setProperty(CONTENT_KEY, ct);
// props.setProperty(SIGNATURE_KEY, sg);
// return props;
// }
//
// public int verify(byte[] content, byte[] signature) {
// byte[] digest = Hash.sha512(content);
// IBSSignature sign = new IBSSignature();
// ByteArrayInputStream in = new ByteArrayInputStream(signature);
// try {
// sign.readExternal(in);
// } catch (IOException e) {
// } catch (ClassNotFoundException e) {
// }
// boolean b0 = IBEEngine.verify(sign, digest);
// if (!b0)
// return 1;// 错误
// ActivationContent activationContent = ActivationContent.fromBytes(content);
// long now = System.currentTimeMillis();
// long start = activationContent.getActiveDate().getTime();
// if (now - start < oneweek) {
// User applicant = userDAO.getOne(activationContent.getUserId());
// if (activationContent.getType() == ActivationContent.ACTIVE_ID) {
// IDRequest request = requestDAO.getByOwner(applicant, activationContent.getEmail());
// if (request.getStatus() != IBECSR.APPLICATION_NOT_VERIFIED)
// return 3;//已经激活
// request.setStatus(IBECSR.APPLICATION_STARTED);
// requestDAO.save(request);
// } else if (activationContent.getType() == ActivationContent.ACTIVE_USER) {
// if (applicant.getStatus() != User.USER_REG)
// return 3;
// applicant.setStatus(User.USER_ACTIVE);
// userDAO.save(applicant);
// }
// return 0;// 成功
// }
// return 2;// 过期
// }
// }
| import static java.util.Objects.requireNonNull;
import java.util.HashMap;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import hamaster.gradesign.keydist.client.Encoder;
import hamaster.gradesign.keydist.mail.IBEMailParameterGenerator; | package hamaster.gradesign.keydist.controller;
@RestController
public class ActivationController {
| // Path: server/key-dist-server/src/main/java/hamaster/gradesign/keydist/client/Encoder.java
// public interface Encoder {
//
// String encode(byte[] data);
//
// byte[] decode(String code);
//
// String name();
// }
//
// Path: server/key-dist-server/src/main/java/hamaster/gradesign/keydist/mail/IBEMailParameterGenerator.java
// @Component
// public class IBEMailParameterGenerator {
//
// public final static String CONTENT_KEY = "c";// content
// public final static String SIGNATURE_KEY = "s";//signature
//
// final private static long oneweek = 604800000L;
//
// private UserDAO userDAO;
// private IDRequestService requestDAO;
// private KeyGenClient system;
//
// @Autowired
// public IBEMailParameterGenerator(UserDAO userDAO, IDRequestService requestDAO, KeyGenClient system) {
// this.userDAO = requireNonNull(userDAO);
// this.requestDAO = requireNonNull(requestDAO);
// this.system = requireNonNull(system);
// }
//
// public Properties sign(ActivationContent content) {
// Properties props = new Properties();
// byte[] bs = ActivationContent.toBytes(content);
// byte[] digest = Hash.sha512(bs);
// IBSSignature signature = IBEEngine.sign(system.serverCertificate(), digest, "SHA-512");
// ByteArrayOutputStream out = new ByteArrayOutputStream();
// try {
// signature.writeExternal(out);
// out.flush();
// } catch (IOException e) {
// }
// byte[] sign = out.toByteArray();
//
// Encoder base64 = new Base64Encoder();
// String ct = base64.encode(bs);
// ct = ct.replace('+', '*');
// ct = ct.replace('/', '-');
// ct = StringUtils.replace(ct, "=", "%3D");
//
// String sg = base64.encode(sign);
// sg = sg.replace('+', '*');
// sg = sg.replace('/', '-');
// sg = StringUtils.replace(sg, "=", "%3D");
// props.setProperty(CONTENT_KEY, ct);
// props.setProperty(SIGNATURE_KEY, sg);
// return props;
// }
//
// public int verify(byte[] content, byte[] signature) {
// byte[] digest = Hash.sha512(content);
// IBSSignature sign = new IBSSignature();
// ByteArrayInputStream in = new ByteArrayInputStream(signature);
// try {
// sign.readExternal(in);
// } catch (IOException e) {
// } catch (ClassNotFoundException e) {
// }
// boolean b0 = IBEEngine.verify(sign, digest);
// if (!b0)
// return 1;// 错误
// ActivationContent activationContent = ActivationContent.fromBytes(content);
// long now = System.currentTimeMillis();
// long start = activationContent.getActiveDate().getTime();
// if (now - start < oneweek) {
// User applicant = userDAO.getOne(activationContent.getUserId());
// if (activationContent.getType() == ActivationContent.ACTIVE_ID) {
// IDRequest request = requestDAO.getByOwner(applicant, activationContent.getEmail());
// if (request.getStatus() != IBECSR.APPLICATION_NOT_VERIFIED)
// return 3;//已经激活
// request.setStatus(IBECSR.APPLICATION_STARTED);
// requestDAO.save(request);
// } else if (activationContent.getType() == ActivationContent.ACTIVE_USER) {
// if (applicant.getStatus() != User.USER_REG)
// return 3;
// applicant.setStatus(User.USER_ACTIVE);
// userDAO.save(applicant);
// }
// return 0;// 成功
// }
// return 2;// 过期
// }
// }
// Path: server/key-dist-server/src/main/java/hamaster/gradesign/keydist/controller/ActivationController.java
import static java.util.Objects.requireNonNull;
import java.util.HashMap;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import hamaster.gradesign.keydist.client.Encoder;
import hamaster.gradesign.keydist.mail.IBEMailParameterGenerator;
package hamaster.gradesign.keydist.controller;
@RestController
public class ActivationController {
| private IBEMailParameterGenerator mailParameterGenerator; |
wangyeee/IBE-Secure-Message | server/key-dist-server/src/main/java/hamaster/gradesign/keydist/controller/ActivationController.java | // Path: server/key-dist-server/src/main/java/hamaster/gradesign/keydist/client/Encoder.java
// public interface Encoder {
//
// String encode(byte[] data);
//
// byte[] decode(String code);
//
// String name();
// }
//
// Path: server/key-dist-server/src/main/java/hamaster/gradesign/keydist/mail/IBEMailParameterGenerator.java
// @Component
// public class IBEMailParameterGenerator {
//
// public final static String CONTENT_KEY = "c";// content
// public final static String SIGNATURE_KEY = "s";//signature
//
// final private static long oneweek = 604800000L;
//
// private UserDAO userDAO;
// private IDRequestService requestDAO;
// private KeyGenClient system;
//
// @Autowired
// public IBEMailParameterGenerator(UserDAO userDAO, IDRequestService requestDAO, KeyGenClient system) {
// this.userDAO = requireNonNull(userDAO);
// this.requestDAO = requireNonNull(requestDAO);
// this.system = requireNonNull(system);
// }
//
// public Properties sign(ActivationContent content) {
// Properties props = new Properties();
// byte[] bs = ActivationContent.toBytes(content);
// byte[] digest = Hash.sha512(bs);
// IBSSignature signature = IBEEngine.sign(system.serverCertificate(), digest, "SHA-512");
// ByteArrayOutputStream out = new ByteArrayOutputStream();
// try {
// signature.writeExternal(out);
// out.flush();
// } catch (IOException e) {
// }
// byte[] sign = out.toByteArray();
//
// Encoder base64 = new Base64Encoder();
// String ct = base64.encode(bs);
// ct = ct.replace('+', '*');
// ct = ct.replace('/', '-');
// ct = StringUtils.replace(ct, "=", "%3D");
//
// String sg = base64.encode(sign);
// sg = sg.replace('+', '*');
// sg = sg.replace('/', '-');
// sg = StringUtils.replace(sg, "=", "%3D");
// props.setProperty(CONTENT_KEY, ct);
// props.setProperty(SIGNATURE_KEY, sg);
// return props;
// }
//
// public int verify(byte[] content, byte[] signature) {
// byte[] digest = Hash.sha512(content);
// IBSSignature sign = new IBSSignature();
// ByteArrayInputStream in = new ByteArrayInputStream(signature);
// try {
// sign.readExternal(in);
// } catch (IOException e) {
// } catch (ClassNotFoundException e) {
// }
// boolean b0 = IBEEngine.verify(sign, digest);
// if (!b0)
// return 1;// 错误
// ActivationContent activationContent = ActivationContent.fromBytes(content);
// long now = System.currentTimeMillis();
// long start = activationContent.getActiveDate().getTime();
// if (now - start < oneweek) {
// User applicant = userDAO.getOne(activationContent.getUserId());
// if (activationContent.getType() == ActivationContent.ACTIVE_ID) {
// IDRequest request = requestDAO.getByOwner(applicant, activationContent.getEmail());
// if (request.getStatus() != IBECSR.APPLICATION_NOT_VERIFIED)
// return 3;//已经激活
// request.setStatus(IBECSR.APPLICATION_STARTED);
// requestDAO.save(request);
// } else if (activationContent.getType() == ActivationContent.ACTIVE_USER) {
// if (applicant.getStatus() != User.USER_REG)
// return 3;
// applicant.setStatus(User.USER_ACTIVE);
// userDAO.save(applicant);
// }
// return 0;// 成功
// }
// return 2;// 过期
// }
// }
| import static java.util.Objects.requireNonNull;
import java.util.HashMap;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import hamaster.gradesign.keydist.client.Encoder;
import hamaster.gradesign.keydist.mail.IBEMailParameterGenerator; | package hamaster.gradesign.keydist.controller;
@RestController
public class ActivationController {
private IBEMailParameterGenerator mailParameterGenerator;
| // Path: server/key-dist-server/src/main/java/hamaster/gradesign/keydist/client/Encoder.java
// public interface Encoder {
//
// String encode(byte[] data);
//
// byte[] decode(String code);
//
// String name();
// }
//
// Path: server/key-dist-server/src/main/java/hamaster/gradesign/keydist/mail/IBEMailParameterGenerator.java
// @Component
// public class IBEMailParameterGenerator {
//
// public final static String CONTENT_KEY = "c";// content
// public final static String SIGNATURE_KEY = "s";//signature
//
// final private static long oneweek = 604800000L;
//
// private UserDAO userDAO;
// private IDRequestService requestDAO;
// private KeyGenClient system;
//
// @Autowired
// public IBEMailParameterGenerator(UserDAO userDAO, IDRequestService requestDAO, KeyGenClient system) {
// this.userDAO = requireNonNull(userDAO);
// this.requestDAO = requireNonNull(requestDAO);
// this.system = requireNonNull(system);
// }
//
// public Properties sign(ActivationContent content) {
// Properties props = new Properties();
// byte[] bs = ActivationContent.toBytes(content);
// byte[] digest = Hash.sha512(bs);
// IBSSignature signature = IBEEngine.sign(system.serverCertificate(), digest, "SHA-512");
// ByteArrayOutputStream out = new ByteArrayOutputStream();
// try {
// signature.writeExternal(out);
// out.flush();
// } catch (IOException e) {
// }
// byte[] sign = out.toByteArray();
//
// Encoder base64 = new Base64Encoder();
// String ct = base64.encode(bs);
// ct = ct.replace('+', '*');
// ct = ct.replace('/', '-');
// ct = StringUtils.replace(ct, "=", "%3D");
//
// String sg = base64.encode(sign);
// sg = sg.replace('+', '*');
// sg = sg.replace('/', '-');
// sg = StringUtils.replace(sg, "=", "%3D");
// props.setProperty(CONTENT_KEY, ct);
// props.setProperty(SIGNATURE_KEY, sg);
// return props;
// }
//
// public int verify(byte[] content, byte[] signature) {
// byte[] digest = Hash.sha512(content);
// IBSSignature sign = new IBSSignature();
// ByteArrayInputStream in = new ByteArrayInputStream(signature);
// try {
// sign.readExternal(in);
// } catch (IOException e) {
// } catch (ClassNotFoundException e) {
// }
// boolean b0 = IBEEngine.verify(sign, digest);
// if (!b0)
// return 1;// 错误
// ActivationContent activationContent = ActivationContent.fromBytes(content);
// long now = System.currentTimeMillis();
// long start = activationContent.getActiveDate().getTime();
// if (now - start < oneweek) {
// User applicant = userDAO.getOne(activationContent.getUserId());
// if (activationContent.getType() == ActivationContent.ACTIVE_ID) {
// IDRequest request = requestDAO.getByOwner(applicant, activationContent.getEmail());
// if (request.getStatus() != IBECSR.APPLICATION_NOT_VERIFIED)
// return 3;//已经激活
// request.setStatus(IBECSR.APPLICATION_STARTED);
// requestDAO.save(request);
// } else if (activationContent.getType() == ActivationContent.ACTIVE_USER) {
// if (applicant.getStatus() != User.USER_REG)
// return 3;
// applicant.setStatus(User.USER_ACTIVE);
// userDAO.save(applicant);
// }
// return 0;// 成功
// }
// return 2;// 过期
// }
// }
// Path: server/key-dist-server/src/main/java/hamaster/gradesign/keydist/controller/ActivationController.java
import static java.util.Objects.requireNonNull;
import java.util.HashMap;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import hamaster.gradesign.keydist.client.Encoder;
import hamaster.gradesign.keydist.mail.IBEMailParameterGenerator;
package hamaster.gradesign.keydist.controller;
@RestController
public class ActivationController {
private IBEMailParameterGenerator mailParameterGenerator;
| private Encoder base64; |
wangyeee/IBE-Secure-Message | jlib/jibe/src/main/java/hamaster/gradesgin/ibe/IBEPrivateKey.java | // Path: jlib/jibe/src/main/java/hamaster/gradesgin/util/Hex.java
// public final static int bytesToInt(byte[] bytes) {
// return bytesToInt(bytes,0);
// }
//
// Path: jlib/jibe/src/main/java/hamaster/gradesgin/util/Hex.java
// public final static byte[] intToByte(int i) {
// byte[] bt = new byte[4];
// bt[0] = (byte) ((0xff000000 & i) >> 24);
// bt[1] = (byte) ((0xff0000 & i) >> 16);
// bt[2] = (byte) ((0xff00 & i) >> 8);
// bt[3] = (byte) (0xff & i);
// return bt;
// }
//
// Path: jlib/jibe/src/main/java/hamaster/gradesgin/util/MemoryUtil.java
// final public class MemoryUtil {
//
// /**
// * 在新的线程中安全擦除内存块,这个方法在执行后会快速返回<br>
// * 此方法与在新线程中执行immediateSecureBuffers方法等效
// * @param buffers 待擦除的内存块
// */
// public final static void fastSecureBuffers(byte[] ... buffers) {
// new SecureBufferThread(buffers).start();
// }
//
// /**
// * 立刻安全擦除内存块
// * @param buffers 待擦除的内存块
// */
// public final static void immediateSecureBuffers(byte[] ... buffers) {
// BigInteger i = new BigInteger(Long.toHexString(System.nanoTime()), 16);
// Random random = new SecureRandom(i.toByteArray());
// for (byte[] buffer : buffers) {
// if (buffer != null)
// random.nextBytes(buffer);
// }
// }
// }
| import static hamaster.gradesgin.util.Hex.bytesToInt;
import static hamaster.gradesgin.util.Hex.intToByte;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.Serializable;
import java.security.PrivateKey;
import java.util.Arrays;
import hamaster.gradesgin.util.MemoryUtil; | * 椭圆参数长度4字节<br>
* 椭圆参数不定长度
* Serialize the private key, this implementation writes key content directly to a file, keep it private!!!
* Sequence: rID - 20 bytes, hID - 128 bytes, length of public key - 4 bytes, public key, length of pairing - 4 bytes, pairing
* @see hamaster.gradesgin.ibe.IBEConstraints#writeExternal(java.io.OutputStream)
*/
@Override
public void writeExternal(OutputStream out) throws IOException {
byte[] encoded = getEncoded();
if (encoded != null) {
out.write(encoded);
out.flush();
return;
}
// 不编码,直接将私钥写入输出流
// TODO encrypt the private key with a password.
byte[] rBuffer = new byte[IBE_ZR_SIZE];
Arrays.fill(rBuffer, (byte) 0);
if (rID != null)
System.arraycopy(rID, 0, rBuffer, 0, IBE_ZR_SIZE > rID.length ? rID.length : IBE_ZR_SIZE);
out.write(rBuffer);
byte[] hBuffer = new byte[IBE_G_SIZE];
Arrays.fill(hBuffer, (byte) 0);
if (hID != null)
System.arraycopy(hID, 0, hBuffer, 0, IBE_G_SIZE > hID.length ? hID.length : IBE_G_SIZE);
out.write(hBuffer);
byte[] userBuffer = null;
if (userString != null) {
userBuffer = userString.getBytes(USER_STRING_ENCODING); | // Path: jlib/jibe/src/main/java/hamaster/gradesgin/util/Hex.java
// public final static int bytesToInt(byte[] bytes) {
// return bytesToInt(bytes,0);
// }
//
// Path: jlib/jibe/src/main/java/hamaster/gradesgin/util/Hex.java
// public final static byte[] intToByte(int i) {
// byte[] bt = new byte[4];
// bt[0] = (byte) ((0xff000000 & i) >> 24);
// bt[1] = (byte) ((0xff0000 & i) >> 16);
// bt[2] = (byte) ((0xff00 & i) >> 8);
// bt[3] = (byte) (0xff & i);
// return bt;
// }
//
// Path: jlib/jibe/src/main/java/hamaster/gradesgin/util/MemoryUtil.java
// final public class MemoryUtil {
//
// /**
// * 在新的线程中安全擦除内存块,这个方法在执行后会快速返回<br>
// * 此方法与在新线程中执行immediateSecureBuffers方法等效
// * @param buffers 待擦除的内存块
// */
// public final static void fastSecureBuffers(byte[] ... buffers) {
// new SecureBufferThread(buffers).start();
// }
//
// /**
// * 立刻安全擦除内存块
// * @param buffers 待擦除的内存块
// */
// public final static void immediateSecureBuffers(byte[] ... buffers) {
// BigInteger i = new BigInteger(Long.toHexString(System.nanoTime()), 16);
// Random random = new SecureRandom(i.toByteArray());
// for (byte[] buffer : buffers) {
// if (buffer != null)
// random.nextBytes(buffer);
// }
// }
// }
// Path: jlib/jibe/src/main/java/hamaster/gradesgin/ibe/IBEPrivateKey.java
import static hamaster.gradesgin.util.Hex.bytesToInt;
import static hamaster.gradesgin.util.Hex.intToByte;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.Serializable;
import java.security.PrivateKey;
import java.util.Arrays;
import hamaster.gradesgin.util.MemoryUtil;
* 椭圆参数长度4字节<br>
* 椭圆参数不定长度
* Serialize the private key, this implementation writes key content directly to a file, keep it private!!!
* Sequence: rID - 20 bytes, hID - 128 bytes, length of public key - 4 bytes, public key, length of pairing - 4 bytes, pairing
* @see hamaster.gradesgin.ibe.IBEConstraints#writeExternal(java.io.OutputStream)
*/
@Override
public void writeExternal(OutputStream out) throws IOException {
byte[] encoded = getEncoded();
if (encoded != null) {
out.write(encoded);
out.flush();
return;
}
// 不编码,直接将私钥写入输出流
// TODO encrypt the private key with a password.
byte[] rBuffer = new byte[IBE_ZR_SIZE];
Arrays.fill(rBuffer, (byte) 0);
if (rID != null)
System.arraycopy(rID, 0, rBuffer, 0, IBE_ZR_SIZE > rID.length ? rID.length : IBE_ZR_SIZE);
out.write(rBuffer);
byte[] hBuffer = new byte[IBE_G_SIZE];
Arrays.fill(hBuffer, (byte) 0);
if (hID != null)
System.arraycopy(hID, 0, hBuffer, 0, IBE_G_SIZE > hID.length ? hID.length : IBE_G_SIZE);
out.write(hBuffer);
byte[] userBuffer = null;
if (userString != null) {
userBuffer = userString.getBytes(USER_STRING_ENCODING); | out.write(intToByte(userBuffer.length)); |
wangyeee/IBE-Secure-Message | jlib/jibe/src/main/java/hamaster/gradesgin/ibe/IBEPrivateKey.java | // Path: jlib/jibe/src/main/java/hamaster/gradesgin/util/Hex.java
// public final static int bytesToInt(byte[] bytes) {
// return bytesToInt(bytes,0);
// }
//
// Path: jlib/jibe/src/main/java/hamaster/gradesgin/util/Hex.java
// public final static byte[] intToByte(int i) {
// byte[] bt = new byte[4];
// bt[0] = (byte) ((0xff000000 & i) >> 24);
// bt[1] = (byte) ((0xff0000 & i) >> 16);
// bt[2] = (byte) ((0xff00 & i) >> 8);
// bt[3] = (byte) (0xff & i);
// return bt;
// }
//
// Path: jlib/jibe/src/main/java/hamaster/gradesgin/util/MemoryUtil.java
// final public class MemoryUtil {
//
// /**
// * 在新的线程中安全擦除内存块,这个方法在执行后会快速返回<br>
// * 此方法与在新线程中执行immediateSecureBuffers方法等效
// * @param buffers 待擦除的内存块
// */
// public final static void fastSecureBuffers(byte[] ... buffers) {
// new SecureBufferThread(buffers).start();
// }
//
// /**
// * 立刻安全擦除内存块
// * @param buffers 待擦除的内存块
// */
// public final static void immediateSecureBuffers(byte[] ... buffers) {
// BigInteger i = new BigInteger(Long.toHexString(System.nanoTime()), 16);
// Random random = new SecureRandom(i.toByteArray());
// for (byte[] buffer : buffers) {
// if (buffer != null)
// random.nextBytes(buffer);
// }
// }
// }
| import static hamaster.gradesgin.util.Hex.bytesToInt;
import static hamaster.gradesgin.util.Hex.intToByte;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.Serializable;
import java.security.PrivateKey;
import java.util.Arrays;
import hamaster.gradesgin.util.MemoryUtil; | }
// 不编码,直接将私钥写入输出流
// TODO encrypt the private key with a password.
byte[] rBuffer = new byte[IBE_ZR_SIZE];
Arrays.fill(rBuffer, (byte) 0);
if (rID != null)
System.arraycopy(rID, 0, rBuffer, 0, IBE_ZR_SIZE > rID.length ? rID.length : IBE_ZR_SIZE);
out.write(rBuffer);
byte[] hBuffer = new byte[IBE_G_SIZE];
Arrays.fill(hBuffer, (byte) 0);
if (hID != null)
System.arraycopy(hID, 0, hBuffer, 0, IBE_G_SIZE > hID.length ? hID.length : IBE_G_SIZE);
out.write(hBuffer);
byte[] userBuffer = null;
if (userString != null) {
userBuffer = userString.getBytes(USER_STRING_ENCODING);
out.write(intToByte(userBuffer.length));
out.write(userBuffer);
}
byte[] pBuffer = new byte[IBE_G_SIZE * 4];
Arrays.fill(pBuffer, (byte) 0);
if (pairing != null) {
System.arraycopy(pairing, 0, pBuffer, 0, pairing.length);
out.write(intToByte(pairing.length));
} else {
out.write(intToByte(IBE_G_SIZE * 4));
}
out.write(pBuffer, 0, pairing == null ? pBuffer.length : pairing.length);
out.flush(); | // Path: jlib/jibe/src/main/java/hamaster/gradesgin/util/Hex.java
// public final static int bytesToInt(byte[] bytes) {
// return bytesToInt(bytes,0);
// }
//
// Path: jlib/jibe/src/main/java/hamaster/gradesgin/util/Hex.java
// public final static byte[] intToByte(int i) {
// byte[] bt = new byte[4];
// bt[0] = (byte) ((0xff000000 & i) >> 24);
// bt[1] = (byte) ((0xff0000 & i) >> 16);
// bt[2] = (byte) ((0xff00 & i) >> 8);
// bt[3] = (byte) (0xff & i);
// return bt;
// }
//
// Path: jlib/jibe/src/main/java/hamaster/gradesgin/util/MemoryUtil.java
// final public class MemoryUtil {
//
// /**
// * 在新的线程中安全擦除内存块,这个方法在执行后会快速返回<br>
// * 此方法与在新线程中执行immediateSecureBuffers方法等效
// * @param buffers 待擦除的内存块
// */
// public final static void fastSecureBuffers(byte[] ... buffers) {
// new SecureBufferThread(buffers).start();
// }
//
// /**
// * 立刻安全擦除内存块
// * @param buffers 待擦除的内存块
// */
// public final static void immediateSecureBuffers(byte[] ... buffers) {
// BigInteger i = new BigInteger(Long.toHexString(System.nanoTime()), 16);
// Random random = new SecureRandom(i.toByteArray());
// for (byte[] buffer : buffers) {
// if (buffer != null)
// random.nextBytes(buffer);
// }
// }
// }
// Path: jlib/jibe/src/main/java/hamaster/gradesgin/ibe/IBEPrivateKey.java
import static hamaster.gradesgin.util.Hex.bytesToInt;
import static hamaster.gradesgin.util.Hex.intToByte;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.Serializable;
import java.security.PrivateKey;
import java.util.Arrays;
import hamaster.gradesgin.util.MemoryUtil;
}
// 不编码,直接将私钥写入输出流
// TODO encrypt the private key with a password.
byte[] rBuffer = new byte[IBE_ZR_SIZE];
Arrays.fill(rBuffer, (byte) 0);
if (rID != null)
System.arraycopy(rID, 0, rBuffer, 0, IBE_ZR_SIZE > rID.length ? rID.length : IBE_ZR_SIZE);
out.write(rBuffer);
byte[] hBuffer = new byte[IBE_G_SIZE];
Arrays.fill(hBuffer, (byte) 0);
if (hID != null)
System.arraycopy(hID, 0, hBuffer, 0, IBE_G_SIZE > hID.length ? hID.length : IBE_G_SIZE);
out.write(hBuffer);
byte[] userBuffer = null;
if (userString != null) {
userBuffer = userString.getBytes(USER_STRING_ENCODING);
out.write(intToByte(userBuffer.length));
out.write(userBuffer);
}
byte[] pBuffer = new byte[IBE_G_SIZE * 4];
Arrays.fill(pBuffer, (byte) 0);
if (pairing != null) {
System.arraycopy(pairing, 0, pBuffer, 0, pairing.length);
out.write(intToByte(pairing.length));
} else {
out.write(intToByte(IBE_G_SIZE * 4));
}
out.write(pBuffer, 0, pairing == null ? pBuffer.length : pairing.length);
out.flush(); | MemoryUtil.fastSecureBuffers(userBuffer, pBuffer); |
wangyeee/IBE-Secure-Message | jlib/jibe/src/main/java/hamaster/gradesgin/ibe/IBEPrivateKey.java | // Path: jlib/jibe/src/main/java/hamaster/gradesgin/util/Hex.java
// public final static int bytesToInt(byte[] bytes) {
// return bytesToInt(bytes,0);
// }
//
// Path: jlib/jibe/src/main/java/hamaster/gradesgin/util/Hex.java
// public final static byte[] intToByte(int i) {
// byte[] bt = new byte[4];
// bt[0] = (byte) ((0xff000000 & i) >> 24);
// bt[1] = (byte) ((0xff0000 & i) >> 16);
// bt[2] = (byte) ((0xff00 & i) >> 8);
// bt[3] = (byte) (0xff & i);
// return bt;
// }
//
// Path: jlib/jibe/src/main/java/hamaster/gradesgin/util/MemoryUtil.java
// final public class MemoryUtil {
//
// /**
// * 在新的线程中安全擦除内存块,这个方法在执行后会快速返回<br>
// * 此方法与在新线程中执行immediateSecureBuffers方法等效
// * @param buffers 待擦除的内存块
// */
// public final static void fastSecureBuffers(byte[] ... buffers) {
// new SecureBufferThread(buffers).start();
// }
//
// /**
// * 立刻安全擦除内存块
// * @param buffers 待擦除的内存块
// */
// public final static void immediateSecureBuffers(byte[] ... buffers) {
// BigInteger i = new BigInteger(Long.toHexString(System.nanoTime()), 16);
// Random random = new SecureRandom(i.toByteArray());
// for (byte[] buffer : buffers) {
// if (buffer != null)
// random.nextBytes(buffer);
// }
// }
// }
| import static hamaster.gradesgin.util.Hex.bytesToInt;
import static hamaster.gradesgin.util.Hex.intToByte;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.Serializable;
import java.security.PrivateKey;
import java.util.Arrays;
import hamaster.gradesgin.util.MemoryUtil; | out.write(intToByte(IBE_G_SIZE * 4));
}
out.write(pBuffer, 0, pairing == null ? pBuffer.length : pairing.length);
out.flush();
MemoryUtil.fastSecureBuffers(userBuffer, pBuffer);
MemoryUtil.immediateSecureBuffers(rBuffer, hBuffer);
}
/*
* (non-Javadoc)
* @see hamaster.gradesgin.ibe.IBEConstraints#readExternal(java.io.InputStream)
*/
@Override
public void readExternal(InputStream in) throws IOException, ClassNotFoundException {
// TODO 判断私钥是否是编码过的
byte[] buffer = new byte[IBE_ZR_SIZE + IBE_G_SIZE];
int keySize = in.read(buffer);
if (keySize != buffer.length)
throw new IOException("Not enough bytes for a PrivateKey");
this.rID = new byte[IBE_ZR_SIZE];
this.hID = new byte[IBE_G_SIZE];
System.arraycopy(buffer, 0, rID, 0, IBE_ZR_SIZE);
System.arraycopy(buffer, IBE_ZR_SIZE, hID, 0, IBE_G_SIZE);
byte[] upTmp = new byte[4];
Arrays.fill(upTmp, (byte) 0);
if (4 != in.read(upTmp)) {
throw new IOException("Not enough bytes for a PrivateKey");
} | // Path: jlib/jibe/src/main/java/hamaster/gradesgin/util/Hex.java
// public final static int bytesToInt(byte[] bytes) {
// return bytesToInt(bytes,0);
// }
//
// Path: jlib/jibe/src/main/java/hamaster/gradesgin/util/Hex.java
// public final static byte[] intToByte(int i) {
// byte[] bt = new byte[4];
// bt[0] = (byte) ((0xff000000 & i) >> 24);
// bt[1] = (byte) ((0xff0000 & i) >> 16);
// bt[2] = (byte) ((0xff00 & i) >> 8);
// bt[3] = (byte) (0xff & i);
// return bt;
// }
//
// Path: jlib/jibe/src/main/java/hamaster/gradesgin/util/MemoryUtil.java
// final public class MemoryUtil {
//
// /**
// * 在新的线程中安全擦除内存块,这个方法在执行后会快速返回<br>
// * 此方法与在新线程中执行immediateSecureBuffers方法等效
// * @param buffers 待擦除的内存块
// */
// public final static void fastSecureBuffers(byte[] ... buffers) {
// new SecureBufferThread(buffers).start();
// }
//
// /**
// * 立刻安全擦除内存块
// * @param buffers 待擦除的内存块
// */
// public final static void immediateSecureBuffers(byte[] ... buffers) {
// BigInteger i = new BigInteger(Long.toHexString(System.nanoTime()), 16);
// Random random = new SecureRandom(i.toByteArray());
// for (byte[] buffer : buffers) {
// if (buffer != null)
// random.nextBytes(buffer);
// }
// }
// }
// Path: jlib/jibe/src/main/java/hamaster/gradesgin/ibe/IBEPrivateKey.java
import static hamaster.gradesgin.util.Hex.bytesToInt;
import static hamaster.gradesgin.util.Hex.intToByte;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.Serializable;
import java.security.PrivateKey;
import java.util.Arrays;
import hamaster.gradesgin.util.MemoryUtil;
out.write(intToByte(IBE_G_SIZE * 4));
}
out.write(pBuffer, 0, pairing == null ? pBuffer.length : pairing.length);
out.flush();
MemoryUtil.fastSecureBuffers(userBuffer, pBuffer);
MemoryUtil.immediateSecureBuffers(rBuffer, hBuffer);
}
/*
* (non-Javadoc)
* @see hamaster.gradesgin.ibe.IBEConstraints#readExternal(java.io.InputStream)
*/
@Override
public void readExternal(InputStream in) throws IOException, ClassNotFoundException {
// TODO 判断私钥是否是编码过的
byte[] buffer = new byte[IBE_ZR_SIZE + IBE_G_SIZE];
int keySize = in.read(buffer);
if (keySize != buffer.length)
throw new IOException("Not enough bytes for a PrivateKey");
this.rID = new byte[IBE_ZR_SIZE];
this.hID = new byte[IBE_G_SIZE];
System.arraycopy(buffer, 0, rID, 0, IBE_ZR_SIZE);
System.arraycopy(buffer, IBE_ZR_SIZE, hID, 0, IBE_G_SIZE);
byte[] upTmp = new byte[4];
Arrays.fill(upTmp, (byte) 0);
if (4 != in.read(upTmp)) {
throw new IOException("Not enough bytes for a PrivateKey");
} | int uSize = bytesToInt(upTmp); |
wangyeee/IBE-Secure-Message | jlib/ibejnilib/src/main/java/hamaster/gradesign/ibe/IBELibrary.java | // Path: jlib/ibejnilib/src/main/java/hamaster/gradesign/ibe/jni/IBENative.java
// public final class IBENative {
//
// final private static String LIB_NAME = "ibejni";
//
// static {
// System.loadLibrary(LIB_NAME);
// }
//
// /**
// * 生成系统参数
// * @param alpha_out 系统主密钥,长度20字节
// * @param g_out 参数g,长度128字节
// * @param g1_out 参数g1,长度128字节
// * @param h_out 参数h,长度128字节
// * @param pairing_str_in 椭圆曲线参数
// * @return
// */
// public static native int setup_str(byte[] alpha_out, byte[] g_out, byte[] g1_out, byte[] h_out, byte[] pairing_str_in);
//
// /**
// * 为用户生成私钥
// * @param hID_out 私钥hID参数,长度128字节
// * @param rID_out 私钥rID参数,长度20字节
// * @param user_in 用户身份,如电子邮件地址
// * @param alpha_in 系统主密钥,长度20字节
// * @param g_in 参数g,长度128字节
// * @param h_in 参数h,长度128字节
// * @param pairing_str_in 椭圆曲线参数
// * @param random_rID 是否随即生成rID
// * @return
// */
// public static native int keygen_str(byte[] hID_out, byte[] rID_out, byte[] user_in, byte[] alpha_in, byte[] g_in, byte[] h_in, byte[] pairing_str_in,
// boolean random_rID);
//
// /**
// * 加密数据
// * @param cipher_buffer_out 输出密文,长度384字节,按照uvw顺序排列
// * @param plain_in 明文,长度128字节
// * @param g_in 接收方参数g,长度128字节
// * @param g1_in 接收方参数g1,长度128字节
// * @param h_in 接收方参数h,长度128字节
// * @param alice_in 接收方身份,长度20字节
// * @param pairing_str_in 椭圆曲线参数
// * @return
// */
// public static native int encrypt_str(byte[] cipher_buffer_out, byte[] plain_in, byte[] g_in, byte[] g1_in, byte[] h_in, byte[] alice_in,
// byte[] pairing_str_in);
//
// /**
// * 解密数据
// * @param plain_buffer_out 输出明文,长度128字节
// * @param cipher_in 输入密文,长度384字节,按照uvw顺序排列
// * @param rID_in 接收方私钥rID,长度20字节
// * @param hID_in 接收方私钥hID,长度128字节
// * @param pairing_str_in 椭圆曲线参数
// * @return
// */
// public static native int decrypt_str(byte[] plain_buffer_out, byte[] cipher_in, byte[] rID_in, byte[] hID_in, byte[] pairing_str_in);
//
// private IBENative() {
// }
// }
| import hamaster.gradesign.ibe.jni.IBENative; | package hamaster.gradesign.ibe;
/**
* 对IBE的Java封装
* @author <a href="mailto:wangyeee@gmail.com">王烨</a>
*/
public final class IBELibrary {
public final static int PBC_G_SIZE = 128;
public final static int PBC_ZR_SIZE = 20;
private IBELibrary() {
}
/**
* 生成系统参数
* @param alphaOut 系统主密钥,长度20字节
* @param gOut 参数g,长度128字节
* @param g1Out 参数g1,长度128字节
* @param hOut 参数h,长度128字节
* @param pairingIn 椭圆曲线参数
* @return
*/
public final static int setup(byte[] alphaOut, byte[] gOut, byte[] g1Out, byte[] hOut, byte[] pairingIn) {
ensureArrayCapacity(alphaOut, PBC_ZR_SIZE);
ensureArrayCapacity(gOut, PBC_G_SIZE);
ensureArrayCapacity(g1Out, PBC_G_SIZE);
ensureArrayCapacity(hOut, PBC_G_SIZE); | // Path: jlib/ibejnilib/src/main/java/hamaster/gradesign/ibe/jni/IBENative.java
// public final class IBENative {
//
// final private static String LIB_NAME = "ibejni";
//
// static {
// System.loadLibrary(LIB_NAME);
// }
//
// /**
// * 生成系统参数
// * @param alpha_out 系统主密钥,长度20字节
// * @param g_out 参数g,长度128字节
// * @param g1_out 参数g1,长度128字节
// * @param h_out 参数h,长度128字节
// * @param pairing_str_in 椭圆曲线参数
// * @return
// */
// public static native int setup_str(byte[] alpha_out, byte[] g_out, byte[] g1_out, byte[] h_out, byte[] pairing_str_in);
//
// /**
// * 为用户生成私钥
// * @param hID_out 私钥hID参数,长度128字节
// * @param rID_out 私钥rID参数,长度20字节
// * @param user_in 用户身份,如电子邮件地址
// * @param alpha_in 系统主密钥,长度20字节
// * @param g_in 参数g,长度128字节
// * @param h_in 参数h,长度128字节
// * @param pairing_str_in 椭圆曲线参数
// * @param random_rID 是否随即生成rID
// * @return
// */
// public static native int keygen_str(byte[] hID_out, byte[] rID_out, byte[] user_in, byte[] alpha_in, byte[] g_in, byte[] h_in, byte[] pairing_str_in,
// boolean random_rID);
//
// /**
// * 加密数据
// * @param cipher_buffer_out 输出密文,长度384字节,按照uvw顺序排列
// * @param plain_in 明文,长度128字节
// * @param g_in 接收方参数g,长度128字节
// * @param g1_in 接收方参数g1,长度128字节
// * @param h_in 接收方参数h,长度128字节
// * @param alice_in 接收方身份,长度20字节
// * @param pairing_str_in 椭圆曲线参数
// * @return
// */
// public static native int encrypt_str(byte[] cipher_buffer_out, byte[] plain_in, byte[] g_in, byte[] g1_in, byte[] h_in, byte[] alice_in,
// byte[] pairing_str_in);
//
// /**
// * 解密数据
// * @param plain_buffer_out 输出明文,长度128字节
// * @param cipher_in 输入密文,长度384字节,按照uvw顺序排列
// * @param rID_in 接收方私钥rID,长度20字节
// * @param hID_in 接收方私钥hID,长度128字节
// * @param pairing_str_in 椭圆曲线参数
// * @return
// */
// public static native int decrypt_str(byte[] plain_buffer_out, byte[] cipher_in, byte[] rID_in, byte[] hID_in, byte[] pairing_str_in);
//
// private IBENative() {
// }
// }
// Path: jlib/ibejnilib/src/main/java/hamaster/gradesign/ibe/IBELibrary.java
import hamaster.gradesign.ibe.jni.IBENative;
package hamaster.gradesign.ibe;
/**
* 对IBE的Java封装
* @author <a href="mailto:wangyeee@gmail.com">王烨</a>
*/
public final class IBELibrary {
public final static int PBC_G_SIZE = 128;
public final static int PBC_ZR_SIZE = 20;
private IBELibrary() {
}
/**
* 生成系统参数
* @param alphaOut 系统主密钥,长度20字节
* @param gOut 参数g,长度128字节
* @param g1Out 参数g1,长度128字节
* @param hOut 参数h,长度128字节
* @param pairingIn 椭圆曲线参数
* @return
*/
public final static int setup(byte[] alphaOut, byte[] gOut, byte[] g1Out, byte[] hOut, byte[] pairingIn) {
ensureArrayCapacity(alphaOut, PBC_ZR_SIZE);
ensureArrayCapacity(gOut, PBC_G_SIZE);
ensureArrayCapacity(g1Out, PBC_G_SIZE);
ensureArrayCapacity(hOut, PBC_G_SIZE); | return IBENative.setup_str(alphaOut, gOut, g1Out, hOut, pairingIn); |
wangyeee/IBE-Secure-Message | jlib/jibe/src/main/java/hamaster/gradesgin/ibe/IBEPublicKey.java | // Path: jlib/jibe/src/main/java/hamaster/gradesgin/util/Hex.java
// public final static int bytesToInt(byte[] bytes) {
// return bytesToInt(bytes,0);
// }
//
// Path: jlib/jibe/src/main/java/hamaster/gradesgin/util/Hex.java
// public final static byte[] intToByte(int i) {
// byte[] bt = new byte[4];
// bt[0] = (byte) ((0xff000000 & i) >> 24);
// bt[1] = (byte) ((0xff0000 & i) >> 16);
// bt[2] = (byte) ((0xff00 & i) >> 8);
// bt[3] = (byte) (0xff & i);
// return bt;
// }
//
// Path: jlib/jibe/src/main/java/hamaster/gradesgin/util/MemoryUtil.java
// final public class MemoryUtil {
//
// /**
// * 在新的线程中安全擦除内存块,这个方法在执行后会快速返回<br>
// * 此方法与在新线程中执行immediateSecureBuffers方法等效
// * @param buffers 待擦除的内存块
// */
// public final static void fastSecureBuffers(byte[] ... buffers) {
// new SecureBufferThread(buffers).start();
// }
//
// /**
// * 立刻安全擦除内存块
// * @param buffers 待擦除的内存块
// */
// public final static void immediateSecureBuffers(byte[] ... buffers) {
// BigInteger i = new BigInteger(Long.toHexString(System.nanoTime()), 16);
// Random random = new SecureRandom(i.toByteArray());
// for (byte[] buffer : buffers) {
// if (buffer != null)
// random.nextBytes(buffer);
// }
// }
// }
| import static hamaster.gradesgin.util.Hex.bytesToInt;
import static hamaster.gradesgin.util.Hex.intToByte;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.Serializable;
import java.security.PublicKey;
import java.util.Arrays;
import hamaster.gradesgin.util.MemoryUtil; | * (non-Javadoc)
* @see java.security.Key#getEncoded()
*/
@Override
public byte[] getEncoded() {
return null;
}
/**
* 序列化字段:<br>
* 用户ID摘要 20字节<br>
* 用户ID长度 4字节<br>
* 用户ID字符串
* @see hamaster.gradesgin.ibe.IBEConstraints#writeExternal(java.io.OutputStream)
*/
@Override
public void writeExternal(OutputStream out) throws IOException {
byte[] encoded = getEncoded();
if (encoded != null) {
out.write(encoded);
out.flush();
return;
}
// 不编码,直接将公钥写入输出流
byte[] userBuffer = new byte[IBE_ZR_SIZE];
Arrays.fill(userBuffer, (byte) 0);
if (user != null)
System.arraycopy(user, 0, userBuffer, 0, IBE_ZR_SIZE > user.length ? user.length : IBE_ZR_SIZE);
out.write(userBuffer);
int keySize = userString == null ? 0 : userString.getBytes(USER_STRING_ENCODING).length; | // Path: jlib/jibe/src/main/java/hamaster/gradesgin/util/Hex.java
// public final static int bytesToInt(byte[] bytes) {
// return bytesToInt(bytes,0);
// }
//
// Path: jlib/jibe/src/main/java/hamaster/gradesgin/util/Hex.java
// public final static byte[] intToByte(int i) {
// byte[] bt = new byte[4];
// bt[0] = (byte) ((0xff000000 & i) >> 24);
// bt[1] = (byte) ((0xff0000 & i) >> 16);
// bt[2] = (byte) ((0xff00 & i) >> 8);
// bt[3] = (byte) (0xff & i);
// return bt;
// }
//
// Path: jlib/jibe/src/main/java/hamaster/gradesgin/util/MemoryUtil.java
// final public class MemoryUtil {
//
// /**
// * 在新的线程中安全擦除内存块,这个方法在执行后会快速返回<br>
// * 此方法与在新线程中执行immediateSecureBuffers方法等效
// * @param buffers 待擦除的内存块
// */
// public final static void fastSecureBuffers(byte[] ... buffers) {
// new SecureBufferThread(buffers).start();
// }
//
// /**
// * 立刻安全擦除内存块
// * @param buffers 待擦除的内存块
// */
// public final static void immediateSecureBuffers(byte[] ... buffers) {
// BigInteger i = new BigInteger(Long.toHexString(System.nanoTime()), 16);
// Random random = new SecureRandom(i.toByteArray());
// for (byte[] buffer : buffers) {
// if (buffer != null)
// random.nextBytes(buffer);
// }
// }
// }
// Path: jlib/jibe/src/main/java/hamaster/gradesgin/ibe/IBEPublicKey.java
import static hamaster.gradesgin.util.Hex.bytesToInt;
import static hamaster.gradesgin.util.Hex.intToByte;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.Serializable;
import java.security.PublicKey;
import java.util.Arrays;
import hamaster.gradesgin.util.MemoryUtil;
* (non-Javadoc)
* @see java.security.Key#getEncoded()
*/
@Override
public byte[] getEncoded() {
return null;
}
/**
* 序列化字段:<br>
* 用户ID摘要 20字节<br>
* 用户ID长度 4字节<br>
* 用户ID字符串
* @see hamaster.gradesgin.ibe.IBEConstraints#writeExternal(java.io.OutputStream)
*/
@Override
public void writeExternal(OutputStream out) throws IOException {
byte[] encoded = getEncoded();
if (encoded != null) {
out.write(encoded);
out.flush();
return;
}
// 不编码,直接将公钥写入输出流
byte[] userBuffer = new byte[IBE_ZR_SIZE];
Arrays.fill(userBuffer, (byte) 0);
if (user != null)
System.arraycopy(user, 0, userBuffer, 0, IBE_ZR_SIZE > user.length ? user.length : IBE_ZR_SIZE);
out.write(userBuffer);
int keySize = userString == null ? 0 : userString.getBytes(USER_STRING_ENCODING).length; | out.write(intToByte(keySize)); |
wangyeee/IBE-Secure-Message | jlib/jibe/src/main/java/hamaster/gradesgin/ibe/IBEPublicKey.java | // Path: jlib/jibe/src/main/java/hamaster/gradesgin/util/Hex.java
// public final static int bytesToInt(byte[] bytes) {
// return bytesToInt(bytes,0);
// }
//
// Path: jlib/jibe/src/main/java/hamaster/gradesgin/util/Hex.java
// public final static byte[] intToByte(int i) {
// byte[] bt = new byte[4];
// bt[0] = (byte) ((0xff000000 & i) >> 24);
// bt[1] = (byte) ((0xff0000 & i) >> 16);
// bt[2] = (byte) ((0xff00 & i) >> 8);
// bt[3] = (byte) (0xff & i);
// return bt;
// }
//
// Path: jlib/jibe/src/main/java/hamaster/gradesgin/util/MemoryUtil.java
// final public class MemoryUtil {
//
// /**
// * 在新的线程中安全擦除内存块,这个方法在执行后会快速返回<br>
// * 此方法与在新线程中执行immediateSecureBuffers方法等效
// * @param buffers 待擦除的内存块
// */
// public final static void fastSecureBuffers(byte[] ... buffers) {
// new SecureBufferThread(buffers).start();
// }
//
// /**
// * 立刻安全擦除内存块
// * @param buffers 待擦除的内存块
// */
// public final static void immediateSecureBuffers(byte[] ... buffers) {
// BigInteger i = new BigInteger(Long.toHexString(System.nanoTime()), 16);
// Random random = new SecureRandom(i.toByteArray());
// for (byte[] buffer : buffers) {
// if (buffer != null)
// random.nextBytes(buffer);
// }
// }
// }
| import static hamaster.gradesgin.util.Hex.bytesToInt;
import static hamaster.gradesgin.util.Hex.intToByte;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.Serializable;
import java.security.PublicKey;
import java.util.Arrays;
import hamaster.gradesgin.util.MemoryUtil; | /**
* 序列化字段:<br>
* 用户ID摘要 20字节<br>
* 用户ID长度 4字节<br>
* 用户ID字符串
* @see hamaster.gradesgin.ibe.IBEConstraints#writeExternal(java.io.OutputStream)
*/
@Override
public void writeExternal(OutputStream out) throws IOException {
byte[] encoded = getEncoded();
if (encoded != null) {
out.write(encoded);
out.flush();
return;
}
// 不编码,直接将公钥写入输出流
byte[] userBuffer = new byte[IBE_ZR_SIZE];
Arrays.fill(userBuffer, (byte) 0);
if (user != null)
System.arraycopy(user, 0, userBuffer, 0, IBE_ZR_SIZE > user.length ? user.length : IBE_ZR_SIZE);
out.write(userBuffer);
int keySize = userString == null ? 0 : userString.getBytes(USER_STRING_ENCODING).length;
out.write(intToByte(keySize));
byte[] strBuffer = null;
if (userString != null) {
strBuffer = userString.getBytes(USER_STRING_ENCODING);
out.write(strBuffer);
}
out.flush();
if (strBuffer != null) | // Path: jlib/jibe/src/main/java/hamaster/gradesgin/util/Hex.java
// public final static int bytesToInt(byte[] bytes) {
// return bytesToInt(bytes,0);
// }
//
// Path: jlib/jibe/src/main/java/hamaster/gradesgin/util/Hex.java
// public final static byte[] intToByte(int i) {
// byte[] bt = new byte[4];
// bt[0] = (byte) ((0xff000000 & i) >> 24);
// bt[1] = (byte) ((0xff0000 & i) >> 16);
// bt[2] = (byte) ((0xff00 & i) >> 8);
// bt[3] = (byte) (0xff & i);
// return bt;
// }
//
// Path: jlib/jibe/src/main/java/hamaster/gradesgin/util/MemoryUtil.java
// final public class MemoryUtil {
//
// /**
// * 在新的线程中安全擦除内存块,这个方法在执行后会快速返回<br>
// * 此方法与在新线程中执行immediateSecureBuffers方法等效
// * @param buffers 待擦除的内存块
// */
// public final static void fastSecureBuffers(byte[] ... buffers) {
// new SecureBufferThread(buffers).start();
// }
//
// /**
// * 立刻安全擦除内存块
// * @param buffers 待擦除的内存块
// */
// public final static void immediateSecureBuffers(byte[] ... buffers) {
// BigInteger i = new BigInteger(Long.toHexString(System.nanoTime()), 16);
// Random random = new SecureRandom(i.toByteArray());
// for (byte[] buffer : buffers) {
// if (buffer != null)
// random.nextBytes(buffer);
// }
// }
// }
// Path: jlib/jibe/src/main/java/hamaster/gradesgin/ibe/IBEPublicKey.java
import static hamaster.gradesgin.util.Hex.bytesToInt;
import static hamaster.gradesgin.util.Hex.intToByte;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.Serializable;
import java.security.PublicKey;
import java.util.Arrays;
import hamaster.gradesgin.util.MemoryUtil;
/**
* 序列化字段:<br>
* 用户ID摘要 20字节<br>
* 用户ID长度 4字节<br>
* 用户ID字符串
* @see hamaster.gradesgin.ibe.IBEConstraints#writeExternal(java.io.OutputStream)
*/
@Override
public void writeExternal(OutputStream out) throws IOException {
byte[] encoded = getEncoded();
if (encoded != null) {
out.write(encoded);
out.flush();
return;
}
// 不编码,直接将公钥写入输出流
byte[] userBuffer = new byte[IBE_ZR_SIZE];
Arrays.fill(userBuffer, (byte) 0);
if (user != null)
System.arraycopy(user, 0, userBuffer, 0, IBE_ZR_SIZE > user.length ? user.length : IBE_ZR_SIZE);
out.write(userBuffer);
int keySize = userString == null ? 0 : userString.getBytes(USER_STRING_ENCODING).length;
out.write(intToByte(keySize));
byte[] strBuffer = null;
if (userString != null) {
strBuffer = userString.getBytes(USER_STRING_ENCODING);
out.write(strBuffer);
}
out.flush();
if (strBuffer != null) | MemoryUtil.fastSecureBuffers(userBuffer, strBuffer); |
wangyeee/IBE-Secure-Message | jlib/jibe/src/main/java/hamaster/gradesgin/ibe/IBEPublicKey.java | // Path: jlib/jibe/src/main/java/hamaster/gradesgin/util/Hex.java
// public final static int bytesToInt(byte[] bytes) {
// return bytesToInt(bytes,0);
// }
//
// Path: jlib/jibe/src/main/java/hamaster/gradesgin/util/Hex.java
// public final static byte[] intToByte(int i) {
// byte[] bt = new byte[4];
// bt[0] = (byte) ((0xff000000 & i) >> 24);
// bt[1] = (byte) ((0xff0000 & i) >> 16);
// bt[2] = (byte) ((0xff00 & i) >> 8);
// bt[3] = (byte) (0xff & i);
// return bt;
// }
//
// Path: jlib/jibe/src/main/java/hamaster/gradesgin/util/MemoryUtil.java
// final public class MemoryUtil {
//
// /**
// * 在新的线程中安全擦除内存块,这个方法在执行后会快速返回<br>
// * 此方法与在新线程中执行immediateSecureBuffers方法等效
// * @param buffers 待擦除的内存块
// */
// public final static void fastSecureBuffers(byte[] ... buffers) {
// new SecureBufferThread(buffers).start();
// }
//
// /**
// * 立刻安全擦除内存块
// * @param buffers 待擦除的内存块
// */
// public final static void immediateSecureBuffers(byte[] ... buffers) {
// BigInteger i = new BigInteger(Long.toHexString(System.nanoTime()), 16);
// Random random = new SecureRandom(i.toByteArray());
// for (byte[] buffer : buffers) {
// if (buffer != null)
// random.nextBytes(buffer);
// }
// }
// }
| import static hamaster.gradesgin.util.Hex.bytesToInt;
import static hamaster.gradesgin.util.Hex.intToByte;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.Serializable;
import java.security.PublicKey;
import java.util.Arrays;
import hamaster.gradesgin.util.MemoryUtil; | out.write(intToByte(keySize));
byte[] strBuffer = null;
if (userString != null) {
strBuffer = userString.getBytes(USER_STRING_ENCODING);
out.write(strBuffer);
}
out.flush();
if (strBuffer != null)
MemoryUtil.fastSecureBuffers(userBuffer, strBuffer);
else
MemoryUtil.fastSecureBuffers(userBuffer);
}
/*
* (non-Javadoc)
* @see hamaster.gradesgin.ibe.IBEConstraints#readExternal(java.io.InputStream)
*/
@Override
public void readExternal(InputStream in) throws IOException, ClassNotFoundException {
byte[] buffer = new byte[IBE_ZR_SIZE];
int keySize = in.read(buffer);
if (keySize != buffer.length)
throw new IOException("Not enough bytes for a PublicKey");
this.user = new byte[IBE_ZR_SIZE];
System.arraycopy(buffer, 0, user, 0, IBE_ZR_SIZE);
byte[] kTmp = new byte[4];
Arrays.fill(kTmp, (byte) 0);
if (4 != in.read(kTmp)) {
throw new IOException("Not enough bytes for a PublicKey");
} | // Path: jlib/jibe/src/main/java/hamaster/gradesgin/util/Hex.java
// public final static int bytesToInt(byte[] bytes) {
// return bytesToInt(bytes,0);
// }
//
// Path: jlib/jibe/src/main/java/hamaster/gradesgin/util/Hex.java
// public final static byte[] intToByte(int i) {
// byte[] bt = new byte[4];
// bt[0] = (byte) ((0xff000000 & i) >> 24);
// bt[1] = (byte) ((0xff0000 & i) >> 16);
// bt[2] = (byte) ((0xff00 & i) >> 8);
// bt[3] = (byte) (0xff & i);
// return bt;
// }
//
// Path: jlib/jibe/src/main/java/hamaster/gradesgin/util/MemoryUtil.java
// final public class MemoryUtil {
//
// /**
// * 在新的线程中安全擦除内存块,这个方法在执行后会快速返回<br>
// * 此方法与在新线程中执行immediateSecureBuffers方法等效
// * @param buffers 待擦除的内存块
// */
// public final static void fastSecureBuffers(byte[] ... buffers) {
// new SecureBufferThread(buffers).start();
// }
//
// /**
// * 立刻安全擦除内存块
// * @param buffers 待擦除的内存块
// */
// public final static void immediateSecureBuffers(byte[] ... buffers) {
// BigInteger i = new BigInteger(Long.toHexString(System.nanoTime()), 16);
// Random random = new SecureRandom(i.toByteArray());
// for (byte[] buffer : buffers) {
// if (buffer != null)
// random.nextBytes(buffer);
// }
// }
// }
// Path: jlib/jibe/src/main/java/hamaster/gradesgin/ibe/IBEPublicKey.java
import static hamaster.gradesgin.util.Hex.bytesToInt;
import static hamaster.gradesgin.util.Hex.intToByte;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.Serializable;
import java.security.PublicKey;
import java.util.Arrays;
import hamaster.gradesgin.util.MemoryUtil;
out.write(intToByte(keySize));
byte[] strBuffer = null;
if (userString != null) {
strBuffer = userString.getBytes(USER_STRING_ENCODING);
out.write(strBuffer);
}
out.flush();
if (strBuffer != null)
MemoryUtil.fastSecureBuffers(userBuffer, strBuffer);
else
MemoryUtil.fastSecureBuffers(userBuffer);
}
/*
* (non-Javadoc)
* @see hamaster.gradesgin.ibe.IBEConstraints#readExternal(java.io.InputStream)
*/
@Override
public void readExternal(InputStream in) throws IOException, ClassNotFoundException {
byte[] buffer = new byte[IBE_ZR_SIZE];
int keySize = in.read(buffer);
if (keySize != buffer.length)
throw new IOException("Not enough bytes for a PublicKey");
this.user = new byte[IBE_ZR_SIZE];
System.arraycopy(buffer, 0, user, 0, IBE_ZR_SIZE);
byte[] kTmp = new byte[4];
Arrays.fill(kTmp, (byte) 0);
if (4 != in.read(kTmp)) {
throw new IOException("Not enough bytes for a PublicKey");
} | keySize = bytesToInt(kTmp); |
wangyeee/IBE-Secure-Message | server/key-dist-server/src/main/java/hamaster/gradesign/keydist/auth/UserAuthenticationProvider.java | // Path: server/key-dist-server/src/main/java/hamaster/gradesign/keydist/service/UserService.java
// public interface UserService {
//
// /**
// * 处理用户登录
// * @param email 用户电子邮件地址
// * @param password 明文密码
// * @return 只有电子邮件地址和密码匹配时返回User对象
// */
// User loginWithEmail(String email, String password);
// User loginWithUsername(String username, String password);
// User loginWithToken(String username, String token);
//
// UserToken appLogin(String username, String password);
// UserToken appLogin(String username, String password, String description);
// List<UserToken> listAllUserTokens(String username, String password);
// void appLogout(String username, String uuid);
//
// boolean isEmailExist(String email);
//
// boolean isUsernameExist(String username);
//
// void register(User user, String password);
// }
| import static java.util.Objects.requireNonNull;
import org.springframework.security.authentication.BadCredentialsException;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.authentication.dao.AbstractUserDetailsAuthenticationProvider;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.stereotype.Component;
import hamaster.gradesign.keydist.service.UserService; | package hamaster.gradesign.keydist.auth;
@Component
public class UserAuthenticationProvider extends AbstractUserDetailsAuthenticationProvider {
| // Path: server/key-dist-server/src/main/java/hamaster/gradesign/keydist/service/UserService.java
// public interface UserService {
//
// /**
// * 处理用户登录
// * @param email 用户电子邮件地址
// * @param password 明文密码
// * @return 只有电子邮件地址和密码匹配时返回User对象
// */
// User loginWithEmail(String email, String password);
// User loginWithUsername(String username, String password);
// User loginWithToken(String username, String token);
//
// UserToken appLogin(String username, String password);
// UserToken appLogin(String username, String password, String description);
// List<UserToken> listAllUserTokens(String username, String password);
// void appLogout(String username, String uuid);
//
// boolean isEmailExist(String email);
//
// boolean isUsernameExist(String username);
//
// void register(User user, String password);
// }
// Path: server/key-dist-server/src/main/java/hamaster/gradesign/keydist/auth/UserAuthenticationProvider.java
import static java.util.Objects.requireNonNull;
import org.springframework.security.authentication.BadCredentialsException;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.authentication.dao.AbstractUserDetailsAuthenticationProvider;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.stereotype.Component;
import hamaster.gradesign.keydist.service.UserService;
package hamaster.gradesign.keydist.auth;
@Component
public class UserAuthenticationProvider extends AbstractUserDetailsAuthenticationProvider {
| private UserService userService; |
wangyeee/IBE-Secure-Message | jlib/ibejnilib/src/test/java/hamaster/gradesgin/test/TestIBENativeLibrary.java | // Path: jlib/ibejnilib/src/main/java/hamaster/gradesign/ibe/IBELibrary.java
// public final static int decrypt(byte[] plainBufferOut, byte[] cipherIn, byte[] rIDIn, byte[] hIDIn, byte[] pairingIn) {
// ensureArrayCapacity(plainBufferOut, PBC_G_SIZE);
// return IBENative.decrypt_str(plainBufferOut, cipherIn, rIDIn, hIDIn, pairingIn);
// }
//
// Path: jlib/ibejnilib/src/main/java/hamaster/gradesign/ibe/IBELibrary.java
// public final static int encrypt(byte[] cipherBufferOut, byte[] plainIn, byte[] gIn, byte[] g1In, byte[] hIn, byte[] aliceIn, byte[] pairingIn) {
// ensureArrayCapacity(cipherBufferOut, 3 * PBC_G_SIZE);
// return IBENative.encrypt_str(cipherBufferOut, plainIn, gIn, g1In, hIn, aliceIn, pairingIn);
// }
//
// Path: jlib/ibejnilib/src/main/java/hamaster/gradesign/ibe/IBELibrary.java
// public final static int keygen(byte[] hIDOut, byte[] rIDOut, byte[] userIn, byte[] alphaIn, byte[] gIn, byte[] hIn, byte[] pairingIn) {
// ensureArrayCapacity(rIDOut, PBC_ZR_SIZE);
// ensureArrayCapacity(hIDOut, PBC_G_SIZE);
// return IBENative.keygen_str(hIDOut, rIDOut, userIn, alphaIn, gIn, hIn, pairingIn, true);
// }
//
// Path: jlib/ibejnilib/src/main/java/hamaster/gradesign/ibe/IBELibrary.java
// public final static int setup(byte[] alphaOut, byte[] gOut, byte[] g1Out, byte[] hOut, byte[] pairingIn) {
// ensureArrayCapacity(alphaOut, PBC_ZR_SIZE);
// ensureArrayCapacity(gOut, PBC_G_SIZE);
// ensureArrayCapacity(g1Out, PBC_G_SIZE);
// ensureArrayCapacity(hOut, PBC_G_SIZE);
// return IBENative.setup_str(alphaOut, gOut, g1Out, hOut, pairingIn);
// }
| import static hamaster.gradesign.ibe.IBELibrary.decrypt;
import static hamaster.gradesign.ibe.IBELibrary.encrypt;
import static hamaster.gradesign.ibe.IBELibrary.keygen;
import static hamaster.gradesign.ibe.IBELibrary.setup;
import static org.junit.jupiter.api.Assertions.assertEquals;
import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
import java.util.ArrayList;
import java.util.List;
import org.junit.jupiter.api.Test; | package hamaster.gradesgin.test;
public class TestIBENativeLibrary {
String param =
"type a q 8780710799663312522437781984754049815806883199414208211028653399266475630880222957078625179422662221423155858769582317459277713367317481324925129998224791 h 12016012264891146079388821366740534204802954401251311822919615131047207289359704531102844802183906537786776 r 730750818665451621361119245571504901405976559617 exp2 159 exp1 107 sign1 1 sign0 1 ";
String data =
"00023065cf3983fc810a12bf66231a826dd6374b171a5db24b8192e3c951dbdede06714f5c93e1fc013ece70a85b0df3ea365c6f333f6eefeeae408d60219c2800b48ef6ef08f6c7a20064f51f29babe3432586ff8126b3f90befddcdf1162624bb071419bd3afedf1123a12100fa4839736cfe73579fa761df472d3f64b7e44";
String user = "wangyeee@gmail.com";
@Test
public void test() {
byte[] pairing_str_in = param.getBytes();
byte[] h_out = new byte[128];
byte[] g1_out = new byte[128];
byte[] g_out = new byte[128];
byte[] alpha_out = new byte[20]; | // Path: jlib/ibejnilib/src/main/java/hamaster/gradesign/ibe/IBELibrary.java
// public final static int decrypt(byte[] plainBufferOut, byte[] cipherIn, byte[] rIDIn, byte[] hIDIn, byte[] pairingIn) {
// ensureArrayCapacity(plainBufferOut, PBC_G_SIZE);
// return IBENative.decrypt_str(plainBufferOut, cipherIn, rIDIn, hIDIn, pairingIn);
// }
//
// Path: jlib/ibejnilib/src/main/java/hamaster/gradesign/ibe/IBELibrary.java
// public final static int encrypt(byte[] cipherBufferOut, byte[] plainIn, byte[] gIn, byte[] g1In, byte[] hIn, byte[] aliceIn, byte[] pairingIn) {
// ensureArrayCapacity(cipherBufferOut, 3 * PBC_G_SIZE);
// return IBENative.encrypt_str(cipherBufferOut, plainIn, gIn, g1In, hIn, aliceIn, pairingIn);
// }
//
// Path: jlib/ibejnilib/src/main/java/hamaster/gradesign/ibe/IBELibrary.java
// public final static int keygen(byte[] hIDOut, byte[] rIDOut, byte[] userIn, byte[] alphaIn, byte[] gIn, byte[] hIn, byte[] pairingIn) {
// ensureArrayCapacity(rIDOut, PBC_ZR_SIZE);
// ensureArrayCapacity(hIDOut, PBC_G_SIZE);
// return IBENative.keygen_str(hIDOut, rIDOut, userIn, alphaIn, gIn, hIn, pairingIn, true);
// }
//
// Path: jlib/ibejnilib/src/main/java/hamaster/gradesign/ibe/IBELibrary.java
// public final static int setup(byte[] alphaOut, byte[] gOut, byte[] g1Out, byte[] hOut, byte[] pairingIn) {
// ensureArrayCapacity(alphaOut, PBC_ZR_SIZE);
// ensureArrayCapacity(gOut, PBC_G_SIZE);
// ensureArrayCapacity(g1Out, PBC_G_SIZE);
// ensureArrayCapacity(hOut, PBC_G_SIZE);
// return IBENative.setup_str(alphaOut, gOut, g1Out, hOut, pairingIn);
// }
// Path: jlib/ibejnilib/src/test/java/hamaster/gradesgin/test/TestIBENativeLibrary.java
import static hamaster.gradesign.ibe.IBELibrary.decrypt;
import static hamaster.gradesign.ibe.IBELibrary.encrypt;
import static hamaster.gradesign.ibe.IBELibrary.keygen;
import static hamaster.gradesign.ibe.IBELibrary.setup;
import static org.junit.jupiter.api.Assertions.assertEquals;
import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
import java.util.ArrayList;
import java.util.List;
import org.junit.jupiter.api.Test;
package hamaster.gradesgin.test;
public class TestIBENativeLibrary {
String param =
"type a q 8780710799663312522437781984754049815806883199414208211028653399266475630880222957078625179422662221423155858769582317459277713367317481324925129998224791 h 12016012264891146079388821366740534204802954401251311822919615131047207289359704531102844802183906537786776 r 730750818665451621361119245571504901405976559617 exp2 159 exp1 107 sign1 1 sign0 1 ";
String data =
"00023065cf3983fc810a12bf66231a826dd6374b171a5db24b8192e3c951dbdede06714f5c93e1fc013ece70a85b0df3ea365c6f333f6eefeeae408d60219c2800b48ef6ef08f6c7a20064f51f29babe3432586ff8126b3f90befddcdf1162624bb071419bd3afedf1123a12100fa4839736cfe73579fa761df472d3f64b7e44";
String user = "wangyeee@gmail.com";
@Test
public void test() {
byte[] pairing_str_in = param.getBytes();
byte[] h_out = new byte[128];
byte[] g1_out = new byte[128];
byte[] g_out = new byte[128];
byte[] alpha_out = new byte[20]; | int i = setup(alpha_out, g_out, g1_out, h_out, pairing_str_in); |
wangyeee/IBE-Secure-Message | jlib/ibejnilib/src/test/java/hamaster/gradesgin/test/TestIBENativeLibrary.java | // Path: jlib/ibejnilib/src/main/java/hamaster/gradesign/ibe/IBELibrary.java
// public final static int decrypt(byte[] plainBufferOut, byte[] cipherIn, byte[] rIDIn, byte[] hIDIn, byte[] pairingIn) {
// ensureArrayCapacity(plainBufferOut, PBC_G_SIZE);
// return IBENative.decrypt_str(plainBufferOut, cipherIn, rIDIn, hIDIn, pairingIn);
// }
//
// Path: jlib/ibejnilib/src/main/java/hamaster/gradesign/ibe/IBELibrary.java
// public final static int encrypt(byte[] cipherBufferOut, byte[] plainIn, byte[] gIn, byte[] g1In, byte[] hIn, byte[] aliceIn, byte[] pairingIn) {
// ensureArrayCapacity(cipherBufferOut, 3 * PBC_G_SIZE);
// return IBENative.encrypt_str(cipherBufferOut, plainIn, gIn, g1In, hIn, aliceIn, pairingIn);
// }
//
// Path: jlib/ibejnilib/src/main/java/hamaster/gradesign/ibe/IBELibrary.java
// public final static int keygen(byte[] hIDOut, byte[] rIDOut, byte[] userIn, byte[] alphaIn, byte[] gIn, byte[] hIn, byte[] pairingIn) {
// ensureArrayCapacity(rIDOut, PBC_ZR_SIZE);
// ensureArrayCapacity(hIDOut, PBC_G_SIZE);
// return IBENative.keygen_str(hIDOut, rIDOut, userIn, alphaIn, gIn, hIn, pairingIn, true);
// }
//
// Path: jlib/ibejnilib/src/main/java/hamaster/gradesign/ibe/IBELibrary.java
// public final static int setup(byte[] alphaOut, byte[] gOut, byte[] g1Out, byte[] hOut, byte[] pairingIn) {
// ensureArrayCapacity(alphaOut, PBC_ZR_SIZE);
// ensureArrayCapacity(gOut, PBC_G_SIZE);
// ensureArrayCapacity(g1Out, PBC_G_SIZE);
// ensureArrayCapacity(hOut, PBC_G_SIZE);
// return IBENative.setup_str(alphaOut, gOut, g1Out, hOut, pairingIn);
// }
| import static hamaster.gradesign.ibe.IBELibrary.decrypt;
import static hamaster.gradesign.ibe.IBELibrary.encrypt;
import static hamaster.gradesign.ibe.IBELibrary.keygen;
import static hamaster.gradesign.ibe.IBELibrary.setup;
import static org.junit.jupiter.api.Assertions.assertEquals;
import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
import java.util.ArrayList;
import java.util.List;
import org.junit.jupiter.api.Test; | package hamaster.gradesgin.test;
public class TestIBENativeLibrary {
String param =
"type a q 8780710799663312522437781984754049815806883199414208211028653399266475630880222957078625179422662221423155858769582317459277713367317481324925129998224791 h 12016012264891146079388821366740534204802954401251311822919615131047207289359704531102844802183906537786776 r 730750818665451621361119245571504901405976559617 exp2 159 exp1 107 sign1 1 sign0 1 ";
String data =
"00023065cf3983fc810a12bf66231a826dd6374b171a5db24b8192e3c951dbdede06714f5c93e1fc013ece70a85b0df3ea365c6f333f6eefeeae408d60219c2800b48ef6ef08f6c7a20064f51f29babe3432586ff8126b3f90befddcdf1162624bb071419bd3afedf1123a12100fa4839736cfe73579fa761df472d3f64b7e44";
String user = "wangyeee@gmail.com";
@Test
public void test() {
byte[] pairing_str_in = param.getBytes();
byte[] h_out = new byte[128];
byte[] g1_out = new byte[128];
byte[] g_out = new byte[128];
byte[] alpha_out = new byte[20];
int i = setup(alpha_out, g_out, g1_out, h_out, pairing_str_in);
byte[] hID_out = new byte[128];
byte[] rID_out = new byte[20]; | // Path: jlib/ibejnilib/src/main/java/hamaster/gradesign/ibe/IBELibrary.java
// public final static int decrypt(byte[] plainBufferOut, byte[] cipherIn, byte[] rIDIn, byte[] hIDIn, byte[] pairingIn) {
// ensureArrayCapacity(plainBufferOut, PBC_G_SIZE);
// return IBENative.decrypt_str(plainBufferOut, cipherIn, rIDIn, hIDIn, pairingIn);
// }
//
// Path: jlib/ibejnilib/src/main/java/hamaster/gradesign/ibe/IBELibrary.java
// public final static int encrypt(byte[] cipherBufferOut, byte[] plainIn, byte[] gIn, byte[] g1In, byte[] hIn, byte[] aliceIn, byte[] pairingIn) {
// ensureArrayCapacity(cipherBufferOut, 3 * PBC_G_SIZE);
// return IBENative.encrypt_str(cipherBufferOut, plainIn, gIn, g1In, hIn, aliceIn, pairingIn);
// }
//
// Path: jlib/ibejnilib/src/main/java/hamaster/gradesign/ibe/IBELibrary.java
// public final static int keygen(byte[] hIDOut, byte[] rIDOut, byte[] userIn, byte[] alphaIn, byte[] gIn, byte[] hIn, byte[] pairingIn) {
// ensureArrayCapacity(rIDOut, PBC_ZR_SIZE);
// ensureArrayCapacity(hIDOut, PBC_G_SIZE);
// return IBENative.keygen_str(hIDOut, rIDOut, userIn, alphaIn, gIn, hIn, pairingIn, true);
// }
//
// Path: jlib/ibejnilib/src/main/java/hamaster/gradesign/ibe/IBELibrary.java
// public final static int setup(byte[] alphaOut, byte[] gOut, byte[] g1Out, byte[] hOut, byte[] pairingIn) {
// ensureArrayCapacity(alphaOut, PBC_ZR_SIZE);
// ensureArrayCapacity(gOut, PBC_G_SIZE);
// ensureArrayCapacity(g1Out, PBC_G_SIZE);
// ensureArrayCapacity(hOut, PBC_G_SIZE);
// return IBENative.setup_str(alphaOut, gOut, g1Out, hOut, pairingIn);
// }
// Path: jlib/ibejnilib/src/test/java/hamaster/gradesgin/test/TestIBENativeLibrary.java
import static hamaster.gradesign.ibe.IBELibrary.decrypt;
import static hamaster.gradesign.ibe.IBELibrary.encrypt;
import static hamaster.gradesign.ibe.IBELibrary.keygen;
import static hamaster.gradesign.ibe.IBELibrary.setup;
import static org.junit.jupiter.api.Assertions.assertEquals;
import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
import java.util.ArrayList;
import java.util.List;
import org.junit.jupiter.api.Test;
package hamaster.gradesgin.test;
public class TestIBENativeLibrary {
String param =
"type a q 8780710799663312522437781984754049815806883199414208211028653399266475630880222957078625179422662221423155858769582317459277713367317481324925129998224791 h 12016012264891146079388821366740534204802954401251311822919615131047207289359704531102844802183906537786776 r 730750818665451621361119245571504901405976559617 exp2 159 exp1 107 sign1 1 sign0 1 ";
String data =
"00023065cf3983fc810a12bf66231a826dd6374b171a5db24b8192e3c951dbdede06714f5c93e1fc013ece70a85b0df3ea365c6f333f6eefeeae408d60219c2800b48ef6ef08f6c7a20064f51f29babe3432586ff8126b3f90befddcdf1162624bb071419bd3afedf1123a12100fa4839736cfe73579fa761df472d3f64b7e44";
String user = "wangyeee@gmail.com";
@Test
public void test() {
byte[] pairing_str_in = param.getBytes();
byte[] h_out = new byte[128];
byte[] g1_out = new byte[128];
byte[] g_out = new byte[128];
byte[] alpha_out = new byte[20];
int i = setup(alpha_out, g_out, g1_out, h_out, pairing_str_in);
byte[] hID_out = new byte[128];
byte[] rID_out = new byte[20]; | i = keygen(hID_out, rID_out, user.getBytes(), alpha_out, g_out, h_out, pairing_str_in); |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.