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 |
|---|---|---|---|---|---|---|
eli1982/intellij-perl-plugin | src/com/intellij/perlplugin/psi/PerlTokenType.java | // Path: src/com/intellij/perlplugin/language/PerlLanguage.java
// public class PerlLanguage extends Language {
// public static final PerlLanguage INSTANCE = new PerlLanguage();
//
// public PerlLanguage() {
// super(Constants.LANGUAGE_NAME);
// SyntaxHighlighterFactory.LANGUAGE_FACTORY.addExplicitExtension(this, new PerlSyntaxHighlighterFactory() {
// @NotNull
// protected SyntaxHighlighter createHighlighter() {
// return new PerlSyntaxHighlighter();
// }
// });
// }
//
// }
| import com.intellij.perlplugin.language.PerlLanguage;
import com.intellij.psi.tree.IElementType;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull; | package com.intellij.perlplugin.psi;
public class PerlTokenType extends IElementType {
public PerlTokenType(@NotNull @NonNls String debugName) { | // Path: src/com/intellij/perlplugin/language/PerlLanguage.java
// public class PerlLanguage extends Language {
// public static final PerlLanguage INSTANCE = new PerlLanguage();
//
// public PerlLanguage() {
// super(Constants.LANGUAGE_NAME);
// SyntaxHighlighterFactory.LANGUAGE_FACTORY.addExplicitExtension(this, new PerlSyntaxHighlighterFactory() {
// @NotNull
// protected SyntaxHighlighter createHighlighter() {
// return new PerlSyntaxHighlighter();
// }
// });
// }
//
// }
// Path: src/com/intellij/perlplugin/psi/PerlTokenType.java
import com.intellij.perlplugin.language.PerlLanguage;
import com.intellij.psi.tree.IElementType;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
package com.intellij.perlplugin.psi;
public class PerlTokenType extends IElementType {
public PerlTokenType(@NotNull @NonNls String debugName) { | super(debugName, PerlLanguage.INSTANCE); |
eli1982/intellij-perl-plugin | src/com/intellij/perlplugin/psi/PerlElement.java | // Path: src/com/intellij/perlplugin/Utils.java
// public class Utils {
// public static boolean verbose = false;
// public static boolean debug = verbose || false;
// protected static OSType detectedOS;
//
// public enum OSType {
// Windows, MacOS, Linux, os, Other
// }
//
// ;
//
// public static void alert(String str) {
// System.out.println("ERROR: " + str);//TODO:: Log an exception properly
// }
//
// public static void print(Object obj) {
// System.out.println(obj);
// }
//
// public static String readFile(String filePath) {
// try {
// return new String(Files.readAllBytes(Paths.get(filePath)));
// } catch (Exception e) {
// Utils.alert(e.getMessage());
// }
// return "";
// }
//
// public static Matcher applyRegex(String regex, String content) {
// return applyRegex(regex, content, 0);
// }
//
// public static Matcher applyRegex(String regex, String content, int flags) {
// Pattern pattern = Pattern.compile(regex, flags);
// return pattern.matcher(content);
// }
//
// public static int getFilesCount(File file, FileFilter fileFilter) {
// File[] files = file.listFiles(fileFilter);
// int count = 0;
// for (File f : files)
// if (f.isDirectory())
// count += getFilesCount(f, fileFilter);
// else
// count++;
//
// return count;
// }
//
// public static boolean isValidateExtension(String path) {
// return path.endsWith(Constants.FILE_TYPE_PM) || path.endsWith(Constants.FILE_TYPE_PL);
// }
//
// public static OSType getOperatingSystemType() {
// if (detectedOS == null) {
// String OS = System.getProperty("os.name", "generic").toLowerCase(Locale.ENGLISH);
// if ((OS.indexOf("mac") >= 0) || (OS.indexOf("darwin") >= 0)) {
// detectedOS = OSType.MacOS;
// } else if (OS.indexOf("win") >= 0) {
// detectedOS = OSType.Windows;
// } else if (OS.indexOf("nux") >= 0) {
// detectedOS = OSType.Linux;
// } else {
// detectedOS = OSType.Other;
// }
// }
// return detectedOS;
// }
// }
| import com.intellij.codeInsight.completion.CompletionParameters;
import com.intellij.lang.parser.GeneratedParserUtilBase;
import com.intellij.perlplugin.Utils;
import com.intellij.psi.PsiElement;
import com.intellij.psi.tree.IElementType;
import com.intellij.psi.util.PsiTreeUtil; | PerlElement previous = previous();
while (previous.isAny(ignoredElements)) {
previous = previous.previous();
}
return previous;
}
public int getTextLength() {
return psiElement != null ? psiElement.getTextLength() : 0;
}
public String getText() {
return psiElement != null ? psiElement.getText() : null;
}
private PsiElement getPreviousPsiElement() {
if (psiElement != null) {
if (psiElement.getPrevSibling() != null) {
//get sibling
return PsiTreeUtil.getDeepestLast(psiElement.getPrevSibling());
} else {
PsiElement parent = psiElement.getParent();
while (parent != null && parent.getPrevSibling() == null) {
parent = parent.getParent();
}
if (parent == null) { //we got to top of block tree and none of the block had siblings thus there is no
//previous element as current is the first one
return null; //no previous element
} else {
return PsiTreeUtil.getDeepestLast(parent.getPrevSibling());
}
}
} else { | // Path: src/com/intellij/perlplugin/Utils.java
// public class Utils {
// public static boolean verbose = false;
// public static boolean debug = verbose || false;
// protected static OSType detectedOS;
//
// public enum OSType {
// Windows, MacOS, Linux, os, Other
// }
//
// ;
//
// public static void alert(String str) {
// System.out.println("ERROR: " + str);//TODO:: Log an exception properly
// }
//
// public static void print(Object obj) {
// System.out.println(obj);
// }
//
// public static String readFile(String filePath) {
// try {
// return new String(Files.readAllBytes(Paths.get(filePath)));
// } catch (Exception e) {
// Utils.alert(e.getMessage());
// }
// return "";
// }
//
// public static Matcher applyRegex(String regex, String content) {
// return applyRegex(regex, content, 0);
// }
//
// public static Matcher applyRegex(String regex, String content, int flags) {
// Pattern pattern = Pattern.compile(regex, flags);
// return pattern.matcher(content);
// }
//
// public static int getFilesCount(File file, FileFilter fileFilter) {
// File[] files = file.listFiles(fileFilter);
// int count = 0;
// for (File f : files)
// if (f.isDirectory())
// count += getFilesCount(f, fileFilter);
// else
// count++;
//
// return count;
// }
//
// public static boolean isValidateExtension(String path) {
// return path.endsWith(Constants.FILE_TYPE_PM) || path.endsWith(Constants.FILE_TYPE_PL);
// }
//
// public static OSType getOperatingSystemType() {
// if (detectedOS == null) {
// String OS = System.getProperty("os.name", "generic").toLowerCase(Locale.ENGLISH);
// if ((OS.indexOf("mac") >= 0) || (OS.indexOf("darwin") >= 0)) {
// detectedOS = OSType.MacOS;
// } else if (OS.indexOf("win") >= 0) {
// detectedOS = OSType.Windows;
// } else if (OS.indexOf("nux") >= 0) {
// detectedOS = OSType.Linux;
// } else {
// detectedOS = OSType.Other;
// }
// }
// return detectedOS;
// }
// }
// Path: src/com/intellij/perlplugin/psi/PerlElement.java
import com.intellij.codeInsight.completion.CompletionParameters;
import com.intellij.lang.parser.GeneratedParserUtilBase;
import com.intellij.perlplugin.Utils;
import com.intellij.psi.PsiElement;
import com.intellij.psi.tree.IElementType;
import com.intellij.psi.util.PsiTreeUtil;
PerlElement previous = previous();
while (previous.isAny(ignoredElements)) {
previous = previous.previous();
}
return previous;
}
public int getTextLength() {
return psiElement != null ? psiElement.getTextLength() : 0;
}
public String getText() {
return psiElement != null ? psiElement.getText() : null;
}
private PsiElement getPreviousPsiElement() {
if (psiElement != null) {
if (psiElement.getPrevSibling() != null) {
//get sibling
return PsiTreeUtil.getDeepestLast(psiElement.getPrevSibling());
} else {
PsiElement parent = psiElement.getParent();
while (parent != null && parent.getPrevSibling() == null) {
parent = parent.getParent();
}
if (parent == null) { //we got to top of block tree and none of the block had siblings thus there is no
//previous element as current is the first one
return null; //no previous element
} else {
return PsiTreeUtil.getDeepestLast(parent.getPrevSibling());
}
}
} else { | Utils.alert("warning: call to getPreviousPsiElement on null element"); |
eli1982/intellij-perl-plugin | src/com/intellij/perlplugin/extensions/module/builder/PerlProjectWizardStep.java | // Path: src/com/intellij/perlplugin/language/PerlIcons.java
// public class PerlIcons {
// public static final Icon LANGUAGE = IconLoader.getIcon("/com/intellij/perlplugin/resources/icons/icon_16x16.png");
// public static final Icon LANGUAGE_32 = IconLoader.getIcon("/com/intellij/perlplugin/resources/icons/icon_32x32.png");
// public static final Icon LANGUAGE_256 = IconLoader.getIcon("/com/intellij/perlplugin/resources/icons/icon_256x256.png");
// public static final Icon PACKAGE = IconLoader.getIcon("/com/intellij/perlplugin/resources/icons/package_16x16.png");
// public static final Icon SUBROUTINE = IconLoader.getIcon("/com/intellij/perlplugin/resources/icons/subroutine_16x16.png");
// public static final Icon CONSTRUCTOR = IconLoader.getIcon("/com/intellij/perlplugin/resources/icons/subroutine_16x16.png");
// public static final Icon VARIABLE = IconLoader.getIcon("/com/intellij/perlplugin/resources/icons/variable_16x16.png");
// }
| import com.intellij.ide.util.projectWizard.ModuleWizardStep;
import com.intellij.ide.util.projectWizard.WizardContext;
import com.intellij.ide.wizard.CommitStepException;
import com.intellij.openapi.Disposable;
import com.intellij.perlplugin.language.PerlIcons;
import javax.swing.*;
import javax.swing.border.TitledBorder;
import java.awt.*; | package com.intellij.perlplugin.extensions.module.builder;
public class PerlProjectWizardStep extends ModuleWizardStep implements Disposable {
private final WizardContext context;
private JLabel jLabelPerlIntro;
private JComponent myMainPanel;
public PerlProjectWizardStep(WizardContext context) {
this.context = context;
}
public void dispose() {
}
public JComponent getPreferredFocusedComponent() {
return this.myMainPanel;
}
public void onWizardFinished() throws CommitStepException {
}
public JComponent getComponent() {
if (myMainPanel == null) {
myMainPanel = new JPanel();
myMainPanel.setBorder(new TitledBorder("Perl"));
myMainPanel.setPreferredSize(new Dimension(333, 364));
jLabelPerlIntro = new JLabel();
Font labelFont = jLabelPerlIntro.getFont();
jLabelPerlIntro.setFont(new Font(labelFont.getName(), 0, 14)); | // Path: src/com/intellij/perlplugin/language/PerlIcons.java
// public class PerlIcons {
// public static final Icon LANGUAGE = IconLoader.getIcon("/com/intellij/perlplugin/resources/icons/icon_16x16.png");
// public static final Icon LANGUAGE_32 = IconLoader.getIcon("/com/intellij/perlplugin/resources/icons/icon_32x32.png");
// public static final Icon LANGUAGE_256 = IconLoader.getIcon("/com/intellij/perlplugin/resources/icons/icon_256x256.png");
// public static final Icon PACKAGE = IconLoader.getIcon("/com/intellij/perlplugin/resources/icons/package_16x16.png");
// public static final Icon SUBROUTINE = IconLoader.getIcon("/com/intellij/perlplugin/resources/icons/subroutine_16x16.png");
// public static final Icon CONSTRUCTOR = IconLoader.getIcon("/com/intellij/perlplugin/resources/icons/subroutine_16x16.png");
// public static final Icon VARIABLE = IconLoader.getIcon("/com/intellij/perlplugin/resources/icons/variable_16x16.png");
// }
// Path: src/com/intellij/perlplugin/extensions/module/builder/PerlProjectWizardStep.java
import com.intellij.ide.util.projectWizard.ModuleWizardStep;
import com.intellij.ide.util.projectWizard.WizardContext;
import com.intellij.ide.wizard.CommitStepException;
import com.intellij.openapi.Disposable;
import com.intellij.perlplugin.language.PerlIcons;
import javax.swing.*;
import javax.swing.border.TitledBorder;
import java.awt.*;
package com.intellij.perlplugin.extensions.module.builder;
public class PerlProjectWizardStep extends ModuleWizardStep implements Disposable {
private final WizardContext context;
private JLabel jLabelPerlIntro;
private JComponent myMainPanel;
public PerlProjectWizardStep(WizardContext context) {
this.context = context;
}
public void dispose() {
}
public JComponent getPreferredFocusedComponent() {
return this.myMainPanel;
}
public void onWizardFinished() throws CommitStepException {
}
public JComponent getComponent() {
if (myMainPanel == null) {
myMainPanel = new JPanel();
myMainPanel.setBorder(new TitledBorder("Perl"));
myMainPanel.setPreferredSize(new Dimension(333, 364));
jLabelPerlIntro = new JLabel();
Font labelFont = jLabelPerlIntro.getFont();
jLabelPerlIntro.setFont(new Font(labelFont.getName(), 0, 14)); | jLabelPerlIntro.setIcon(PerlIcons.LANGUAGE_256); |
eli1982/intellij-perl-plugin | src/com/intellij/perlplugin/extensions/formatting/PerlBlock.java | // Path: src/com/intellij/perlplugin/psi/PerlTypes.java
// public interface PerlTypes {
//
// IElementType PROPERTY = new PerlElementType("PROPERTY");
// IElementType CRLF = new PerlTokenType("CRLF");
// IElementType KEY = new PerlTokenType("KEY");
// IElementType OPERATOR = new PerlTokenType("OPERATOR");
// IElementType BRACES = new PerlTokenType("BRACES");
// IElementType VALUE = new PerlTokenType("VALUE");
// IElementType WHITESPACE = new PerlTokenType("WHITESPACE");
// IElementType SUBROUTINE = new PerlTokenType("SUBROUTINE");
// IElementType PACKAGE = new PerlTokenType("PACKAGE");
// IElementType POINTER = new PerlTokenType("POINTER");
// IElementType LINE_COMMENT = new PerlTokenType("LINE_COMMENT");
// IElementType MARKUP = new PerlTokenType("MARKUP");
// IElementType LANG_VARIABLE = new PerlTokenType("LANG_VARIABLE");
// IElementType LANG_FUNCTION = new PerlTokenType("LANG_FUNCTION");
// IElementType LANG_SYNTAX = new PerlTokenType("LANG_SYNTAX");
// IElementType LANG_FILE_HANDLES = new PerlTokenType("LANG_FILE_HANDLES");
// IElementType ARGUMENTS = new PerlTokenType("ARGUMENTS");
// IElementType VARIABLE = new PerlTokenType("VARIABLE");
// IElementType HASH_KEY = new PerlTokenType("HASH_KEY");
// IElementType PREDICATE = new PerlTokenType("PREDICATE");
//
// class Factory {
// public static PsiElement createElement(ASTNode node) {
// IElementType type = node.getElementType();
// // if (type == PROPERTY) {
// return new PerlPropertyImpl(node);
// // }
// // throw new AssertionError("Unknown element type: " + type);
// }
// }
//
// }
| import com.intellij.formatting.*;
import com.intellij.lang.ASTNode;
import com.intellij.perlplugin.psi.PerlTypes;
import com.intellij.psi.TokenType;
import com.intellij.psi.formatter.common.AbstractBlock;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.ArrayList;
import java.util.List; | package com.intellij.perlplugin.extensions;
public class PerlBlock extends AbstractBlock {
private SpacingBuilder spacingBuilder;
protected PerlBlock(@NotNull ASTNode node, @Nullable Wrap wrap, @Nullable Alignment alignment,
SpacingBuilder spacingBuilder) {
super(node, wrap, alignment);
this.spacingBuilder = spacingBuilder;
}
@Override
protected List<Block> buildChildren() {
List<Block> blocks = new ArrayList<Block>();
ASTNode child = myNode.getFirstChildNode();
ASTNode previousChild = null;
while (child != null) {
if (child.getElementType() != TokenType.WHITE_SPACE && | // Path: src/com/intellij/perlplugin/psi/PerlTypes.java
// public interface PerlTypes {
//
// IElementType PROPERTY = new PerlElementType("PROPERTY");
// IElementType CRLF = new PerlTokenType("CRLF");
// IElementType KEY = new PerlTokenType("KEY");
// IElementType OPERATOR = new PerlTokenType("OPERATOR");
// IElementType BRACES = new PerlTokenType("BRACES");
// IElementType VALUE = new PerlTokenType("VALUE");
// IElementType WHITESPACE = new PerlTokenType("WHITESPACE");
// IElementType SUBROUTINE = new PerlTokenType("SUBROUTINE");
// IElementType PACKAGE = new PerlTokenType("PACKAGE");
// IElementType POINTER = new PerlTokenType("POINTER");
// IElementType LINE_COMMENT = new PerlTokenType("LINE_COMMENT");
// IElementType MARKUP = new PerlTokenType("MARKUP");
// IElementType LANG_VARIABLE = new PerlTokenType("LANG_VARIABLE");
// IElementType LANG_FUNCTION = new PerlTokenType("LANG_FUNCTION");
// IElementType LANG_SYNTAX = new PerlTokenType("LANG_SYNTAX");
// IElementType LANG_FILE_HANDLES = new PerlTokenType("LANG_FILE_HANDLES");
// IElementType ARGUMENTS = new PerlTokenType("ARGUMENTS");
// IElementType VARIABLE = new PerlTokenType("VARIABLE");
// IElementType HASH_KEY = new PerlTokenType("HASH_KEY");
// IElementType PREDICATE = new PerlTokenType("PREDICATE");
//
// class Factory {
// public static PsiElement createElement(ASTNode node) {
// IElementType type = node.getElementType();
// // if (type == PROPERTY) {
// return new PerlPropertyImpl(node);
// // }
// // throw new AssertionError("Unknown element type: " + type);
// }
// }
//
// }
// Path: src/com/intellij/perlplugin/extensions/formatting/PerlBlock.java
import com.intellij.formatting.*;
import com.intellij.lang.ASTNode;
import com.intellij.perlplugin.psi.PerlTypes;
import com.intellij.psi.TokenType;
import com.intellij.psi.formatter.common.AbstractBlock;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.ArrayList;
import java.util.List;
package com.intellij.perlplugin.extensions;
public class PerlBlock extends AbstractBlock {
private SpacingBuilder spacingBuilder;
protected PerlBlock(@NotNull ASTNode node, @Nullable Wrap wrap, @Nullable Alignment alignment,
SpacingBuilder spacingBuilder) {
super(node, wrap, alignment);
this.spacingBuilder = spacingBuilder;
}
@Override
protected List<Block> buildChildren() {
List<Block> blocks = new ArrayList<Block>();
ASTNode child = myNode.getFirstChildNode();
ASTNode previousChild = null;
while (child != null) {
if (child.getElementType() != TokenType.WHITE_SPACE && | (previousChild == null || previousChild.getElementType() != PerlTypes.CRLF || |
ZhangFly/WTFSocket_Server_JAVA | src/wtf/socket/controller/WTFSocketController.java | // Path: src/wtf/socket/exception/WTFSocketException.java
// public abstract class WTFSocketException extends Exception {
//
//
// public WTFSocketException(String msg) {
// super(msg);
// }
//
// public abstract int getErrCode();
//
// }
//
// Path: src/wtf/socket/protocol/WTFSocketMsg.java
// public interface WTFSocketMsg {
//
// String getIoTag();
//
// void setIoTag(String ioTag);
//
// String getFrom();
//
// void setFrom(String from);
//
// String getTo();
//
// void setTo(String to);
//
// int getMsgId();
//
// void setMsgId(int msgId);
//
// int getMsgType();
//
// void setMsgType(int msgType);
//
// int getState();
//
// void setState(int state);
//
// void setConnectType(String connectType);
//
// String getConnectType();
//
// String getVersion();
//
// void setVersion(String version);
//
// Object getBody();
//
// <T> T getBody(Class<T> tClass);
//
// void setBody(Object body);
//
// WTFSocketMsg makeResponse();
// }
//
// Path: src/wtf/socket/routing/item/WTFSocketRoutingItem.java
// @Component
// @Scope("prototype")
// public abstract class WTFSocketRoutingItem {
//
// /**
// * 自身通讯地址
// */
// private String address;
// /**
// * 终端对象
// */
// private WTFSocketIOTerm term;
// /**
// * 接受的协议类型
// */
// private String accept;
// /**
// * 终端类型(iOS, Android, Hardware)
// */
// private String deviceType = "Unknown";
// /**
// * 是否允许覆盖
// */
// private boolean cover = true;
// /**
// * 允许用户为客户端添加自定义Tag信息
// */
// private Object tag;
//
// private WTFSocketServer context;
//
// public void setAddress(String address) {
// this.address = address;
// }
//
// public String getAddress() {
// return address;
// }
//
// public String getAccept() {
// return accept;
// }
//
// public void setAccept(String accept) {
// this.accept = accept;
// }
//
// public String getDeviceType() {
// return deviceType;
// }
//
// public void setDeviceType(String deviceType) {
// this.deviceType = deviceType == null ? "Unknown" : deviceType;
// }
//
// public WTFSocketIOTerm getTerm() {
// return term;
// }
//
// public void setTerm(WTFSocketIOTerm term) {
// this.term = term;
// }
//
// public boolean isCover() {
// return cover;
// }
//
// public void setCover(boolean cover) {
// this.cover = cover;
// }
//
// public WTFSocketServer getContext() {
// return context;
// }
//
// public void setContext(WTFSocketServer context) {
// this.context = context;
// }
//
// public Object getTag() {
// return tag;
// }
//
// public void setTag(Object tag) {
// this.tag = tag;
// }
//
// public void close() throws WTFSocketException {
// getContext().getEventsGroup().publishEvent(this, null, WTFSocketEventsType.Disconnect);
// getTerm().close();
// }
// }
//
// Path: src/wtf/socket/util/WTFSocketPriority.java
// public final class WTFSocketPriority {
//
// private WTFSocketPriority() {
// }
//
// public final static int HIGHEST = -3;
// public final static int HIGH = -2;
// public final static int MEDIUM_HIGH = -1;
// public final static int MEDIUM = 0;
// public final static int MEDIUM_LOW = 1;
// public final static int LOW = 2;
// public final static int LOWEST = 3;
//
// }
| import wtf.socket.exception.WTFSocketException;
import wtf.socket.protocol.WTFSocketMsg;
import wtf.socket.routing.item.WTFSocketRoutingItem;
import wtf.socket.util.WTFSocketPriority;
import java.util.List; | package wtf.socket.controller;
/**
* 服务器功能接口
* <p>
* Created by ZFly on 2017/4/21.
*/
public interface WTFSocketController {
/**
* 控制器优先级
* 数值越低优先级越高,默认的优先级为 WTFSocketPriority.MEDIUM
*
* @return 优先级数值
*/
default int priority() { | // Path: src/wtf/socket/exception/WTFSocketException.java
// public abstract class WTFSocketException extends Exception {
//
//
// public WTFSocketException(String msg) {
// super(msg);
// }
//
// public abstract int getErrCode();
//
// }
//
// Path: src/wtf/socket/protocol/WTFSocketMsg.java
// public interface WTFSocketMsg {
//
// String getIoTag();
//
// void setIoTag(String ioTag);
//
// String getFrom();
//
// void setFrom(String from);
//
// String getTo();
//
// void setTo(String to);
//
// int getMsgId();
//
// void setMsgId(int msgId);
//
// int getMsgType();
//
// void setMsgType(int msgType);
//
// int getState();
//
// void setState(int state);
//
// void setConnectType(String connectType);
//
// String getConnectType();
//
// String getVersion();
//
// void setVersion(String version);
//
// Object getBody();
//
// <T> T getBody(Class<T> tClass);
//
// void setBody(Object body);
//
// WTFSocketMsg makeResponse();
// }
//
// Path: src/wtf/socket/routing/item/WTFSocketRoutingItem.java
// @Component
// @Scope("prototype")
// public abstract class WTFSocketRoutingItem {
//
// /**
// * 自身通讯地址
// */
// private String address;
// /**
// * 终端对象
// */
// private WTFSocketIOTerm term;
// /**
// * 接受的协议类型
// */
// private String accept;
// /**
// * 终端类型(iOS, Android, Hardware)
// */
// private String deviceType = "Unknown";
// /**
// * 是否允许覆盖
// */
// private boolean cover = true;
// /**
// * 允许用户为客户端添加自定义Tag信息
// */
// private Object tag;
//
// private WTFSocketServer context;
//
// public void setAddress(String address) {
// this.address = address;
// }
//
// public String getAddress() {
// return address;
// }
//
// public String getAccept() {
// return accept;
// }
//
// public void setAccept(String accept) {
// this.accept = accept;
// }
//
// public String getDeviceType() {
// return deviceType;
// }
//
// public void setDeviceType(String deviceType) {
// this.deviceType = deviceType == null ? "Unknown" : deviceType;
// }
//
// public WTFSocketIOTerm getTerm() {
// return term;
// }
//
// public void setTerm(WTFSocketIOTerm term) {
// this.term = term;
// }
//
// public boolean isCover() {
// return cover;
// }
//
// public void setCover(boolean cover) {
// this.cover = cover;
// }
//
// public WTFSocketServer getContext() {
// return context;
// }
//
// public void setContext(WTFSocketServer context) {
// this.context = context;
// }
//
// public Object getTag() {
// return tag;
// }
//
// public void setTag(Object tag) {
// this.tag = tag;
// }
//
// public void close() throws WTFSocketException {
// getContext().getEventsGroup().publishEvent(this, null, WTFSocketEventsType.Disconnect);
// getTerm().close();
// }
// }
//
// Path: src/wtf/socket/util/WTFSocketPriority.java
// public final class WTFSocketPriority {
//
// private WTFSocketPriority() {
// }
//
// public final static int HIGHEST = -3;
// public final static int HIGH = -2;
// public final static int MEDIUM_HIGH = -1;
// public final static int MEDIUM = 0;
// public final static int MEDIUM_LOW = 1;
// public final static int LOW = 2;
// public final static int LOWEST = 3;
//
// }
// Path: src/wtf/socket/controller/WTFSocketController.java
import wtf.socket.exception.WTFSocketException;
import wtf.socket.protocol.WTFSocketMsg;
import wtf.socket.routing.item.WTFSocketRoutingItem;
import wtf.socket.util.WTFSocketPriority;
import java.util.List;
package wtf.socket.controller;
/**
* 服务器功能接口
* <p>
* Created by ZFly on 2017/4/21.
*/
public interface WTFSocketController {
/**
* 控制器优先级
* 数值越低优先级越高,默认的优先级为 WTFSocketPriority.MEDIUM
*
* @return 优先级数值
*/
default int priority() { | return WTFSocketPriority.MEDIUM; |
ZhangFly/WTFSocket_Server_JAVA | src/wtf/socket/controller/WTFSocketController.java | // Path: src/wtf/socket/exception/WTFSocketException.java
// public abstract class WTFSocketException extends Exception {
//
//
// public WTFSocketException(String msg) {
// super(msg);
// }
//
// public abstract int getErrCode();
//
// }
//
// Path: src/wtf/socket/protocol/WTFSocketMsg.java
// public interface WTFSocketMsg {
//
// String getIoTag();
//
// void setIoTag(String ioTag);
//
// String getFrom();
//
// void setFrom(String from);
//
// String getTo();
//
// void setTo(String to);
//
// int getMsgId();
//
// void setMsgId(int msgId);
//
// int getMsgType();
//
// void setMsgType(int msgType);
//
// int getState();
//
// void setState(int state);
//
// void setConnectType(String connectType);
//
// String getConnectType();
//
// String getVersion();
//
// void setVersion(String version);
//
// Object getBody();
//
// <T> T getBody(Class<T> tClass);
//
// void setBody(Object body);
//
// WTFSocketMsg makeResponse();
// }
//
// Path: src/wtf/socket/routing/item/WTFSocketRoutingItem.java
// @Component
// @Scope("prototype")
// public abstract class WTFSocketRoutingItem {
//
// /**
// * 自身通讯地址
// */
// private String address;
// /**
// * 终端对象
// */
// private WTFSocketIOTerm term;
// /**
// * 接受的协议类型
// */
// private String accept;
// /**
// * 终端类型(iOS, Android, Hardware)
// */
// private String deviceType = "Unknown";
// /**
// * 是否允许覆盖
// */
// private boolean cover = true;
// /**
// * 允许用户为客户端添加自定义Tag信息
// */
// private Object tag;
//
// private WTFSocketServer context;
//
// public void setAddress(String address) {
// this.address = address;
// }
//
// public String getAddress() {
// return address;
// }
//
// public String getAccept() {
// return accept;
// }
//
// public void setAccept(String accept) {
// this.accept = accept;
// }
//
// public String getDeviceType() {
// return deviceType;
// }
//
// public void setDeviceType(String deviceType) {
// this.deviceType = deviceType == null ? "Unknown" : deviceType;
// }
//
// public WTFSocketIOTerm getTerm() {
// return term;
// }
//
// public void setTerm(WTFSocketIOTerm term) {
// this.term = term;
// }
//
// public boolean isCover() {
// return cover;
// }
//
// public void setCover(boolean cover) {
// this.cover = cover;
// }
//
// public WTFSocketServer getContext() {
// return context;
// }
//
// public void setContext(WTFSocketServer context) {
// this.context = context;
// }
//
// public Object getTag() {
// return tag;
// }
//
// public void setTag(Object tag) {
// this.tag = tag;
// }
//
// public void close() throws WTFSocketException {
// getContext().getEventsGroup().publishEvent(this, null, WTFSocketEventsType.Disconnect);
// getTerm().close();
// }
// }
//
// Path: src/wtf/socket/util/WTFSocketPriority.java
// public final class WTFSocketPriority {
//
// private WTFSocketPriority() {
// }
//
// public final static int HIGHEST = -3;
// public final static int HIGH = -2;
// public final static int MEDIUM_HIGH = -1;
// public final static int MEDIUM = 0;
// public final static int MEDIUM_LOW = 1;
// public final static int LOW = 2;
// public final static int LOWEST = 3;
//
// }
| import wtf.socket.exception.WTFSocketException;
import wtf.socket.protocol.WTFSocketMsg;
import wtf.socket.routing.item.WTFSocketRoutingItem;
import wtf.socket.util.WTFSocketPriority;
import java.util.List; | package wtf.socket.controller;
/**
* 服务器功能接口
* <p>
* Created by ZFly on 2017/4/21.
*/
public interface WTFSocketController {
/**
* 控制器优先级
* 数值越低优先级越高,默认的优先级为 WTFSocketPriority.MEDIUM
*
* @return 优先级数值
*/
default int priority() {
return WTFSocketPriority.MEDIUM;
}
/**
* 是否响应该消息
*
* @param msg 消息对象
*
* @return 是否响应
*/ | // Path: src/wtf/socket/exception/WTFSocketException.java
// public abstract class WTFSocketException extends Exception {
//
//
// public WTFSocketException(String msg) {
// super(msg);
// }
//
// public abstract int getErrCode();
//
// }
//
// Path: src/wtf/socket/protocol/WTFSocketMsg.java
// public interface WTFSocketMsg {
//
// String getIoTag();
//
// void setIoTag(String ioTag);
//
// String getFrom();
//
// void setFrom(String from);
//
// String getTo();
//
// void setTo(String to);
//
// int getMsgId();
//
// void setMsgId(int msgId);
//
// int getMsgType();
//
// void setMsgType(int msgType);
//
// int getState();
//
// void setState(int state);
//
// void setConnectType(String connectType);
//
// String getConnectType();
//
// String getVersion();
//
// void setVersion(String version);
//
// Object getBody();
//
// <T> T getBody(Class<T> tClass);
//
// void setBody(Object body);
//
// WTFSocketMsg makeResponse();
// }
//
// Path: src/wtf/socket/routing/item/WTFSocketRoutingItem.java
// @Component
// @Scope("prototype")
// public abstract class WTFSocketRoutingItem {
//
// /**
// * 自身通讯地址
// */
// private String address;
// /**
// * 终端对象
// */
// private WTFSocketIOTerm term;
// /**
// * 接受的协议类型
// */
// private String accept;
// /**
// * 终端类型(iOS, Android, Hardware)
// */
// private String deviceType = "Unknown";
// /**
// * 是否允许覆盖
// */
// private boolean cover = true;
// /**
// * 允许用户为客户端添加自定义Tag信息
// */
// private Object tag;
//
// private WTFSocketServer context;
//
// public void setAddress(String address) {
// this.address = address;
// }
//
// public String getAddress() {
// return address;
// }
//
// public String getAccept() {
// return accept;
// }
//
// public void setAccept(String accept) {
// this.accept = accept;
// }
//
// public String getDeviceType() {
// return deviceType;
// }
//
// public void setDeviceType(String deviceType) {
// this.deviceType = deviceType == null ? "Unknown" : deviceType;
// }
//
// public WTFSocketIOTerm getTerm() {
// return term;
// }
//
// public void setTerm(WTFSocketIOTerm term) {
// this.term = term;
// }
//
// public boolean isCover() {
// return cover;
// }
//
// public void setCover(boolean cover) {
// this.cover = cover;
// }
//
// public WTFSocketServer getContext() {
// return context;
// }
//
// public void setContext(WTFSocketServer context) {
// this.context = context;
// }
//
// public Object getTag() {
// return tag;
// }
//
// public void setTag(Object tag) {
// this.tag = tag;
// }
//
// public void close() throws WTFSocketException {
// getContext().getEventsGroup().publishEvent(this, null, WTFSocketEventsType.Disconnect);
// getTerm().close();
// }
// }
//
// Path: src/wtf/socket/util/WTFSocketPriority.java
// public final class WTFSocketPriority {
//
// private WTFSocketPriority() {
// }
//
// public final static int HIGHEST = -3;
// public final static int HIGH = -2;
// public final static int MEDIUM_HIGH = -1;
// public final static int MEDIUM = 0;
// public final static int MEDIUM_LOW = 1;
// public final static int LOW = 2;
// public final static int LOWEST = 3;
//
// }
// Path: src/wtf/socket/controller/WTFSocketController.java
import wtf.socket.exception.WTFSocketException;
import wtf.socket.protocol.WTFSocketMsg;
import wtf.socket.routing.item.WTFSocketRoutingItem;
import wtf.socket.util.WTFSocketPriority;
import java.util.List;
package wtf.socket.controller;
/**
* 服务器功能接口
* <p>
* Created by ZFly on 2017/4/21.
*/
public interface WTFSocketController {
/**
* 控制器优先级
* 数值越低优先级越高,默认的优先级为 WTFSocketPriority.MEDIUM
*
* @return 优先级数值
*/
default int priority() {
return WTFSocketPriority.MEDIUM;
}
/**
* 是否响应该消息
*
* @param msg 消息对象
*
* @return 是否响应
*/ | boolean isResponse(WTFSocketMsg msg); |
ZhangFly/WTFSocket_Server_JAVA | src/wtf/socket/controller/WTFSocketController.java | // Path: src/wtf/socket/exception/WTFSocketException.java
// public abstract class WTFSocketException extends Exception {
//
//
// public WTFSocketException(String msg) {
// super(msg);
// }
//
// public abstract int getErrCode();
//
// }
//
// Path: src/wtf/socket/protocol/WTFSocketMsg.java
// public interface WTFSocketMsg {
//
// String getIoTag();
//
// void setIoTag(String ioTag);
//
// String getFrom();
//
// void setFrom(String from);
//
// String getTo();
//
// void setTo(String to);
//
// int getMsgId();
//
// void setMsgId(int msgId);
//
// int getMsgType();
//
// void setMsgType(int msgType);
//
// int getState();
//
// void setState(int state);
//
// void setConnectType(String connectType);
//
// String getConnectType();
//
// String getVersion();
//
// void setVersion(String version);
//
// Object getBody();
//
// <T> T getBody(Class<T> tClass);
//
// void setBody(Object body);
//
// WTFSocketMsg makeResponse();
// }
//
// Path: src/wtf/socket/routing/item/WTFSocketRoutingItem.java
// @Component
// @Scope("prototype")
// public abstract class WTFSocketRoutingItem {
//
// /**
// * 自身通讯地址
// */
// private String address;
// /**
// * 终端对象
// */
// private WTFSocketIOTerm term;
// /**
// * 接受的协议类型
// */
// private String accept;
// /**
// * 终端类型(iOS, Android, Hardware)
// */
// private String deviceType = "Unknown";
// /**
// * 是否允许覆盖
// */
// private boolean cover = true;
// /**
// * 允许用户为客户端添加自定义Tag信息
// */
// private Object tag;
//
// private WTFSocketServer context;
//
// public void setAddress(String address) {
// this.address = address;
// }
//
// public String getAddress() {
// return address;
// }
//
// public String getAccept() {
// return accept;
// }
//
// public void setAccept(String accept) {
// this.accept = accept;
// }
//
// public String getDeviceType() {
// return deviceType;
// }
//
// public void setDeviceType(String deviceType) {
// this.deviceType = deviceType == null ? "Unknown" : deviceType;
// }
//
// public WTFSocketIOTerm getTerm() {
// return term;
// }
//
// public void setTerm(WTFSocketIOTerm term) {
// this.term = term;
// }
//
// public boolean isCover() {
// return cover;
// }
//
// public void setCover(boolean cover) {
// this.cover = cover;
// }
//
// public WTFSocketServer getContext() {
// return context;
// }
//
// public void setContext(WTFSocketServer context) {
// this.context = context;
// }
//
// public Object getTag() {
// return tag;
// }
//
// public void setTag(Object tag) {
// this.tag = tag;
// }
//
// public void close() throws WTFSocketException {
// getContext().getEventsGroup().publishEvent(this, null, WTFSocketEventsType.Disconnect);
// getTerm().close();
// }
// }
//
// Path: src/wtf/socket/util/WTFSocketPriority.java
// public final class WTFSocketPriority {
//
// private WTFSocketPriority() {
// }
//
// public final static int HIGHEST = -3;
// public final static int HIGH = -2;
// public final static int MEDIUM_HIGH = -1;
// public final static int MEDIUM = 0;
// public final static int MEDIUM_LOW = 1;
// public final static int LOW = 2;
// public final static int LOWEST = 3;
//
// }
| import wtf.socket.exception.WTFSocketException;
import wtf.socket.protocol.WTFSocketMsg;
import wtf.socket.routing.item.WTFSocketRoutingItem;
import wtf.socket.util.WTFSocketPriority;
import java.util.List; | package wtf.socket.controller;
/**
* 服务器功能接口
* <p>
* Created by ZFly on 2017/4/21.
*/
public interface WTFSocketController {
/**
* 控制器优先级
* 数值越低优先级越高,默认的优先级为 WTFSocketPriority.MEDIUM
*
* @return 优先级数值
*/
default int priority() {
return WTFSocketPriority.MEDIUM;
}
/**
* 是否响应该消息
*
* @param msg 消息对象
*
* @return 是否响应
*/
boolean isResponse(WTFSocketMsg msg);
/**
* 控制器工作函数
* 当控制器的isResponse()方法为true时调用
* 当控制器工作完成后如果返回true表示该请求被消费,请求传递终止
* 否则请求继续向下传递
*
* @param source 消息发送源
* @param request 请求消息
* @param responses 回复消息列表
*
* @return 请求是否被消费
*
* @throws WTFSocketException 异常消息
*/ | // Path: src/wtf/socket/exception/WTFSocketException.java
// public abstract class WTFSocketException extends Exception {
//
//
// public WTFSocketException(String msg) {
// super(msg);
// }
//
// public abstract int getErrCode();
//
// }
//
// Path: src/wtf/socket/protocol/WTFSocketMsg.java
// public interface WTFSocketMsg {
//
// String getIoTag();
//
// void setIoTag(String ioTag);
//
// String getFrom();
//
// void setFrom(String from);
//
// String getTo();
//
// void setTo(String to);
//
// int getMsgId();
//
// void setMsgId(int msgId);
//
// int getMsgType();
//
// void setMsgType(int msgType);
//
// int getState();
//
// void setState(int state);
//
// void setConnectType(String connectType);
//
// String getConnectType();
//
// String getVersion();
//
// void setVersion(String version);
//
// Object getBody();
//
// <T> T getBody(Class<T> tClass);
//
// void setBody(Object body);
//
// WTFSocketMsg makeResponse();
// }
//
// Path: src/wtf/socket/routing/item/WTFSocketRoutingItem.java
// @Component
// @Scope("prototype")
// public abstract class WTFSocketRoutingItem {
//
// /**
// * 自身通讯地址
// */
// private String address;
// /**
// * 终端对象
// */
// private WTFSocketIOTerm term;
// /**
// * 接受的协议类型
// */
// private String accept;
// /**
// * 终端类型(iOS, Android, Hardware)
// */
// private String deviceType = "Unknown";
// /**
// * 是否允许覆盖
// */
// private boolean cover = true;
// /**
// * 允许用户为客户端添加自定义Tag信息
// */
// private Object tag;
//
// private WTFSocketServer context;
//
// public void setAddress(String address) {
// this.address = address;
// }
//
// public String getAddress() {
// return address;
// }
//
// public String getAccept() {
// return accept;
// }
//
// public void setAccept(String accept) {
// this.accept = accept;
// }
//
// public String getDeviceType() {
// return deviceType;
// }
//
// public void setDeviceType(String deviceType) {
// this.deviceType = deviceType == null ? "Unknown" : deviceType;
// }
//
// public WTFSocketIOTerm getTerm() {
// return term;
// }
//
// public void setTerm(WTFSocketIOTerm term) {
// this.term = term;
// }
//
// public boolean isCover() {
// return cover;
// }
//
// public void setCover(boolean cover) {
// this.cover = cover;
// }
//
// public WTFSocketServer getContext() {
// return context;
// }
//
// public void setContext(WTFSocketServer context) {
// this.context = context;
// }
//
// public Object getTag() {
// return tag;
// }
//
// public void setTag(Object tag) {
// this.tag = tag;
// }
//
// public void close() throws WTFSocketException {
// getContext().getEventsGroup().publishEvent(this, null, WTFSocketEventsType.Disconnect);
// getTerm().close();
// }
// }
//
// Path: src/wtf/socket/util/WTFSocketPriority.java
// public final class WTFSocketPriority {
//
// private WTFSocketPriority() {
// }
//
// public final static int HIGHEST = -3;
// public final static int HIGH = -2;
// public final static int MEDIUM_HIGH = -1;
// public final static int MEDIUM = 0;
// public final static int MEDIUM_LOW = 1;
// public final static int LOW = 2;
// public final static int LOWEST = 3;
//
// }
// Path: src/wtf/socket/controller/WTFSocketController.java
import wtf.socket.exception.WTFSocketException;
import wtf.socket.protocol.WTFSocketMsg;
import wtf.socket.routing.item.WTFSocketRoutingItem;
import wtf.socket.util.WTFSocketPriority;
import java.util.List;
package wtf.socket.controller;
/**
* 服务器功能接口
* <p>
* Created by ZFly on 2017/4/21.
*/
public interface WTFSocketController {
/**
* 控制器优先级
* 数值越低优先级越高,默认的优先级为 WTFSocketPriority.MEDIUM
*
* @return 优先级数值
*/
default int priority() {
return WTFSocketPriority.MEDIUM;
}
/**
* 是否响应该消息
*
* @param msg 消息对象
*
* @return 是否响应
*/
boolean isResponse(WTFSocketMsg msg);
/**
* 控制器工作函数
* 当控制器的isResponse()方法为true时调用
* 当控制器工作完成后如果返回true表示该请求被消费,请求传递终止
* 否则请求继续向下传递
*
* @param source 消息发送源
* @param request 请求消息
* @param responses 回复消息列表
*
* @return 请求是否被消费
*
* @throws WTFSocketException 异常消息
*/ | boolean work(WTFSocketRoutingItem source, WTFSocketMsg request, List<WTFSocketMsg> responses) throws WTFSocketException; |
ZhangFly/WTFSocket_Server_JAVA | src/wtf/socket/controller/WTFSocketController.java | // Path: src/wtf/socket/exception/WTFSocketException.java
// public abstract class WTFSocketException extends Exception {
//
//
// public WTFSocketException(String msg) {
// super(msg);
// }
//
// public abstract int getErrCode();
//
// }
//
// Path: src/wtf/socket/protocol/WTFSocketMsg.java
// public interface WTFSocketMsg {
//
// String getIoTag();
//
// void setIoTag(String ioTag);
//
// String getFrom();
//
// void setFrom(String from);
//
// String getTo();
//
// void setTo(String to);
//
// int getMsgId();
//
// void setMsgId(int msgId);
//
// int getMsgType();
//
// void setMsgType(int msgType);
//
// int getState();
//
// void setState(int state);
//
// void setConnectType(String connectType);
//
// String getConnectType();
//
// String getVersion();
//
// void setVersion(String version);
//
// Object getBody();
//
// <T> T getBody(Class<T> tClass);
//
// void setBody(Object body);
//
// WTFSocketMsg makeResponse();
// }
//
// Path: src/wtf/socket/routing/item/WTFSocketRoutingItem.java
// @Component
// @Scope("prototype")
// public abstract class WTFSocketRoutingItem {
//
// /**
// * 自身通讯地址
// */
// private String address;
// /**
// * 终端对象
// */
// private WTFSocketIOTerm term;
// /**
// * 接受的协议类型
// */
// private String accept;
// /**
// * 终端类型(iOS, Android, Hardware)
// */
// private String deviceType = "Unknown";
// /**
// * 是否允许覆盖
// */
// private boolean cover = true;
// /**
// * 允许用户为客户端添加自定义Tag信息
// */
// private Object tag;
//
// private WTFSocketServer context;
//
// public void setAddress(String address) {
// this.address = address;
// }
//
// public String getAddress() {
// return address;
// }
//
// public String getAccept() {
// return accept;
// }
//
// public void setAccept(String accept) {
// this.accept = accept;
// }
//
// public String getDeviceType() {
// return deviceType;
// }
//
// public void setDeviceType(String deviceType) {
// this.deviceType = deviceType == null ? "Unknown" : deviceType;
// }
//
// public WTFSocketIOTerm getTerm() {
// return term;
// }
//
// public void setTerm(WTFSocketIOTerm term) {
// this.term = term;
// }
//
// public boolean isCover() {
// return cover;
// }
//
// public void setCover(boolean cover) {
// this.cover = cover;
// }
//
// public WTFSocketServer getContext() {
// return context;
// }
//
// public void setContext(WTFSocketServer context) {
// this.context = context;
// }
//
// public Object getTag() {
// return tag;
// }
//
// public void setTag(Object tag) {
// this.tag = tag;
// }
//
// public void close() throws WTFSocketException {
// getContext().getEventsGroup().publishEvent(this, null, WTFSocketEventsType.Disconnect);
// getTerm().close();
// }
// }
//
// Path: src/wtf/socket/util/WTFSocketPriority.java
// public final class WTFSocketPriority {
//
// private WTFSocketPriority() {
// }
//
// public final static int HIGHEST = -3;
// public final static int HIGH = -2;
// public final static int MEDIUM_HIGH = -1;
// public final static int MEDIUM = 0;
// public final static int MEDIUM_LOW = 1;
// public final static int LOW = 2;
// public final static int LOWEST = 3;
//
// }
| import wtf.socket.exception.WTFSocketException;
import wtf.socket.protocol.WTFSocketMsg;
import wtf.socket.routing.item.WTFSocketRoutingItem;
import wtf.socket.util.WTFSocketPriority;
import java.util.List; | package wtf.socket.controller;
/**
* 服务器功能接口
* <p>
* Created by ZFly on 2017/4/21.
*/
public interface WTFSocketController {
/**
* 控制器优先级
* 数值越低优先级越高,默认的优先级为 WTFSocketPriority.MEDIUM
*
* @return 优先级数值
*/
default int priority() {
return WTFSocketPriority.MEDIUM;
}
/**
* 是否响应该消息
*
* @param msg 消息对象
*
* @return 是否响应
*/
boolean isResponse(WTFSocketMsg msg);
/**
* 控制器工作函数
* 当控制器的isResponse()方法为true时调用
* 当控制器工作完成后如果返回true表示该请求被消费,请求传递终止
* 否则请求继续向下传递
*
* @param source 消息发送源
* @param request 请求消息
* @param responses 回复消息列表
*
* @return 请求是否被消费
*
* @throws WTFSocketException 异常消息
*/ | // Path: src/wtf/socket/exception/WTFSocketException.java
// public abstract class WTFSocketException extends Exception {
//
//
// public WTFSocketException(String msg) {
// super(msg);
// }
//
// public abstract int getErrCode();
//
// }
//
// Path: src/wtf/socket/protocol/WTFSocketMsg.java
// public interface WTFSocketMsg {
//
// String getIoTag();
//
// void setIoTag(String ioTag);
//
// String getFrom();
//
// void setFrom(String from);
//
// String getTo();
//
// void setTo(String to);
//
// int getMsgId();
//
// void setMsgId(int msgId);
//
// int getMsgType();
//
// void setMsgType(int msgType);
//
// int getState();
//
// void setState(int state);
//
// void setConnectType(String connectType);
//
// String getConnectType();
//
// String getVersion();
//
// void setVersion(String version);
//
// Object getBody();
//
// <T> T getBody(Class<T> tClass);
//
// void setBody(Object body);
//
// WTFSocketMsg makeResponse();
// }
//
// Path: src/wtf/socket/routing/item/WTFSocketRoutingItem.java
// @Component
// @Scope("prototype")
// public abstract class WTFSocketRoutingItem {
//
// /**
// * 自身通讯地址
// */
// private String address;
// /**
// * 终端对象
// */
// private WTFSocketIOTerm term;
// /**
// * 接受的协议类型
// */
// private String accept;
// /**
// * 终端类型(iOS, Android, Hardware)
// */
// private String deviceType = "Unknown";
// /**
// * 是否允许覆盖
// */
// private boolean cover = true;
// /**
// * 允许用户为客户端添加自定义Tag信息
// */
// private Object tag;
//
// private WTFSocketServer context;
//
// public void setAddress(String address) {
// this.address = address;
// }
//
// public String getAddress() {
// return address;
// }
//
// public String getAccept() {
// return accept;
// }
//
// public void setAccept(String accept) {
// this.accept = accept;
// }
//
// public String getDeviceType() {
// return deviceType;
// }
//
// public void setDeviceType(String deviceType) {
// this.deviceType = deviceType == null ? "Unknown" : deviceType;
// }
//
// public WTFSocketIOTerm getTerm() {
// return term;
// }
//
// public void setTerm(WTFSocketIOTerm term) {
// this.term = term;
// }
//
// public boolean isCover() {
// return cover;
// }
//
// public void setCover(boolean cover) {
// this.cover = cover;
// }
//
// public WTFSocketServer getContext() {
// return context;
// }
//
// public void setContext(WTFSocketServer context) {
// this.context = context;
// }
//
// public Object getTag() {
// return tag;
// }
//
// public void setTag(Object tag) {
// this.tag = tag;
// }
//
// public void close() throws WTFSocketException {
// getContext().getEventsGroup().publishEvent(this, null, WTFSocketEventsType.Disconnect);
// getTerm().close();
// }
// }
//
// Path: src/wtf/socket/util/WTFSocketPriority.java
// public final class WTFSocketPriority {
//
// private WTFSocketPriority() {
// }
//
// public final static int HIGHEST = -3;
// public final static int HIGH = -2;
// public final static int MEDIUM_HIGH = -1;
// public final static int MEDIUM = 0;
// public final static int MEDIUM_LOW = 1;
// public final static int LOW = 2;
// public final static int LOWEST = 3;
//
// }
// Path: src/wtf/socket/controller/WTFSocketController.java
import wtf.socket.exception.WTFSocketException;
import wtf.socket.protocol.WTFSocketMsg;
import wtf.socket.routing.item.WTFSocketRoutingItem;
import wtf.socket.util.WTFSocketPriority;
import java.util.List;
package wtf.socket.controller;
/**
* 服务器功能接口
* <p>
* Created by ZFly on 2017/4/21.
*/
public interface WTFSocketController {
/**
* 控制器优先级
* 数值越低优先级越高,默认的优先级为 WTFSocketPriority.MEDIUM
*
* @return 优先级数值
*/
default int priority() {
return WTFSocketPriority.MEDIUM;
}
/**
* 是否响应该消息
*
* @param msg 消息对象
*
* @return 是否响应
*/
boolean isResponse(WTFSocketMsg msg);
/**
* 控制器工作函数
* 当控制器的isResponse()方法为true时调用
* 当控制器工作完成后如果返回true表示该请求被消费,请求传递终止
* 否则请求继续向下传递
*
* @param source 消息发送源
* @param request 请求消息
* @param responses 回复消息列表
*
* @return 请求是否被消费
*
* @throws WTFSocketException 异常消息
*/ | boolean work(WTFSocketRoutingItem source, WTFSocketMsg request, List<WTFSocketMsg> responses) throws WTFSocketException; |
ZhangFly/WTFSocket_Server_JAVA | src/wtf/socket/secure/strategy/impl/WTFSocketBaseSecureStrategyImpl.java | // Path: src/wtf/socket/WTFSocketServer.java
// public final class WTFSocketServer {
//
// /**
// * Spring 上下文
// */
// private ApplicationContext spring = new ClassPathXmlApplicationContext("spring.wtf.socket.xml");
//
// /**
// * 消息调度组件
// * 根据消息的头信息将消息投递到指定的目的地
// */
// @Resource()
// private WTFSocketScheduler scheduler;
//
// /**
// * 路由组件
// * 查询和记录连接的地址
// */
// @Resource
// private WTFSocketRouting routing;
//
// /**
// * 协议族组件
// * IO层收到数据后选择合适的解析器将数据解析为标准消息格式
// */
// @Resource
// private WTFSocketProtocolFamily protocolFamily;
//
// /**
// * 安全组件
// * 可用添加一些安全策略,如发送数据的授权许可等
// */
// @Resource
// private WTFSocketSecureDelegatesGroup secureDelegatesGroup;
//
// /**
// * 事件组组件
// * 包含了一些服务器的监听事件
// */
// @Resource
// private WTFSocketEventListenersGroup eventsGroup;
//
// /**
// * 服务器配置
// */
// private WTFSocketConfig config;
//
// public WTFSocketServer() {
// spring.getAutowireCapableBeanFactory().autowireBean(this);
// scheduler.setContext(this);
// routing.setContext(this);
// }
//
// public void run(WTFSocketConfig config) {
// this.config = config;
// scheduler.run();
// }
//
// public WTFSocketServer addController(WTFSocketController controller) {
// if (scheduler.getHandler() instanceof WTFSocketControllersGroup) {
// ((WTFSocketControllersGroup) scheduler.getHandler()).addController(controller);
// }
// return this;
// }
//
// public WTFSocketScheduler getScheduler() {
// return scheduler;
// }
//
// public WTFSocketProtocolFamily getProtocolFamily() {
// return protocolFamily;
// }
//
// public WTFSocketSecureDelegatesGroup getSecureDelegatesGroup() {
// return secureDelegatesGroup;
// }
//
// public WTFSocketRouting getRouting() {
// return routing;
// }
//
// public WTFSocketEventListenersGroup getEventsGroup() {
// return eventsGroup;
// }
//
// public WTFSocketConfig getConfig() {
// return config;
// }
//
// public void setScheduler(WTFSocketScheduler scheduler) {
// this.scheduler = scheduler;
// }
//
// public void setProtocolFamily(WTFSocketProtocolFamily protocolFamily) {
// this.protocolFamily = protocolFamily;
// }
//
// public void setSecureDelegatesGroup(WTFSocketSecureDelegatesGroup secureDelegatesGroup) {
// this.secureDelegatesGroup = secureDelegatesGroup;
// }
//
// public void setRouting(WTFSocketRouting routing) {
// this.routing = routing;
// }
//
// public void setEventsGroup(WTFSocketEventListenersGroup eventsGroup) {
// this.eventsGroup = eventsGroup;
// }
//
// public WTFSocketConfig setConfig() {
// return config;
// }
//
//
// public ApplicationContext getSpring() {
// return spring;
// }
// }
//
// Path: src/wtf/socket/exception/WTFSocketException.java
// public abstract class WTFSocketException extends Exception {
//
//
// public WTFSocketException(String msg) {
// super(msg);
// }
//
// public abstract int getErrCode();
//
// }
//
// Path: src/wtf/socket/protocol/WTFSocketMsg.java
// public interface WTFSocketMsg {
//
// String getIoTag();
//
// void setIoTag(String ioTag);
//
// String getFrom();
//
// void setFrom(String from);
//
// String getTo();
//
// void setTo(String to);
//
// int getMsgId();
//
// void setMsgId(int msgId);
//
// int getMsgType();
//
// void setMsgType(int msgType);
//
// int getState();
//
// void setState(int state);
//
// void setConnectType(String connectType);
//
// String getConnectType();
//
// String getVersion();
//
// void setVersion(String version);
//
// Object getBody();
//
// <T> T getBody(Class<T> tClass);
//
// void setBody(Object body);
//
// WTFSocketMsg makeResponse();
// }
//
// Path: src/wtf/socket/secure/strategy/WTFSocketSecureStrategy.java
// public interface WTFSocketSecureStrategy {
//
// void check(WTFSocketServer context, WTFSocketMsg msg) throws WTFSocketException;
//
// void setNext(WTFSocketSecureStrategy next);
//
// }
| import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import wtf.socket.WTFSocketServer;
import wtf.socket.exception.WTFSocketException;
import wtf.socket.protocol.WTFSocketMsg;
import wtf.socket.secure.strategy.WTFSocketSecureStrategy; | package wtf.socket.secure.strategy.impl;
/**
*
* Created by ZFly on 2017/5/1.
*/
public abstract class WTFSocketBaseSecureStrategyImpl implements WTFSocketSecureStrategy{
protected Log logger = LogFactory.getLog(this.getClass());
protected WTFSocketSecureStrategy next;
| // Path: src/wtf/socket/WTFSocketServer.java
// public final class WTFSocketServer {
//
// /**
// * Spring 上下文
// */
// private ApplicationContext spring = new ClassPathXmlApplicationContext("spring.wtf.socket.xml");
//
// /**
// * 消息调度组件
// * 根据消息的头信息将消息投递到指定的目的地
// */
// @Resource()
// private WTFSocketScheduler scheduler;
//
// /**
// * 路由组件
// * 查询和记录连接的地址
// */
// @Resource
// private WTFSocketRouting routing;
//
// /**
// * 协议族组件
// * IO层收到数据后选择合适的解析器将数据解析为标准消息格式
// */
// @Resource
// private WTFSocketProtocolFamily protocolFamily;
//
// /**
// * 安全组件
// * 可用添加一些安全策略,如发送数据的授权许可等
// */
// @Resource
// private WTFSocketSecureDelegatesGroup secureDelegatesGroup;
//
// /**
// * 事件组组件
// * 包含了一些服务器的监听事件
// */
// @Resource
// private WTFSocketEventListenersGroup eventsGroup;
//
// /**
// * 服务器配置
// */
// private WTFSocketConfig config;
//
// public WTFSocketServer() {
// spring.getAutowireCapableBeanFactory().autowireBean(this);
// scheduler.setContext(this);
// routing.setContext(this);
// }
//
// public void run(WTFSocketConfig config) {
// this.config = config;
// scheduler.run();
// }
//
// public WTFSocketServer addController(WTFSocketController controller) {
// if (scheduler.getHandler() instanceof WTFSocketControllersGroup) {
// ((WTFSocketControllersGroup) scheduler.getHandler()).addController(controller);
// }
// return this;
// }
//
// public WTFSocketScheduler getScheduler() {
// return scheduler;
// }
//
// public WTFSocketProtocolFamily getProtocolFamily() {
// return protocolFamily;
// }
//
// public WTFSocketSecureDelegatesGroup getSecureDelegatesGroup() {
// return secureDelegatesGroup;
// }
//
// public WTFSocketRouting getRouting() {
// return routing;
// }
//
// public WTFSocketEventListenersGroup getEventsGroup() {
// return eventsGroup;
// }
//
// public WTFSocketConfig getConfig() {
// return config;
// }
//
// public void setScheduler(WTFSocketScheduler scheduler) {
// this.scheduler = scheduler;
// }
//
// public void setProtocolFamily(WTFSocketProtocolFamily protocolFamily) {
// this.protocolFamily = protocolFamily;
// }
//
// public void setSecureDelegatesGroup(WTFSocketSecureDelegatesGroup secureDelegatesGroup) {
// this.secureDelegatesGroup = secureDelegatesGroup;
// }
//
// public void setRouting(WTFSocketRouting routing) {
// this.routing = routing;
// }
//
// public void setEventsGroup(WTFSocketEventListenersGroup eventsGroup) {
// this.eventsGroup = eventsGroup;
// }
//
// public WTFSocketConfig setConfig() {
// return config;
// }
//
//
// public ApplicationContext getSpring() {
// return spring;
// }
// }
//
// Path: src/wtf/socket/exception/WTFSocketException.java
// public abstract class WTFSocketException extends Exception {
//
//
// public WTFSocketException(String msg) {
// super(msg);
// }
//
// public abstract int getErrCode();
//
// }
//
// Path: src/wtf/socket/protocol/WTFSocketMsg.java
// public interface WTFSocketMsg {
//
// String getIoTag();
//
// void setIoTag(String ioTag);
//
// String getFrom();
//
// void setFrom(String from);
//
// String getTo();
//
// void setTo(String to);
//
// int getMsgId();
//
// void setMsgId(int msgId);
//
// int getMsgType();
//
// void setMsgType(int msgType);
//
// int getState();
//
// void setState(int state);
//
// void setConnectType(String connectType);
//
// String getConnectType();
//
// String getVersion();
//
// void setVersion(String version);
//
// Object getBody();
//
// <T> T getBody(Class<T> tClass);
//
// void setBody(Object body);
//
// WTFSocketMsg makeResponse();
// }
//
// Path: src/wtf/socket/secure/strategy/WTFSocketSecureStrategy.java
// public interface WTFSocketSecureStrategy {
//
// void check(WTFSocketServer context, WTFSocketMsg msg) throws WTFSocketException;
//
// void setNext(WTFSocketSecureStrategy next);
//
// }
// Path: src/wtf/socket/secure/strategy/impl/WTFSocketBaseSecureStrategyImpl.java
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import wtf.socket.WTFSocketServer;
import wtf.socket.exception.WTFSocketException;
import wtf.socket.protocol.WTFSocketMsg;
import wtf.socket.secure.strategy.WTFSocketSecureStrategy;
package wtf.socket.secure.strategy.impl;
/**
*
* Created by ZFly on 2017/5/1.
*/
public abstract class WTFSocketBaseSecureStrategyImpl implements WTFSocketSecureStrategy{
protected Log logger = LogFactory.getLog(this.getClass());
protected WTFSocketSecureStrategy next;
| protected void doNext(WTFSocketServer context, WTFSocketMsg msg) throws WTFSocketException { |
ZhangFly/WTFSocket_Server_JAVA | src/wtf/socket/secure/strategy/impl/WTFSocketBaseSecureStrategyImpl.java | // Path: src/wtf/socket/WTFSocketServer.java
// public final class WTFSocketServer {
//
// /**
// * Spring 上下文
// */
// private ApplicationContext spring = new ClassPathXmlApplicationContext("spring.wtf.socket.xml");
//
// /**
// * 消息调度组件
// * 根据消息的头信息将消息投递到指定的目的地
// */
// @Resource()
// private WTFSocketScheduler scheduler;
//
// /**
// * 路由组件
// * 查询和记录连接的地址
// */
// @Resource
// private WTFSocketRouting routing;
//
// /**
// * 协议族组件
// * IO层收到数据后选择合适的解析器将数据解析为标准消息格式
// */
// @Resource
// private WTFSocketProtocolFamily protocolFamily;
//
// /**
// * 安全组件
// * 可用添加一些安全策略,如发送数据的授权许可等
// */
// @Resource
// private WTFSocketSecureDelegatesGroup secureDelegatesGroup;
//
// /**
// * 事件组组件
// * 包含了一些服务器的监听事件
// */
// @Resource
// private WTFSocketEventListenersGroup eventsGroup;
//
// /**
// * 服务器配置
// */
// private WTFSocketConfig config;
//
// public WTFSocketServer() {
// spring.getAutowireCapableBeanFactory().autowireBean(this);
// scheduler.setContext(this);
// routing.setContext(this);
// }
//
// public void run(WTFSocketConfig config) {
// this.config = config;
// scheduler.run();
// }
//
// public WTFSocketServer addController(WTFSocketController controller) {
// if (scheduler.getHandler() instanceof WTFSocketControllersGroup) {
// ((WTFSocketControllersGroup) scheduler.getHandler()).addController(controller);
// }
// return this;
// }
//
// public WTFSocketScheduler getScheduler() {
// return scheduler;
// }
//
// public WTFSocketProtocolFamily getProtocolFamily() {
// return protocolFamily;
// }
//
// public WTFSocketSecureDelegatesGroup getSecureDelegatesGroup() {
// return secureDelegatesGroup;
// }
//
// public WTFSocketRouting getRouting() {
// return routing;
// }
//
// public WTFSocketEventListenersGroup getEventsGroup() {
// return eventsGroup;
// }
//
// public WTFSocketConfig getConfig() {
// return config;
// }
//
// public void setScheduler(WTFSocketScheduler scheduler) {
// this.scheduler = scheduler;
// }
//
// public void setProtocolFamily(WTFSocketProtocolFamily protocolFamily) {
// this.protocolFamily = protocolFamily;
// }
//
// public void setSecureDelegatesGroup(WTFSocketSecureDelegatesGroup secureDelegatesGroup) {
// this.secureDelegatesGroup = secureDelegatesGroup;
// }
//
// public void setRouting(WTFSocketRouting routing) {
// this.routing = routing;
// }
//
// public void setEventsGroup(WTFSocketEventListenersGroup eventsGroup) {
// this.eventsGroup = eventsGroup;
// }
//
// public WTFSocketConfig setConfig() {
// return config;
// }
//
//
// public ApplicationContext getSpring() {
// return spring;
// }
// }
//
// Path: src/wtf/socket/exception/WTFSocketException.java
// public abstract class WTFSocketException extends Exception {
//
//
// public WTFSocketException(String msg) {
// super(msg);
// }
//
// public abstract int getErrCode();
//
// }
//
// Path: src/wtf/socket/protocol/WTFSocketMsg.java
// public interface WTFSocketMsg {
//
// String getIoTag();
//
// void setIoTag(String ioTag);
//
// String getFrom();
//
// void setFrom(String from);
//
// String getTo();
//
// void setTo(String to);
//
// int getMsgId();
//
// void setMsgId(int msgId);
//
// int getMsgType();
//
// void setMsgType(int msgType);
//
// int getState();
//
// void setState(int state);
//
// void setConnectType(String connectType);
//
// String getConnectType();
//
// String getVersion();
//
// void setVersion(String version);
//
// Object getBody();
//
// <T> T getBody(Class<T> tClass);
//
// void setBody(Object body);
//
// WTFSocketMsg makeResponse();
// }
//
// Path: src/wtf/socket/secure/strategy/WTFSocketSecureStrategy.java
// public interface WTFSocketSecureStrategy {
//
// void check(WTFSocketServer context, WTFSocketMsg msg) throws WTFSocketException;
//
// void setNext(WTFSocketSecureStrategy next);
//
// }
| import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import wtf.socket.WTFSocketServer;
import wtf.socket.exception.WTFSocketException;
import wtf.socket.protocol.WTFSocketMsg;
import wtf.socket.secure.strategy.WTFSocketSecureStrategy; | package wtf.socket.secure.strategy.impl;
/**
*
* Created by ZFly on 2017/5/1.
*/
public abstract class WTFSocketBaseSecureStrategyImpl implements WTFSocketSecureStrategy{
protected Log logger = LogFactory.getLog(this.getClass());
protected WTFSocketSecureStrategy next;
| // Path: src/wtf/socket/WTFSocketServer.java
// public final class WTFSocketServer {
//
// /**
// * Spring 上下文
// */
// private ApplicationContext spring = new ClassPathXmlApplicationContext("spring.wtf.socket.xml");
//
// /**
// * 消息调度组件
// * 根据消息的头信息将消息投递到指定的目的地
// */
// @Resource()
// private WTFSocketScheduler scheduler;
//
// /**
// * 路由组件
// * 查询和记录连接的地址
// */
// @Resource
// private WTFSocketRouting routing;
//
// /**
// * 协议族组件
// * IO层收到数据后选择合适的解析器将数据解析为标准消息格式
// */
// @Resource
// private WTFSocketProtocolFamily protocolFamily;
//
// /**
// * 安全组件
// * 可用添加一些安全策略,如发送数据的授权许可等
// */
// @Resource
// private WTFSocketSecureDelegatesGroup secureDelegatesGroup;
//
// /**
// * 事件组组件
// * 包含了一些服务器的监听事件
// */
// @Resource
// private WTFSocketEventListenersGroup eventsGroup;
//
// /**
// * 服务器配置
// */
// private WTFSocketConfig config;
//
// public WTFSocketServer() {
// spring.getAutowireCapableBeanFactory().autowireBean(this);
// scheduler.setContext(this);
// routing.setContext(this);
// }
//
// public void run(WTFSocketConfig config) {
// this.config = config;
// scheduler.run();
// }
//
// public WTFSocketServer addController(WTFSocketController controller) {
// if (scheduler.getHandler() instanceof WTFSocketControllersGroup) {
// ((WTFSocketControllersGroup) scheduler.getHandler()).addController(controller);
// }
// return this;
// }
//
// public WTFSocketScheduler getScheduler() {
// return scheduler;
// }
//
// public WTFSocketProtocolFamily getProtocolFamily() {
// return protocolFamily;
// }
//
// public WTFSocketSecureDelegatesGroup getSecureDelegatesGroup() {
// return secureDelegatesGroup;
// }
//
// public WTFSocketRouting getRouting() {
// return routing;
// }
//
// public WTFSocketEventListenersGroup getEventsGroup() {
// return eventsGroup;
// }
//
// public WTFSocketConfig getConfig() {
// return config;
// }
//
// public void setScheduler(WTFSocketScheduler scheduler) {
// this.scheduler = scheduler;
// }
//
// public void setProtocolFamily(WTFSocketProtocolFamily protocolFamily) {
// this.protocolFamily = protocolFamily;
// }
//
// public void setSecureDelegatesGroup(WTFSocketSecureDelegatesGroup secureDelegatesGroup) {
// this.secureDelegatesGroup = secureDelegatesGroup;
// }
//
// public void setRouting(WTFSocketRouting routing) {
// this.routing = routing;
// }
//
// public void setEventsGroup(WTFSocketEventListenersGroup eventsGroup) {
// this.eventsGroup = eventsGroup;
// }
//
// public WTFSocketConfig setConfig() {
// return config;
// }
//
//
// public ApplicationContext getSpring() {
// return spring;
// }
// }
//
// Path: src/wtf/socket/exception/WTFSocketException.java
// public abstract class WTFSocketException extends Exception {
//
//
// public WTFSocketException(String msg) {
// super(msg);
// }
//
// public abstract int getErrCode();
//
// }
//
// Path: src/wtf/socket/protocol/WTFSocketMsg.java
// public interface WTFSocketMsg {
//
// String getIoTag();
//
// void setIoTag(String ioTag);
//
// String getFrom();
//
// void setFrom(String from);
//
// String getTo();
//
// void setTo(String to);
//
// int getMsgId();
//
// void setMsgId(int msgId);
//
// int getMsgType();
//
// void setMsgType(int msgType);
//
// int getState();
//
// void setState(int state);
//
// void setConnectType(String connectType);
//
// String getConnectType();
//
// String getVersion();
//
// void setVersion(String version);
//
// Object getBody();
//
// <T> T getBody(Class<T> tClass);
//
// void setBody(Object body);
//
// WTFSocketMsg makeResponse();
// }
//
// Path: src/wtf/socket/secure/strategy/WTFSocketSecureStrategy.java
// public interface WTFSocketSecureStrategy {
//
// void check(WTFSocketServer context, WTFSocketMsg msg) throws WTFSocketException;
//
// void setNext(WTFSocketSecureStrategy next);
//
// }
// Path: src/wtf/socket/secure/strategy/impl/WTFSocketBaseSecureStrategyImpl.java
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import wtf.socket.WTFSocketServer;
import wtf.socket.exception.WTFSocketException;
import wtf.socket.protocol.WTFSocketMsg;
import wtf.socket.secure.strategy.WTFSocketSecureStrategy;
package wtf.socket.secure.strategy.impl;
/**
*
* Created by ZFly on 2017/5/1.
*/
public abstract class WTFSocketBaseSecureStrategyImpl implements WTFSocketSecureStrategy{
protected Log logger = LogFactory.getLog(this.getClass());
protected WTFSocketSecureStrategy next;
| protected void doNext(WTFSocketServer context, WTFSocketMsg msg) throws WTFSocketException { |
ZhangFly/WTFSocket_Server_JAVA | src/wtf/socket/secure/strategy/impl/WTFSocketBaseSecureStrategyImpl.java | // Path: src/wtf/socket/WTFSocketServer.java
// public final class WTFSocketServer {
//
// /**
// * Spring 上下文
// */
// private ApplicationContext spring = new ClassPathXmlApplicationContext("spring.wtf.socket.xml");
//
// /**
// * 消息调度组件
// * 根据消息的头信息将消息投递到指定的目的地
// */
// @Resource()
// private WTFSocketScheduler scheduler;
//
// /**
// * 路由组件
// * 查询和记录连接的地址
// */
// @Resource
// private WTFSocketRouting routing;
//
// /**
// * 协议族组件
// * IO层收到数据后选择合适的解析器将数据解析为标准消息格式
// */
// @Resource
// private WTFSocketProtocolFamily protocolFamily;
//
// /**
// * 安全组件
// * 可用添加一些安全策略,如发送数据的授权许可等
// */
// @Resource
// private WTFSocketSecureDelegatesGroup secureDelegatesGroup;
//
// /**
// * 事件组组件
// * 包含了一些服务器的监听事件
// */
// @Resource
// private WTFSocketEventListenersGroup eventsGroup;
//
// /**
// * 服务器配置
// */
// private WTFSocketConfig config;
//
// public WTFSocketServer() {
// spring.getAutowireCapableBeanFactory().autowireBean(this);
// scheduler.setContext(this);
// routing.setContext(this);
// }
//
// public void run(WTFSocketConfig config) {
// this.config = config;
// scheduler.run();
// }
//
// public WTFSocketServer addController(WTFSocketController controller) {
// if (scheduler.getHandler() instanceof WTFSocketControllersGroup) {
// ((WTFSocketControllersGroup) scheduler.getHandler()).addController(controller);
// }
// return this;
// }
//
// public WTFSocketScheduler getScheduler() {
// return scheduler;
// }
//
// public WTFSocketProtocolFamily getProtocolFamily() {
// return protocolFamily;
// }
//
// public WTFSocketSecureDelegatesGroup getSecureDelegatesGroup() {
// return secureDelegatesGroup;
// }
//
// public WTFSocketRouting getRouting() {
// return routing;
// }
//
// public WTFSocketEventListenersGroup getEventsGroup() {
// return eventsGroup;
// }
//
// public WTFSocketConfig getConfig() {
// return config;
// }
//
// public void setScheduler(WTFSocketScheduler scheduler) {
// this.scheduler = scheduler;
// }
//
// public void setProtocolFamily(WTFSocketProtocolFamily protocolFamily) {
// this.protocolFamily = protocolFamily;
// }
//
// public void setSecureDelegatesGroup(WTFSocketSecureDelegatesGroup secureDelegatesGroup) {
// this.secureDelegatesGroup = secureDelegatesGroup;
// }
//
// public void setRouting(WTFSocketRouting routing) {
// this.routing = routing;
// }
//
// public void setEventsGroup(WTFSocketEventListenersGroup eventsGroup) {
// this.eventsGroup = eventsGroup;
// }
//
// public WTFSocketConfig setConfig() {
// return config;
// }
//
//
// public ApplicationContext getSpring() {
// return spring;
// }
// }
//
// Path: src/wtf/socket/exception/WTFSocketException.java
// public abstract class WTFSocketException extends Exception {
//
//
// public WTFSocketException(String msg) {
// super(msg);
// }
//
// public abstract int getErrCode();
//
// }
//
// Path: src/wtf/socket/protocol/WTFSocketMsg.java
// public interface WTFSocketMsg {
//
// String getIoTag();
//
// void setIoTag(String ioTag);
//
// String getFrom();
//
// void setFrom(String from);
//
// String getTo();
//
// void setTo(String to);
//
// int getMsgId();
//
// void setMsgId(int msgId);
//
// int getMsgType();
//
// void setMsgType(int msgType);
//
// int getState();
//
// void setState(int state);
//
// void setConnectType(String connectType);
//
// String getConnectType();
//
// String getVersion();
//
// void setVersion(String version);
//
// Object getBody();
//
// <T> T getBody(Class<T> tClass);
//
// void setBody(Object body);
//
// WTFSocketMsg makeResponse();
// }
//
// Path: src/wtf/socket/secure/strategy/WTFSocketSecureStrategy.java
// public interface WTFSocketSecureStrategy {
//
// void check(WTFSocketServer context, WTFSocketMsg msg) throws WTFSocketException;
//
// void setNext(WTFSocketSecureStrategy next);
//
// }
| import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import wtf.socket.WTFSocketServer;
import wtf.socket.exception.WTFSocketException;
import wtf.socket.protocol.WTFSocketMsg;
import wtf.socket.secure.strategy.WTFSocketSecureStrategy; | package wtf.socket.secure.strategy.impl;
/**
*
* Created by ZFly on 2017/5/1.
*/
public abstract class WTFSocketBaseSecureStrategyImpl implements WTFSocketSecureStrategy{
protected Log logger = LogFactory.getLog(this.getClass());
protected WTFSocketSecureStrategy next;
| // Path: src/wtf/socket/WTFSocketServer.java
// public final class WTFSocketServer {
//
// /**
// * Spring 上下文
// */
// private ApplicationContext spring = new ClassPathXmlApplicationContext("spring.wtf.socket.xml");
//
// /**
// * 消息调度组件
// * 根据消息的头信息将消息投递到指定的目的地
// */
// @Resource()
// private WTFSocketScheduler scheduler;
//
// /**
// * 路由组件
// * 查询和记录连接的地址
// */
// @Resource
// private WTFSocketRouting routing;
//
// /**
// * 协议族组件
// * IO层收到数据后选择合适的解析器将数据解析为标准消息格式
// */
// @Resource
// private WTFSocketProtocolFamily protocolFamily;
//
// /**
// * 安全组件
// * 可用添加一些安全策略,如发送数据的授权许可等
// */
// @Resource
// private WTFSocketSecureDelegatesGroup secureDelegatesGroup;
//
// /**
// * 事件组组件
// * 包含了一些服务器的监听事件
// */
// @Resource
// private WTFSocketEventListenersGroup eventsGroup;
//
// /**
// * 服务器配置
// */
// private WTFSocketConfig config;
//
// public WTFSocketServer() {
// spring.getAutowireCapableBeanFactory().autowireBean(this);
// scheduler.setContext(this);
// routing.setContext(this);
// }
//
// public void run(WTFSocketConfig config) {
// this.config = config;
// scheduler.run();
// }
//
// public WTFSocketServer addController(WTFSocketController controller) {
// if (scheduler.getHandler() instanceof WTFSocketControllersGroup) {
// ((WTFSocketControllersGroup) scheduler.getHandler()).addController(controller);
// }
// return this;
// }
//
// public WTFSocketScheduler getScheduler() {
// return scheduler;
// }
//
// public WTFSocketProtocolFamily getProtocolFamily() {
// return protocolFamily;
// }
//
// public WTFSocketSecureDelegatesGroup getSecureDelegatesGroup() {
// return secureDelegatesGroup;
// }
//
// public WTFSocketRouting getRouting() {
// return routing;
// }
//
// public WTFSocketEventListenersGroup getEventsGroup() {
// return eventsGroup;
// }
//
// public WTFSocketConfig getConfig() {
// return config;
// }
//
// public void setScheduler(WTFSocketScheduler scheduler) {
// this.scheduler = scheduler;
// }
//
// public void setProtocolFamily(WTFSocketProtocolFamily protocolFamily) {
// this.protocolFamily = protocolFamily;
// }
//
// public void setSecureDelegatesGroup(WTFSocketSecureDelegatesGroup secureDelegatesGroup) {
// this.secureDelegatesGroup = secureDelegatesGroup;
// }
//
// public void setRouting(WTFSocketRouting routing) {
// this.routing = routing;
// }
//
// public void setEventsGroup(WTFSocketEventListenersGroup eventsGroup) {
// this.eventsGroup = eventsGroup;
// }
//
// public WTFSocketConfig setConfig() {
// return config;
// }
//
//
// public ApplicationContext getSpring() {
// return spring;
// }
// }
//
// Path: src/wtf/socket/exception/WTFSocketException.java
// public abstract class WTFSocketException extends Exception {
//
//
// public WTFSocketException(String msg) {
// super(msg);
// }
//
// public abstract int getErrCode();
//
// }
//
// Path: src/wtf/socket/protocol/WTFSocketMsg.java
// public interface WTFSocketMsg {
//
// String getIoTag();
//
// void setIoTag(String ioTag);
//
// String getFrom();
//
// void setFrom(String from);
//
// String getTo();
//
// void setTo(String to);
//
// int getMsgId();
//
// void setMsgId(int msgId);
//
// int getMsgType();
//
// void setMsgType(int msgType);
//
// int getState();
//
// void setState(int state);
//
// void setConnectType(String connectType);
//
// String getConnectType();
//
// String getVersion();
//
// void setVersion(String version);
//
// Object getBody();
//
// <T> T getBody(Class<T> tClass);
//
// void setBody(Object body);
//
// WTFSocketMsg makeResponse();
// }
//
// Path: src/wtf/socket/secure/strategy/WTFSocketSecureStrategy.java
// public interface WTFSocketSecureStrategy {
//
// void check(WTFSocketServer context, WTFSocketMsg msg) throws WTFSocketException;
//
// void setNext(WTFSocketSecureStrategy next);
//
// }
// Path: src/wtf/socket/secure/strategy/impl/WTFSocketBaseSecureStrategyImpl.java
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import wtf.socket.WTFSocketServer;
import wtf.socket.exception.WTFSocketException;
import wtf.socket.protocol.WTFSocketMsg;
import wtf.socket.secure.strategy.WTFSocketSecureStrategy;
package wtf.socket.secure.strategy.impl;
/**
*
* Created by ZFly on 2017/5/1.
*/
public abstract class WTFSocketBaseSecureStrategyImpl implements WTFSocketSecureStrategy{
protected Log logger = LogFactory.getLog(this.getClass());
protected WTFSocketSecureStrategy next;
| protected void doNext(WTFSocketServer context, WTFSocketMsg msg) throws WTFSocketException { |
ZhangFly/WTFSocket_Server_JAVA | src/wtf/socket/secure/strategy/impl/WTFSocketSourceKeepWordsSecureStrategyImpl.java | // Path: src/wtf/socket/WTFSocketServer.java
// public final class WTFSocketServer {
//
// /**
// * Spring 上下文
// */
// private ApplicationContext spring = new ClassPathXmlApplicationContext("spring.wtf.socket.xml");
//
// /**
// * 消息调度组件
// * 根据消息的头信息将消息投递到指定的目的地
// */
// @Resource()
// private WTFSocketScheduler scheduler;
//
// /**
// * 路由组件
// * 查询和记录连接的地址
// */
// @Resource
// private WTFSocketRouting routing;
//
// /**
// * 协议族组件
// * IO层收到数据后选择合适的解析器将数据解析为标准消息格式
// */
// @Resource
// private WTFSocketProtocolFamily protocolFamily;
//
// /**
// * 安全组件
// * 可用添加一些安全策略,如发送数据的授权许可等
// */
// @Resource
// private WTFSocketSecureDelegatesGroup secureDelegatesGroup;
//
// /**
// * 事件组组件
// * 包含了一些服务器的监听事件
// */
// @Resource
// private WTFSocketEventListenersGroup eventsGroup;
//
// /**
// * 服务器配置
// */
// private WTFSocketConfig config;
//
// public WTFSocketServer() {
// spring.getAutowireCapableBeanFactory().autowireBean(this);
// scheduler.setContext(this);
// routing.setContext(this);
// }
//
// public void run(WTFSocketConfig config) {
// this.config = config;
// scheduler.run();
// }
//
// public WTFSocketServer addController(WTFSocketController controller) {
// if (scheduler.getHandler() instanceof WTFSocketControllersGroup) {
// ((WTFSocketControllersGroup) scheduler.getHandler()).addController(controller);
// }
// return this;
// }
//
// public WTFSocketScheduler getScheduler() {
// return scheduler;
// }
//
// public WTFSocketProtocolFamily getProtocolFamily() {
// return protocolFamily;
// }
//
// public WTFSocketSecureDelegatesGroup getSecureDelegatesGroup() {
// return secureDelegatesGroup;
// }
//
// public WTFSocketRouting getRouting() {
// return routing;
// }
//
// public WTFSocketEventListenersGroup getEventsGroup() {
// return eventsGroup;
// }
//
// public WTFSocketConfig getConfig() {
// return config;
// }
//
// public void setScheduler(WTFSocketScheduler scheduler) {
// this.scheduler = scheduler;
// }
//
// public void setProtocolFamily(WTFSocketProtocolFamily protocolFamily) {
// this.protocolFamily = protocolFamily;
// }
//
// public void setSecureDelegatesGroup(WTFSocketSecureDelegatesGroup secureDelegatesGroup) {
// this.secureDelegatesGroup = secureDelegatesGroup;
// }
//
// public void setRouting(WTFSocketRouting routing) {
// this.routing = routing;
// }
//
// public void setEventsGroup(WTFSocketEventListenersGroup eventsGroup) {
// this.eventsGroup = eventsGroup;
// }
//
// public WTFSocketConfig setConfig() {
// return config;
// }
//
//
// public ApplicationContext getSpring() {
// return spring;
// }
// }
//
// Path: src/wtf/socket/exception/WTFSocketException.java
// public abstract class WTFSocketException extends Exception {
//
//
// public WTFSocketException(String msg) {
// super(msg);
// }
//
// public abstract int getErrCode();
//
// }
//
// Path: src/wtf/socket/exception/fatal/WTFSocketKeepWordsException.java
// public class WTFSocketKeepWordsException extends WTFSocketFatalException {
// public WTFSocketKeepWordsException(String msg) {
// super(msg);
// }
//
// @Override
// public int getErrCode() {
// return 69;
// }
// }
//
// Path: src/wtf/socket/protocol/WTFSocketMsg.java
// public interface WTFSocketMsg {
//
// String getIoTag();
//
// void setIoTag(String ioTag);
//
// String getFrom();
//
// void setFrom(String from);
//
// String getTo();
//
// void setTo(String to);
//
// int getMsgId();
//
// void setMsgId(int msgId);
//
// int getMsgType();
//
// void setMsgType(int msgType);
//
// int getState();
//
// void setState(int state);
//
// void setConnectType(String connectType);
//
// String getConnectType();
//
// String getVersion();
//
// void setVersion(String version);
//
// Object getBody();
//
// <T> T getBody(Class<T> tClass);
//
// void setBody(Object body);
//
// WTFSocketMsg makeResponse();
// }
| import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Component;
import wtf.socket.WTFSocketServer;
import wtf.socket.exception.WTFSocketException;
import wtf.socket.exception.fatal.WTFSocketKeepWordsException;
import wtf.socket.protocol.WTFSocketMsg; | package wtf.socket.secure.strategy.impl;
/**
* 是否使用了系统保留关键字
* <p>
* Created by ZFly on 2017/4/25.
*/
@Component
public final class WTFSocketSourceKeepWordsSecureStrategyImpl extends WTFSocketBaseSecureStrategyImpl {
@Override | // Path: src/wtf/socket/WTFSocketServer.java
// public final class WTFSocketServer {
//
// /**
// * Spring 上下文
// */
// private ApplicationContext spring = new ClassPathXmlApplicationContext("spring.wtf.socket.xml");
//
// /**
// * 消息调度组件
// * 根据消息的头信息将消息投递到指定的目的地
// */
// @Resource()
// private WTFSocketScheduler scheduler;
//
// /**
// * 路由组件
// * 查询和记录连接的地址
// */
// @Resource
// private WTFSocketRouting routing;
//
// /**
// * 协议族组件
// * IO层收到数据后选择合适的解析器将数据解析为标准消息格式
// */
// @Resource
// private WTFSocketProtocolFamily protocolFamily;
//
// /**
// * 安全组件
// * 可用添加一些安全策略,如发送数据的授权许可等
// */
// @Resource
// private WTFSocketSecureDelegatesGroup secureDelegatesGroup;
//
// /**
// * 事件组组件
// * 包含了一些服务器的监听事件
// */
// @Resource
// private WTFSocketEventListenersGroup eventsGroup;
//
// /**
// * 服务器配置
// */
// private WTFSocketConfig config;
//
// public WTFSocketServer() {
// spring.getAutowireCapableBeanFactory().autowireBean(this);
// scheduler.setContext(this);
// routing.setContext(this);
// }
//
// public void run(WTFSocketConfig config) {
// this.config = config;
// scheduler.run();
// }
//
// public WTFSocketServer addController(WTFSocketController controller) {
// if (scheduler.getHandler() instanceof WTFSocketControllersGroup) {
// ((WTFSocketControllersGroup) scheduler.getHandler()).addController(controller);
// }
// return this;
// }
//
// public WTFSocketScheduler getScheduler() {
// return scheduler;
// }
//
// public WTFSocketProtocolFamily getProtocolFamily() {
// return protocolFamily;
// }
//
// public WTFSocketSecureDelegatesGroup getSecureDelegatesGroup() {
// return secureDelegatesGroup;
// }
//
// public WTFSocketRouting getRouting() {
// return routing;
// }
//
// public WTFSocketEventListenersGroup getEventsGroup() {
// return eventsGroup;
// }
//
// public WTFSocketConfig getConfig() {
// return config;
// }
//
// public void setScheduler(WTFSocketScheduler scheduler) {
// this.scheduler = scheduler;
// }
//
// public void setProtocolFamily(WTFSocketProtocolFamily protocolFamily) {
// this.protocolFamily = protocolFamily;
// }
//
// public void setSecureDelegatesGroup(WTFSocketSecureDelegatesGroup secureDelegatesGroup) {
// this.secureDelegatesGroup = secureDelegatesGroup;
// }
//
// public void setRouting(WTFSocketRouting routing) {
// this.routing = routing;
// }
//
// public void setEventsGroup(WTFSocketEventListenersGroup eventsGroup) {
// this.eventsGroup = eventsGroup;
// }
//
// public WTFSocketConfig setConfig() {
// return config;
// }
//
//
// public ApplicationContext getSpring() {
// return spring;
// }
// }
//
// Path: src/wtf/socket/exception/WTFSocketException.java
// public abstract class WTFSocketException extends Exception {
//
//
// public WTFSocketException(String msg) {
// super(msg);
// }
//
// public abstract int getErrCode();
//
// }
//
// Path: src/wtf/socket/exception/fatal/WTFSocketKeepWordsException.java
// public class WTFSocketKeepWordsException extends WTFSocketFatalException {
// public WTFSocketKeepWordsException(String msg) {
// super(msg);
// }
//
// @Override
// public int getErrCode() {
// return 69;
// }
// }
//
// Path: src/wtf/socket/protocol/WTFSocketMsg.java
// public interface WTFSocketMsg {
//
// String getIoTag();
//
// void setIoTag(String ioTag);
//
// String getFrom();
//
// void setFrom(String from);
//
// String getTo();
//
// void setTo(String to);
//
// int getMsgId();
//
// void setMsgId(int msgId);
//
// int getMsgType();
//
// void setMsgType(int msgType);
//
// int getState();
//
// void setState(int state);
//
// void setConnectType(String connectType);
//
// String getConnectType();
//
// String getVersion();
//
// void setVersion(String version);
//
// Object getBody();
//
// <T> T getBody(Class<T> tClass);
//
// void setBody(Object body);
//
// WTFSocketMsg makeResponse();
// }
// Path: src/wtf/socket/secure/strategy/impl/WTFSocketSourceKeepWordsSecureStrategyImpl.java
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Component;
import wtf.socket.WTFSocketServer;
import wtf.socket.exception.WTFSocketException;
import wtf.socket.exception.fatal.WTFSocketKeepWordsException;
import wtf.socket.protocol.WTFSocketMsg;
package wtf.socket.secure.strategy.impl;
/**
* 是否使用了系统保留关键字
* <p>
* Created by ZFly on 2017/4/25.
*/
@Component
public final class WTFSocketSourceKeepWordsSecureStrategyImpl extends WTFSocketBaseSecureStrategyImpl {
@Override | public void check(WTFSocketServer context, WTFSocketMsg msg) throws WTFSocketException { |
ZhangFly/WTFSocket_Server_JAVA | src/wtf/socket/secure/strategy/impl/WTFSocketSourceKeepWordsSecureStrategyImpl.java | // Path: src/wtf/socket/WTFSocketServer.java
// public final class WTFSocketServer {
//
// /**
// * Spring 上下文
// */
// private ApplicationContext spring = new ClassPathXmlApplicationContext("spring.wtf.socket.xml");
//
// /**
// * 消息调度组件
// * 根据消息的头信息将消息投递到指定的目的地
// */
// @Resource()
// private WTFSocketScheduler scheduler;
//
// /**
// * 路由组件
// * 查询和记录连接的地址
// */
// @Resource
// private WTFSocketRouting routing;
//
// /**
// * 协议族组件
// * IO层收到数据后选择合适的解析器将数据解析为标准消息格式
// */
// @Resource
// private WTFSocketProtocolFamily protocolFamily;
//
// /**
// * 安全组件
// * 可用添加一些安全策略,如发送数据的授权许可等
// */
// @Resource
// private WTFSocketSecureDelegatesGroup secureDelegatesGroup;
//
// /**
// * 事件组组件
// * 包含了一些服务器的监听事件
// */
// @Resource
// private WTFSocketEventListenersGroup eventsGroup;
//
// /**
// * 服务器配置
// */
// private WTFSocketConfig config;
//
// public WTFSocketServer() {
// spring.getAutowireCapableBeanFactory().autowireBean(this);
// scheduler.setContext(this);
// routing.setContext(this);
// }
//
// public void run(WTFSocketConfig config) {
// this.config = config;
// scheduler.run();
// }
//
// public WTFSocketServer addController(WTFSocketController controller) {
// if (scheduler.getHandler() instanceof WTFSocketControllersGroup) {
// ((WTFSocketControllersGroup) scheduler.getHandler()).addController(controller);
// }
// return this;
// }
//
// public WTFSocketScheduler getScheduler() {
// return scheduler;
// }
//
// public WTFSocketProtocolFamily getProtocolFamily() {
// return protocolFamily;
// }
//
// public WTFSocketSecureDelegatesGroup getSecureDelegatesGroup() {
// return secureDelegatesGroup;
// }
//
// public WTFSocketRouting getRouting() {
// return routing;
// }
//
// public WTFSocketEventListenersGroup getEventsGroup() {
// return eventsGroup;
// }
//
// public WTFSocketConfig getConfig() {
// return config;
// }
//
// public void setScheduler(WTFSocketScheduler scheduler) {
// this.scheduler = scheduler;
// }
//
// public void setProtocolFamily(WTFSocketProtocolFamily protocolFamily) {
// this.protocolFamily = protocolFamily;
// }
//
// public void setSecureDelegatesGroup(WTFSocketSecureDelegatesGroup secureDelegatesGroup) {
// this.secureDelegatesGroup = secureDelegatesGroup;
// }
//
// public void setRouting(WTFSocketRouting routing) {
// this.routing = routing;
// }
//
// public void setEventsGroup(WTFSocketEventListenersGroup eventsGroup) {
// this.eventsGroup = eventsGroup;
// }
//
// public WTFSocketConfig setConfig() {
// return config;
// }
//
//
// public ApplicationContext getSpring() {
// return spring;
// }
// }
//
// Path: src/wtf/socket/exception/WTFSocketException.java
// public abstract class WTFSocketException extends Exception {
//
//
// public WTFSocketException(String msg) {
// super(msg);
// }
//
// public abstract int getErrCode();
//
// }
//
// Path: src/wtf/socket/exception/fatal/WTFSocketKeepWordsException.java
// public class WTFSocketKeepWordsException extends WTFSocketFatalException {
// public WTFSocketKeepWordsException(String msg) {
// super(msg);
// }
//
// @Override
// public int getErrCode() {
// return 69;
// }
// }
//
// Path: src/wtf/socket/protocol/WTFSocketMsg.java
// public interface WTFSocketMsg {
//
// String getIoTag();
//
// void setIoTag(String ioTag);
//
// String getFrom();
//
// void setFrom(String from);
//
// String getTo();
//
// void setTo(String to);
//
// int getMsgId();
//
// void setMsgId(int msgId);
//
// int getMsgType();
//
// void setMsgType(int msgType);
//
// int getState();
//
// void setState(int state);
//
// void setConnectType(String connectType);
//
// String getConnectType();
//
// String getVersion();
//
// void setVersion(String version);
//
// Object getBody();
//
// <T> T getBody(Class<T> tClass);
//
// void setBody(Object body);
//
// WTFSocketMsg makeResponse();
// }
| import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Component;
import wtf.socket.WTFSocketServer;
import wtf.socket.exception.WTFSocketException;
import wtf.socket.exception.fatal.WTFSocketKeepWordsException;
import wtf.socket.protocol.WTFSocketMsg; | package wtf.socket.secure.strategy.impl;
/**
* 是否使用了系统保留关键字
* <p>
* Created by ZFly on 2017/4/25.
*/
@Component
public final class WTFSocketSourceKeepWordsSecureStrategyImpl extends WTFSocketBaseSecureStrategyImpl {
@Override | // Path: src/wtf/socket/WTFSocketServer.java
// public final class WTFSocketServer {
//
// /**
// * Spring 上下文
// */
// private ApplicationContext spring = new ClassPathXmlApplicationContext("spring.wtf.socket.xml");
//
// /**
// * 消息调度组件
// * 根据消息的头信息将消息投递到指定的目的地
// */
// @Resource()
// private WTFSocketScheduler scheduler;
//
// /**
// * 路由组件
// * 查询和记录连接的地址
// */
// @Resource
// private WTFSocketRouting routing;
//
// /**
// * 协议族组件
// * IO层收到数据后选择合适的解析器将数据解析为标准消息格式
// */
// @Resource
// private WTFSocketProtocolFamily protocolFamily;
//
// /**
// * 安全组件
// * 可用添加一些安全策略,如发送数据的授权许可等
// */
// @Resource
// private WTFSocketSecureDelegatesGroup secureDelegatesGroup;
//
// /**
// * 事件组组件
// * 包含了一些服务器的监听事件
// */
// @Resource
// private WTFSocketEventListenersGroup eventsGroup;
//
// /**
// * 服务器配置
// */
// private WTFSocketConfig config;
//
// public WTFSocketServer() {
// spring.getAutowireCapableBeanFactory().autowireBean(this);
// scheduler.setContext(this);
// routing.setContext(this);
// }
//
// public void run(WTFSocketConfig config) {
// this.config = config;
// scheduler.run();
// }
//
// public WTFSocketServer addController(WTFSocketController controller) {
// if (scheduler.getHandler() instanceof WTFSocketControllersGroup) {
// ((WTFSocketControllersGroup) scheduler.getHandler()).addController(controller);
// }
// return this;
// }
//
// public WTFSocketScheduler getScheduler() {
// return scheduler;
// }
//
// public WTFSocketProtocolFamily getProtocolFamily() {
// return protocolFamily;
// }
//
// public WTFSocketSecureDelegatesGroup getSecureDelegatesGroup() {
// return secureDelegatesGroup;
// }
//
// public WTFSocketRouting getRouting() {
// return routing;
// }
//
// public WTFSocketEventListenersGroup getEventsGroup() {
// return eventsGroup;
// }
//
// public WTFSocketConfig getConfig() {
// return config;
// }
//
// public void setScheduler(WTFSocketScheduler scheduler) {
// this.scheduler = scheduler;
// }
//
// public void setProtocolFamily(WTFSocketProtocolFamily protocolFamily) {
// this.protocolFamily = protocolFamily;
// }
//
// public void setSecureDelegatesGroup(WTFSocketSecureDelegatesGroup secureDelegatesGroup) {
// this.secureDelegatesGroup = secureDelegatesGroup;
// }
//
// public void setRouting(WTFSocketRouting routing) {
// this.routing = routing;
// }
//
// public void setEventsGroup(WTFSocketEventListenersGroup eventsGroup) {
// this.eventsGroup = eventsGroup;
// }
//
// public WTFSocketConfig setConfig() {
// return config;
// }
//
//
// public ApplicationContext getSpring() {
// return spring;
// }
// }
//
// Path: src/wtf/socket/exception/WTFSocketException.java
// public abstract class WTFSocketException extends Exception {
//
//
// public WTFSocketException(String msg) {
// super(msg);
// }
//
// public abstract int getErrCode();
//
// }
//
// Path: src/wtf/socket/exception/fatal/WTFSocketKeepWordsException.java
// public class WTFSocketKeepWordsException extends WTFSocketFatalException {
// public WTFSocketKeepWordsException(String msg) {
// super(msg);
// }
//
// @Override
// public int getErrCode() {
// return 69;
// }
// }
//
// Path: src/wtf/socket/protocol/WTFSocketMsg.java
// public interface WTFSocketMsg {
//
// String getIoTag();
//
// void setIoTag(String ioTag);
//
// String getFrom();
//
// void setFrom(String from);
//
// String getTo();
//
// void setTo(String to);
//
// int getMsgId();
//
// void setMsgId(int msgId);
//
// int getMsgType();
//
// void setMsgType(int msgType);
//
// int getState();
//
// void setState(int state);
//
// void setConnectType(String connectType);
//
// String getConnectType();
//
// String getVersion();
//
// void setVersion(String version);
//
// Object getBody();
//
// <T> T getBody(Class<T> tClass);
//
// void setBody(Object body);
//
// WTFSocketMsg makeResponse();
// }
// Path: src/wtf/socket/secure/strategy/impl/WTFSocketSourceKeepWordsSecureStrategyImpl.java
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Component;
import wtf.socket.WTFSocketServer;
import wtf.socket.exception.WTFSocketException;
import wtf.socket.exception.fatal.WTFSocketKeepWordsException;
import wtf.socket.protocol.WTFSocketMsg;
package wtf.socket.secure.strategy.impl;
/**
* 是否使用了系统保留关键字
* <p>
* Created by ZFly on 2017/4/25.
*/
@Component
public final class WTFSocketSourceKeepWordsSecureStrategyImpl extends WTFSocketBaseSecureStrategyImpl {
@Override | public void check(WTFSocketServer context, WTFSocketMsg msg) throws WTFSocketException { |
ZhangFly/WTFSocket_Server_JAVA | src/wtf/socket/secure/strategy/impl/WTFSocketSourceKeepWordsSecureStrategyImpl.java | // Path: src/wtf/socket/WTFSocketServer.java
// public final class WTFSocketServer {
//
// /**
// * Spring 上下文
// */
// private ApplicationContext spring = new ClassPathXmlApplicationContext("spring.wtf.socket.xml");
//
// /**
// * 消息调度组件
// * 根据消息的头信息将消息投递到指定的目的地
// */
// @Resource()
// private WTFSocketScheduler scheduler;
//
// /**
// * 路由组件
// * 查询和记录连接的地址
// */
// @Resource
// private WTFSocketRouting routing;
//
// /**
// * 协议族组件
// * IO层收到数据后选择合适的解析器将数据解析为标准消息格式
// */
// @Resource
// private WTFSocketProtocolFamily protocolFamily;
//
// /**
// * 安全组件
// * 可用添加一些安全策略,如发送数据的授权许可等
// */
// @Resource
// private WTFSocketSecureDelegatesGroup secureDelegatesGroup;
//
// /**
// * 事件组组件
// * 包含了一些服务器的监听事件
// */
// @Resource
// private WTFSocketEventListenersGroup eventsGroup;
//
// /**
// * 服务器配置
// */
// private WTFSocketConfig config;
//
// public WTFSocketServer() {
// spring.getAutowireCapableBeanFactory().autowireBean(this);
// scheduler.setContext(this);
// routing.setContext(this);
// }
//
// public void run(WTFSocketConfig config) {
// this.config = config;
// scheduler.run();
// }
//
// public WTFSocketServer addController(WTFSocketController controller) {
// if (scheduler.getHandler() instanceof WTFSocketControllersGroup) {
// ((WTFSocketControllersGroup) scheduler.getHandler()).addController(controller);
// }
// return this;
// }
//
// public WTFSocketScheduler getScheduler() {
// return scheduler;
// }
//
// public WTFSocketProtocolFamily getProtocolFamily() {
// return protocolFamily;
// }
//
// public WTFSocketSecureDelegatesGroup getSecureDelegatesGroup() {
// return secureDelegatesGroup;
// }
//
// public WTFSocketRouting getRouting() {
// return routing;
// }
//
// public WTFSocketEventListenersGroup getEventsGroup() {
// return eventsGroup;
// }
//
// public WTFSocketConfig getConfig() {
// return config;
// }
//
// public void setScheduler(WTFSocketScheduler scheduler) {
// this.scheduler = scheduler;
// }
//
// public void setProtocolFamily(WTFSocketProtocolFamily protocolFamily) {
// this.protocolFamily = protocolFamily;
// }
//
// public void setSecureDelegatesGroup(WTFSocketSecureDelegatesGroup secureDelegatesGroup) {
// this.secureDelegatesGroup = secureDelegatesGroup;
// }
//
// public void setRouting(WTFSocketRouting routing) {
// this.routing = routing;
// }
//
// public void setEventsGroup(WTFSocketEventListenersGroup eventsGroup) {
// this.eventsGroup = eventsGroup;
// }
//
// public WTFSocketConfig setConfig() {
// return config;
// }
//
//
// public ApplicationContext getSpring() {
// return spring;
// }
// }
//
// Path: src/wtf/socket/exception/WTFSocketException.java
// public abstract class WTFSocketException extends Exception {
//
//
// public WTFSocketException(String msg) {
// super(msg);
// }
//
// public abstract int getErrCode();
//
// }
//
// Path: src/wtf/socket/exception/fatal/WTFSocketKeepWordsException.java
// public class WTFSocketKeepWordsException extends WTFSocketFatalException {
// public WTFSocketKeepWordsException(String msg) {
// super(msg);
// }
//
// @Override
// public int getErrCode() {
// return 69;
// }
// }
//
// Path: src/wtf/socket/protocol/WTFSocketMsg.java
// public interface WTFSocketMsg {
//
// String getIoTag();
//
// void setIoTag(String ioTag);
//
// String getFrom();
//
// void setFrom(String from);
//
// String getTo();
//
// void setTo(String to);
//
// int getMsgId();
//
// void setMsgId(int msgId);
//
// int getMsgType();
//
// void setMsgType(int msgType);
//
// int getState();
//
// void setState(int state);
//
// void setConnectType(String connectType);
//
// String getConnectType();
//
// String getVersion();
//
// void setVersion(String version);
//
// Object getBody();
//
// <T> T getBody(Class<T> tClass);
//
// void setBody(Object body);
//
// WTFSocketMsg makeResponse();
// }
| import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Component;
import wtf.socket.WTFSocketServer;
import wtf.socket.exception.WTFSocketException;
import wtf.socket.exception.fatal.WTFSocketKeepWordsException;
import wtf.socket.protocol.WTFSocketMsg; | package wtf.socket.secure.strategy.impl;
/**
* 是否使用了系统保留关键字
* <p>
* Created by ZFly on 2017/4/25.
*/
@Component
public final class WTFSocketSourceKeepWordsSecureStrategyImpl extends WTFSocketBaseSecureStrategyImpl {
@Override | // Path: src/wtf/socket/WTFSocketServer.java
// public final class WTFSocketServer {
//
// /**
// * Spring 上下文
// */
// private ApplicationContext spring = new ClassPathXmlApplicationContext("spring.wtf.socket.xml");
//
// /**
// * 消息调度组件
// * 根据消息的头信息将消息投递到指定的目的地
// */
// @Resource()
// private WTFSocketScheduler scheduler;
//
// /**
// * 路由组件
// * 查询和记录连接的地址
// */
// @Resource
// private WTFSocketRouting routing;
//
// /**
// * 协议族组件
// * IO层收到数据后选择合适的解析器将数据解析为标准消息格式
// */
// @Resource
// private WTFSocketProtocolFamily protocolFamily;
//
// /**
// * 安全组件
// * 可用添加一些安全策略,如发送数据的授权许可等
// */
// @Resource
// private WTFSocketSecureDelegatesGroup secureDelegatesGroup;
//
// /**
// * 事件组组件
// * 包含了一些服务器的监听事件
// */
// @Resource
// private WTFSocketEventListenersGroup eventsGroup;
//
// /**
// * 服务器配置
// */
// private WTFSocketConfig config;
//
// public WTFSocketServer() {
// spring.getAutowireCapableBeanFactory().autowireBean(this);
// scheduler.setContext(this);
// routing.setContext(this);
// }
//
// public void run(WTFSocketConfig config) {
// this.config = config;
// scheduler.run();
// }
//
// public WTFSocketServer addController(WTFSocketController controller) {
// if (scheduler.getHandler() instanceof WTFSocketControllersGroup) {
// ((WTFSocketControllersGroup) scheduler.getHandler()).addController(controller);
// }
// return this;
// }
//
// public WTFSocketScheduler getScheduler() {
// return scheduler;
// }
//
// public WTFSocketProtocolFamily getProtocolFamily() {
// return protocolFamily;
// }
//
// public WTFSocketSecureDelegatesGroup getSecureDelegatesGroup() {
// return secureDelegatesGroup;
// }
//
// public WTFSocketRouting getRouting() {
// return routing;
// }
//
// public WTFSocketEventListenersGroup getEventsGroup() {
// return eventsGroup;
// }
//
// public WTFSocketConfig getConfig() {
// return config;
// }
//
// public void setScheduler(WTFSocketScheduler scheduler) {
// this.scheduler = scheduler;
// }
//
// public void setProtocolFamily(WTFSocketProtocolFamily protocolFamily) {
// this.protocolFamily = protocolFamily;
// }
//
// public void setSecureDelegatesGroup(WTFSocketSecureDelegatesGroup secureDelegatesGroup) {
// this.secureDelegatesGroup = secureDelegatesGroup;
// }
//
// public void setRouting(WTFSocketRouting routing) {
// this.routing = routing;
// }
//
// public void setEventsGroup(WTFSocketEventListenersGroup eventsGroup) {
// this.eventsGroup = eventsGroup;
// }
//
// public WTFSocketConfig setConfig() {
// return config;
// }
//
//
// public ApplicationContext getSpring() {
// return spring;
// }
// }
//
// Path: src/wtf/socket/exception/WTFSocketException.java
// public abstract class WTFSocketException extends Exception {
//
//
// public WTFSocketException(String msg) {
// super(msg);
// }
//
// public abstract int getErrCode();
//
// }
//
// Path: src/wtf/socket/exception/fatal/WTFSocketKeepWordsException.java
// public class WTFSocketKeepWordsException extends WTFSocketFatalException {
// public WTFSocketKeepWordsException(String msg) {
// super(msg);
// }
//
// @Override
// public int getErrCode() {
// return 69;
// }
// }
//
// Path: src/wtf/socket/protocol/WTFSocketMsg.java
// public interface WTFSocketMsg {
//
// String getIoTag();
//
// void setIoTag(String ioTag);
//
// String getFrom();
//
// void setFrom(String from);
//
// String getTo();
//
// void setTo(String to);
//
// int getMsgId();
//
// void setMsgId(int msgId);
//
// int getMsgType();
//
// void setMsgType(int msgType);
//
// int getState();
//
// void setState(int state);
//
// void setConnectType(String connectType);
//
// String getConnectType();
//
// String getVersion();
//
// void setVersion(String version);
//
// Object getBody();
//
// <T> T getBody(Class<T> tClass);
//
// void setBody(Object body);
//
// WTFSocketMsg makeResponse();
// }
// Path: src/wtf/socket/secure/strategy/impl/WTFSocketSourceKeepWordsSecureStrategyImpl.java
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Component;
import wtf.socket.WTFSocketServer;
import wtf.socket.exception.WTFSocketException;
import wtf.socket.exception.fatal.WTFSocketKeepWordsException;
import wtf.socket.protocol.WTFSocketMsg;
package wtf.socket.secure.strategy.impl;
/**
* 是否使用了系统保留关键字
* <p>
* Created by ZFly on 2017/4/25.
*/
@Component
public final class WTFSocketSourceKeepWordsSecureStrategyImpl extends WTFSocketBaseSecureStrategyImpl {
@Override | public void check(WTFSocketServer context, WTFSocketMsg msg) throws WTFSocketException { |
ZhangFly/WTFSocket_Server_JAVA | src/wtf/socket/secure/strategy/impl/WTFSocketSourceKeepWordsSecureStrategyImpl.java | // Path: src/wtf/socket/WTFSocketServer.java
// public final class WTFSocketServer {
//
// /**
// * Spring 上下文
// */
// private ApplicationContext spring = new ClassPathXmlApplicationContext("spring.wtf.socket.xml");
//
// /**
// * 消息调度组件
// * 根据消息的头信息将消息投递到指定的目的地
// */
// @Resource()
// private WTFSocketScheduler scheduler;
//
// /**
// * 路由组件
// * 查询和记录连接的地址
// */
// @Resource
// private WTFSocketRouting routing;
//
// /**
// * 协议族组件
// * IO层收到数据后选择合适的解析器将数据解析为标准消息格式
// */
// @Resource
// private WTFSocketProtocolFamily protocolFamily;
//
// /**
// * 安全组件
// * 可用添加一些安全策略,如发送数据的授权许可等
// */
// @Resource
// private WTFSocketSecureDelegatesGroup secureDelegatesGroup;
//
// /**
// * 事件组组件
// * 包含了一些服务器的监听事件
// */
// @Resource
// private WTFSocketEventListenersGroup eventsGroup;
//
// /**
// * 服务器配置
// */
// private WTFSocketConfig config;
//
// public WTFSocketServer() {
// spring.getAutowireCapableBeanFactory().autowireBean(this);
// scheduler.setContext(this);
// routing.setContext(this);
// }
//
// public void run(WTFSocketConfig config) {
// this.config = config;
// scheduler.run();
// }
//
// public WTFSocketServer addController(WTFSocketController controller) {
// if (scheduler.getHandler() instanceof WTFSocketControllersGroup) {
// ((WTFSocketControllersGroup) scheduler.getHandler()).addController(controller);
// }
// return this;
// }
//
// public WTFSocketScheduler getScheduler() {
// return scheduler;
// }
//
// public WTFSocketProtocolFamily getProtocolFamily() {
// return protocolFamily;
// }
//
// public WTFSocketSecureDelegatesGroup getSecureDelegatesGroup() {
// return secureDelegatesGroup;
// }
//
// public WTFSocketRouting getRouting() {
// return routing;
// }
//
// public WTFSocketEventListenersGroup getEventsGroup() {
// return eventsGroup;
// }
//
// public WTFSocketConfig getConfig() {
// return config;
// }
//
// public void setScheduler(WTFSocketScheduler scheduler) {
// this.scheduler = scheduler;
// }
//
// public void setProtocolFamily(WTFSocketProtocolFamily protocolFamily) {
// this.protocolFamily = protocolFamily;
// }
//
// public void setSecureDelegatesGroup(WTFSocketSecureDelegatesGroup secureDelegatesGroup) {
// this.secureDelegatesGroup = secureDelegatesGroup;
// }
//
// public void setRouting(WTFSocketRouting routing) {
// this.routing = routing;
// }
//
// public void setEventsGroup(WTFSocketEventListenersGroup eventsGroup) {
// this.eventsGroup = eventsGroup;
// }
//
// public WTFSocketConfig setConfig() {
// return config;
// }
//
//
// public ApplicationContext getSpring() {
// return spring;
// }
// }
//
// Path: src/wtf/socket/exception/WTFSocketException.java
// public abstract class WTFSocketException extends Exception {
//
//
// public WTFSocketException(String msg) {
// super(msg);
// }
//
// public abstract int getErrCode();
//
// }
//
// Path: src/wtf/socket/exception/fatal/WTFSocketKeepWordsException.java
// public class WTFSocketKeepWordsException extends WTFSocketFatalException {
// public WTFSocketKeepWordsException(String msg) {
// super(msg);
// }
//
// @Override
// public int getErrCode() {
// return 69;
// }
// }
//
// Path: src/wtf/socket/protocol/WTFSocketMsg.java
// public interface WTFSocketMsg {
//
// String getIoTag();
//
// void setIoTag(String ioTag);
//
// String getFrom();
//
// void setFrom(String from);
//
// String getTo();
//
// void setTo(String to);
//
// int getMsgId();
//
// void setMsgId(int msgId);
//
// int getMsgType();
//
// void setMsgType(int msgType);
//
// int getState();
//
// void setState(int state);
//
// void setConnectType(String connectType);
//
// String getConnectType();
//
// String getVersion();
//
// void setVersion(String version);
//
// Object getBody();
//
// <T> T getBody(Class<T> tClass);
//
// void setBody(Object body);
//
// WTFSocketMsg makeResponse();
// }
| import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Component;
import wtf.socket.WTFSocketServer;
import wtf.socket.exception.WTFSocketException;
import wtf.socket.exception.fatal.WTFSocketKeepWordsException;
import wtf.socket.protocol.WTFSocketMsg; | package wtf.socket.secure.strategy.impl;
/**
* 是否使用了系统保留关键字
* <p>
* Created by ZFly on 2017/4/25.
*/
@Component
public final class WTFSocketSourceKeepWordsSecureStrategyImpl extends WTFSocketBaseSecureStrategyImpl {
@Override
public void check(WTFSocketServer context, WTFSocketMsg msg) throws WTFSocketException {
if (StringUtils.equals("server", msg.getFrom())) | // Path: src/wtf/socket/WTFSocketServer.java
// public final class WTFSocketServer {
//
// /**
// * Spring 上下文
// */
// private ApplicationContext spring = new ClassPathXmlApplicationContext("spring.wtf.socket.xml");
//
// /**
// * 消息调度组件
// * 根据消息的头信息将消息投递到指定的目的地
// */
// @Resource()
// private WTFSocketScheduler scheduler;
//
// /**
// * 路由组件
// * 查询和记录连接的地址
// */
// @Resource
// private WTFSocketRouting routing;
//
// /**
// * 协议族组件
// * IO层收到数据后选择合适的解析器将数据解析为标准消息格式
// */
// @Resource
// private WTFSocketProtocolFamily protocolFamily;
//
// /**
// * 安全组件
// * 可用添加一些安全策略,如发送数据的授权许可等
// */
// @Resource
// private WTFSocketSecureDelegatesGroup secureDelegatesGroup;
//
// /**
// * 事件组组件
// * 包含了一些服务器的监听事件
// */
// @Resource
// private WTFSocketEventListenersGroup eventsGroup;
//
// /**
// * 服务器配置
// */
// private WTFSocketConfig config;
//
// public WTFSocketServer() {
// spring.getAutowireCapableBeanFactory().autowireBean(this);
// scheduler.setContext(this);
// routing.setContext(this);
// }
//
// public void run(WTFSocketConfig config) {
// this.config = config;
// scheduler.run();
// }
//
// public WTFSocketServer addController(WTFSocketController controller) {
// if (scheduler.getHandler() instanceof WTFSocketControllersGroup) {
// ((WTFSocketControllersGroup) scheduler.getHandler()).addController(controller);
// }
// return this;
// }
//
// public WTFSocketScheduler getScheduler() {
// return scheduler;
// }
//
// public WTFSocketProtocolFamily getProtocolFamily() {
// return protocolFamily;
// }
//
// public WTFSocketSecureDelegatesGroup getSecureDelegatesGroup() {
// return secureDelegatesGroup;
// }
//
// public WTFSocketRouting getRouting() {
// return routing;
// }
//
// public WTFSocketEventListenersGroup getEventsGroup() {
// return eventsGroup;
// }
//
// public WTFSocketConfig getConfig() {
// return config;
// }
//
// public void setScheduler(WTFSocketScheduler scheduler) {
// this.scheduler = scheduler;
// }
//
// public void setProtocolFamily(WTFSocketProtocolFamily protocolFamily) {
// this.protocolFamily = protocolFamily;
// }
//
// public void setSecureDelegatesGroup(WTFSocketSecureDelegatesGroup secureDelegatesGroup) {
// this.secureDelegatesGroup = secureDelegatesGroup;
// }
//
// public void setRouting(WTFSocketRouting routing) {
// this.routing = routing;
// }
//
// public void setEventsGroup(WTFSocketEventListenersGroup eventsGroup) {
// this.eventsGroup = eventsGroup;
// }
//
// public WTFSocketConfig setConfig() {
// return config;
// }
//
//
// public ApplicationContext getSpring() {
// return spring;
// }
// }
//
// Path: src/wtf/socket/exception/WTFSocketException.java
// public abstract class WTFSocketException extends Exception {
//
//
// public WTFSocketException(String msg) {
// super(msg);
// }
//
// public abstract int getErrCode();
//
// }
//
// Path: src/wtf/socket/exception/fatal/WTFSocketKeepWordsException.java
// public class WTFSocketKeepWordsException extends WTFSocketFatalException {
// public WTFSocketKeepWordsException(String msg) {
// super(msg);
// }
//
// @Override
// public int getErrCode() {
// return 69;
// }
// }
//
// Path: src/wtf/socket/protocol/WTFSocketMsg.java
// public interface WTFSocketMsg {
//
// String getIoTag();
//
// void setIoTag(String ioTag);
//
// String getFrom();
//
// void setFrom(String from);
//
// String getTo();
//
// void setTo(String to);
//
// int getMsgId();
//
// void setMsgId(int msgId);
//
// int getMsgType();
//
// void setMsgType(int msgType);
//
// int getState();
//
// void setState(int state);
//
// void setConnectType(String connectType);
//
// String getConnectType();
//
// String getVersion();
//
// void setVersion(String version);
//
// Object getBody();
//
// <T> T getBody(Class<T> tClass);
//
// void setBody(Object body);
//
// WTFSocketMsg makeResponse();
// }
// Path: src/wtf/socket/secure/strategy/impl/WTFSocketSourceKeepWordsSecureStrategyImpl.java
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Component;
import wtf.socket.WTFSocketServer;
import wtf.socket.exception.WTFSocketException;
import wtf.socket.exception.fatal.WTFSocketKeepWordsException;
import wtf.socket.protocol.WTFSocketMsg;
package wtf.socket.secure.strategy.impl;
/**
* 是否使用了系统保留关键字
* <p>
* Created by ZFly on 2017/4/25.
*/
@Component
public final class WTFSocketSourceKeepWordsSecureStrategyImpl extends WTFSocketBaseSecureStrategyImpl {
@Override
public void check(WTFSocketServer context, WTFSocketMsg msg) throws WTFSocketException {
if (StringUtils.equals("server", msg.getFrom())) | throw new WTFSocketKeepWordsException("Source can not be [server]"); |
ZhangFly/WTFSocket_Server_JAVA | src/wtf/socket/secure/strategy/impl/WTFSocketTargetKeepWordsSecureStrategyImpl.java | // Path: src/wtf/socket/WTFSocketServer.java
// public final class WTFSocketServer {
//
// /**
// * Spring 上下文
// */
// private ApplicationContext spring = new ClassPathXmlApplicationContext("spring.wtf.socket.xml");
//
// /**
// * 消息调度组件
// * 根据消息的头信息将消息投递到指定的目的地
// */
// @Resource()
// private WTFSocketScheduler scheduler;
//
// /**
// * 路由组件
// * 查询和记录连接的地址
// */
// @Resource
// private WTFSocketRouting routing;
//
// /**
// * 协议族组件
// * IO层收到数据后选择合适的解析器将数据解析为标准消息格式
// */
// @Resource
// private WTFSocketProtocolFamily protocolFamily;
//
// /**
// * 安全组件
// * 可用添加一些安全策略,如发送数据的授权许可等
// */
// @Resource
// private WTFSocketSecureDelegatesGroup secureDelegatesGroup;
//
// /**
// * 事件组组件
// * 包含了一些服务器的监听事件
// */
// @Resource
// private WTFSocketEventListenersGroup eventsGroup;
//
// /**
// * 服务器配置
// */
// private WTFSocketConfig config;
//
// public WTFSocketServer() {
// spring.getAutowireCapableBeanFactory().autowireBean(this);
// scheduler.setContext(this);
// routing.setContext(this);
// }
//
// public void run(WTFSocketConfig config) {
// this.config = config;
// scheduler.run();
// }
//
// public WTFSocketServer addController(WTFSocketController controller) {
// if (scheduler.getHandler() instanceof WTFSocketControllersGroup) {
// ((WTFSocketControllersGroup) scheduler.getHandler()).addController(controller);
// }
// return this;
// }
//
// public WTFSocketScheduler getScheduler() {
// return scheduler;
// }
//
// public WTFSocketProtocolFamily getProtocolFamily() {
// return protocolFamily;
// }
//
// public WTFSocketSecureDelegatesGroup getSecureDelegatesGroup() {
// return secureDelegatesGroup;
// }
//
// public WTFSocketRouting getRouting() {
// return routing;
// }
//
// public WTFSocketEventListenersGroup getEventsGroup() {
// return eventsGroup;
// }
//
// public WTFSocketConfig getConfig() {
// return config;
// }
//
// public void setScheduler(WTFSocketScheduler scheduler) {
// this.scheduler = scheduler;
// }
//
// public void setProtocolFamily(WTFSocketProtocolFamily protocolFamily) {
// this.protocolFamily = protocolFamily;
// }
//
// public void setSecureDelegatesGroup(WTFSocketSecureDelegatesGroup secureDelegatesGroup) {
// this.secureDelegatesGroup = secureDelegatesGroup;
// }
//
// public void setRouting(WTFSocketRouting routing) {
// this.routing = routing;
// }
//
// public void setEventsGroup(WTFSocketEventListenersGroup eventsGroup) {
// this.eventsGroup = eventsGroup;
// }
//
// public WTFSocketConfig setConfig() {
// return config;
// }
//
//
// public ApplicationContext getSpring() {
// return spring;
// }
// }
//
// Path: src/wtf/socket/exception/WTFSocketException.java
// public abstract class WTFSocketException extends Exception {
//
//
// public WTFSocketException(String msg) {
// super(msg);
// }
//
// public abstract int getErrCode();
//
// }
//
// Path: src/wtf/socket/exception/fatal/WTFSocketKeepWordsException.java
// public class WTFSocketKeepWordsException extends WTFSocketFatalException {
// public WTFSocketKeepWordsException(String msg) {
// super(msg);
// }
//
// @Override
// public int getErrCode() {
// return 69;
// }
// }
//
// Path: src/wtf/socket/protocol/WTFSocketMsg.java
// public interface WTFSocketMsg {
//
// String getIoTag();
//
// void setIoTag(String ioTag);
//
// String getFrom();
//
// void setFrom(String from);
//
// String getTo();
//
// void setTo(String to);
//
// int getMsgId();
//
// void setMsgId(int msgId);
//
// int getMsgType();
//
// void setMsgType(int msgType);
//
// int getState();
//
// void setState(int state);
//
// void setConnectType(String connectType);
//
// String getConnectType();
//
// String getVersion();
//
// void setVersion(String version);
//
// Object getBody();
//
// <T> T getBody(Class<T> tClass);
//
// void setBody(Object body);
//
// WTFSocketMsg makeResponse();
// }
| import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Component;
import wtf.socket.WTFSocketServer;
import wtf.socket.exception.WTFSocketException;
import wtf.socket.exception.fatal.WTFSocketKeepWordsException;
import wtf.socket.protocol.WTFSocketMsg; | package wtf.socket.secure.strategy.impl;
/**
* 是否使用了系统保留关键字
* <p>
* Created by ZFly on 2017/4/25.
*/
@Component
public final class WTFSocketTargetKeepWordsSecureStrategyImpl extends WTFSocketBaseSecureStrategyImpl {
@Override | // Path: src/wtf/socket/WTFSocketServer.java
// public final class WTFSocketServer {
//
// /**
// * Spring 上下文
// */
// private ApplicationContext spring = new ClassPathXmlApplicationContext("spring.wtf.socket.xml");
//
// /**
// * 消息调度组件
// * 根据消息的头信息将消息投递到指定的目的地
// */
// @Resource()
// private WTFSocketScheduler scheduler;
//
// /**
// * 路由组件
// * 查询和记录连接的地址
// */
// @Resource
// private WTFSocketRouting routing;
//
// /**
// * 协议族组件
// * IO层收到数据后选择合适的解析器将数据解析为标准消息格式
// */
// @Resource
// private WTFSocketProtocolFamily protocolFamily;
//
// /**
// * 安全组件
// * 可用添加一些安全策略,如发送数据的授权许可等
// */
// @Resource
// private WTFSocketSecureDelegatesGroup secureDelegatesGroup;
//
// /**
// * 事件组组件
// * 包含了一些服务器的监听事件
// */
// @Resource
// private WTFSocketEventListenersGroup eventsGroup;
//
// /**
// * 服务器配置
// */
// private WTFSocketConfig config;
//
// public WTFSocketServer() {
// spring.getAutowireCapableBeanFactory().autowireBean(this);
// scheduler.setContext(this);
// routing.setContext(this);
// }
//
// public void run(WTFSocketConfig config) {
// this.config = config;
// scheduler.run();
// }
//
// public WTFSocketServer addController(WTFSocketController controller) {
// if (scheduler.getHandler() instanceof WTFSocketControllersGroup) {
// ((WTFSocketControllersGroup) scheduler.getHandler()).addController(controller);
// }
// return this;
// }
//
// public WTFSocketScheduler getScheduler() {
// return scheduler;
// }
//
// public WTFSocketProtocolFamily getProtocolFamily() {
// return protocolFamily;
// }
//
// public WTFSocketSecureDelegatesGroup getSecureDelegatesGroup() {
// return secureDelegatesGroup;
// }
//
// public WTFSocketRouting getRouting() {
// return routing;
// }
//
// public WTFSocketEventListenersGroup getEventsGroup() {
// return eventsGroup;
// }
//
// public WTFSocketConfig getConfig() {
// return config;
// }
//
// public void setScheduler(WTFSocketScheduler scheduler) {
// this.scheduler = scheduler;
// }
//
// public void setProtocolFamily(WTFSocketProtocolFamily protocolFamily) {
// this.protocolFamily = protocolFamily;
// }
//
// public void setSecureDelegatesGroup(WTFSocketSecureDelegatesGroup secureDelegatesGroup) {
// this.secureDelegatesGroup = secureDelegatesGroup;
// }
//
// public void setRouting(WTFSocketRouting routing) {
// this.routing = routing;
// }
//
// public void setEventsGroup(WTFSocketEventListenersGroup eventsGroup) {
// this.eventsGroup = eventsGroup;
// }
//
// public WTFSocketConfig setConfig() {
// return config;
// }
//
//
// public ApplicationContext getSpring() {
// return spring;
// }
// }
//
// Path: src/wtf/socket/exception/WTFSocketException.java
// public abstract class WTFSocketException extends Exception {
//
//
// public WTFSocketException(String msg) {
// super(msg);
// }
//
// public abstract int getErrCode();
//
// }
//
// Path: src/wtf/socket/exception/fatal/WTFSocketKeepWordsException.java
// public class WTFSocketKeepWordsException extends WTFSocketFatalException {
// public WTFSocketKeepWordsException(String msg) {
// super(msg);
// }
//
// @Override
// public int getErrCode() {
// return 69;
// }
// }
//
// Path: src/wtf/socket/protocol/WTFSocketMsg.java
// public interface WTFSocketMsg {
//
// String getIoTag();
//
// void setIoTag(String ioTag);
//
// String getFrom();
//
// void setFrom(String from);
//
// String getTo();
//
// void setTo(String to);
//
// int getMsgId();
//
// void setMsgId(int msgId);
//
// int getMsgType();
//
// void setMsgType(int msgType);
//
// int getState();
//
// void setState(int state);
//
// void setConnectType(String connectType);
//
// String getConnectType();
//
// String getVersion();
//
// void setVersion(String version);
//
// Object getBody();
//
// <T> T getBody(Class<T> tClass);
//
// void setBody(Object body);
//
// WTFSocketMsg makeResponse();
// }
// Path: src/wtf/socket/secure/strategy/impl/WTFSocketTargetKeepWordsSecureStrategyImpl.java
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Component;
import wtf.socket.WTFSocketServer;
import wtf.socket.exception.WTFSocketException;
import wtf.socket.exception.fatal.WTFSocketKeepWordsException;
import wtf.socket.protocol.WTFSocketMsg;
package wtf.socket.secure.strategy.impl;
/**
* 是否使用了系统保留关键字
* <p>
* Created by ZFly on 2017/4/25.
*/
@Component
public final class WTFSocketTargetKeepWordsSecureStrategyImpl extends WTFSocketBaseSecureStrategyImpl {
@Override | public void check(WTFSocketServer context, WTFSocketMsg msg) throws WTFSocketException { |
ZhangFly/WTFSocket_Server_JAVA | src/wtf/socket/secure/strategy/impl/WTFSocketTargetKeepWordsSecureStrategyImpl.java | // Path: src/wtf/socket/WTFSocketServer.java
// public final class WTFSocketServer {
//
// /**
// * Spring 上下文
// */
// private ApplicationContext spring = new ClassPathXmlApplicationContext("spring.wtf.socket.xml");
//
// /**
// * 消息调度组件
// * 根据消息的头信息将消息投递到指定的目的地
// */
// @Resource()
// private WTFSocketScheduler scheduler;
//
// /**
// * 路由组件
// * 查询和记录连接的地址
// */
// @Resource
// private WTFSocketRouting routing;
//
// /**
// * 协议族组件
// * IO层收到数据后选择合适的解析器将数据解析为标准消息格式
// */
// @Resource
// private WTFSocketProtocolFamily protocolFamily;
//
// /**
// * 安全组件
// * 可用添加一些安全策略,如发送数据的授权许可等
// */
// @Resource
// private WTFSocketSecureDelegatesGroup secureDelegatesGroup;
//
// /**
// * 事件组组件
// * 包含了一些服务器的监听事件
// */
// @Resource
// private WTFSocketEventListenersGroup eventsGroup;
//
// /**
// * 服务器配置
// */
// private WTFSocketConfig config;
//
// public WTFSocketServer() {
// spring.getAutowireCapableBeanFactory().autowireBean(this);
// scheduler.setContext(this);
// routing.setContext(this);
// }
//
// public void run(WTFSocketConfig config) {
// this.config = config;
// scheduler.run();
// }
//
// public WTFSocketServer addController(WTFSocketController controller) {
// if (scheduler.getHandler() instanceof WTFSocketControllersGroup) {
// ((WTFSocketControllersGroup) scheduler.getHandler()).addController(controller);
// }
// return this;
// }
//
// public WTFSocketScheduler getScheduler() {
// return scheduler;
// }
//
// public WTFSocketProtocolFamily getProtocolFamily() {
// return protocolFamily;
// }
//
// public WTFSocketSecureDelegatesGroup getSecureDelegatesGroup() {
// return secureDelegatesGroup;
// }
//
// public WTFSocketRouting getRouting() {
// return routing;
// }
//
// public WTFSocketEventListenersGroup getEventsGroup() {
// return eventsGroup;
// }
//
// public WTFSocketConfig getConfig() {
// return config;
// }
//
// public void setScheduler(WTFSocketScheduler scheduler) {
// this.scheduler = scheduler;
// }
//
// public void setProtocolFamily(WTFSocketProtocolFamily protocolFamily) {
// this.protocolFamily = protocolFamily;
// }
//
// public void setSecureDelegatesGroup(WTFSocketSecureDelegatesGroup secureDelegatesGroup) {
// this.secureDelegatesGroup = secureDelegatesGroup;
// }
//
// public void setRouting(WTFSocketRouting routing) {
// this.routing = routing;
// }
//
// public void setEventsGroup(WTFSocketEventListenersGroup eventsGroup) {
// this.eventsGroup = eventsGroup;
// }
//
// public WTFSocketConfig setConfig() {
// return config;
// }
//
//
// public ApplicationContext getSpring() {
// return spring;
// }
// }
//
// Path: src/wtf/socket/exception/WTFSocketException.java
// public abstract class WTFSocketException extends Exception {
//
//
// public WTFSocketException(String msg) {
// super(msg);
// }
//
// public abstract int getErrCode();
//
// }
//
// Path: src/wtf/socket/exception/fatal/WTFSocketKeepWordsException.java
// public class WTFSocketKeepWordsException extends WTFSocketFatalException {
// public WTFSocketKeepWordsException(String msg) {
// super(msg);
// }
//
// @Override
// public int getErrCode() {
// return 69;
// }
// }
//
// Path: src/wtf/socket/protocol/WTFSocketMsg.java
// public interface WTFSocketMsg {
//
// String getIoTag();
//
// void setIoTag(String ioTag);
//
// String getFrom();
//
// void setFrom(String from);
//
// String getTo();
//
// void setTo(String to);
//
// int getMsgId();
//
// void setMsgId(int msgId);
//
// int getMsgType();
//
// void setMsgType(int msgType);
//
// int getState();
//
// void setState(int state);
//
// void setConnectType(String connectType);
//
// String getConnectType();
//
// String getVersion();
//
// void setVersion(String version);
//
// Object getBody();
//
// <T> T getBody(Class<T> tClass);
//
// void setBody(Object body);
//
// WTFSocketMsg makeResponse();
// }
| import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Component;
import wtf.socket.WTFSocketServer;
import wtf.socket.exception.WTFSocketException;
import wtf.socket.exception.fatal.WTFSocketKeepWordsException;
import wtf.socket.protocol.WTFSocketMsg; | package wtf.socket.secure.strategy.impl;
/**
* 是否使用了系统保留关键字
* <p>
* Created by ZFly on 2017/4/25.
*/
@Component
public final class WTFSocketTargetKeepWordsSecureStrategyImpl extends WTFSocketBaseSecureStrategyImpl {
@Override | // Path: src/wtf/socket/WTFSocketServer.java
// public final class WTFSocketServer {
//
// /**
// * Spring 上下文
// */
// private ApplicationContext spring = new ClassPathXmlApplicationContext("spring.wtf.socket.xml");
//
// /**
// * 消息调度组件
// * 根据消息的头信息将消息投递到指定的目的地
// */
// @Resource()
// private WTFSocketScheduler scheduler;
//
// /**
// * 路由组件
// * 查询和记录连接的地址
// */
// @Resource
// private WTFSocketRouting routing;
//
// /**
// * 协议族组件
// * IO层收到数据后选择合适的解析器将数据解析为标准消息格式
// */
// @Resource
// private WTFSocketProtocolFamily protocolFamily;
//
// /**
// * 安全组件
// * 可用添加一些安全策略,如发送数据的授权许可等
// */
// @Resource
// private WTFSocketSecureDelegatesGroup secureDelegatesGroup;
//
// /**
// * 事件组组件
// * 包含了一些服务器的监听事件
// */
// @Resource
// private WTFSocketEventListenersGroup eventsGroup;
//
// /**
// * 服务器配置
// */
// private WTFSocketConfig config;
//
// public WTFSocketServer() {
// spring.getAutowireCapableBeanFactory().autowireBean(this);
// scheduler.setContext(this);
// routing.setContext(this);
// }
//
// public void run(WTFSocketConfig config) {
// this.config = config;
// scheduler.run();
// }
//
// public WTFSocketServer addController(WTFSocketController controller) {
// if (scheduler.getHandler() instanceof WTFSocketControllersGroup) {
// ((WTFSocketControllersGroup) scheduler.getHandler()).addController(controller);
// }
// return this;
// }
//
// public WTFSocketScheduler getScheduler() {
// return scheduler;
// }
//
// public WTFSocketProtocolFamily getProtocolFamily() {
// return protocolFamily;
// }
//
// public WTFSocketSecureDelegatesGroup getSecureDelegatesGroup() {
// return secureDelegatesGroup;
// }
//
// public WTFSocketRouting getRouting() {
// return routing;
// }
//
// public WTFSocketEventListenersGroup getEventsGroup() {
// return eventsGroup;
// }
//
// public WTFSocketConfig getConfig() {
// return config;
// }
//
// public void setScheduler(WTFSocketScheduler scheduler) {
// this.scheduler = scheduler;
// }
//
// public void setProtocolFamily(WTFSocketProtocolFamily protocolFamily) {
// this.protocolFamily = protocolFamily;
// }
//
// public void setSecureDelegatesGroup(WTFSocketSecureDelegatesGroup secureDelegatesGroup) {
// this.secureDelegatesGroup = secureDelegatesGroup;
// }
//
// public void setRouting(WTFSocketRouting routing) {
// this.routing = routing;
// }
//
// public void setEventsGroup(WTFSocketEventListenersGroup eventsGroup) {
// this.eventsGroup = eventsGroup;
// }
//
// public WTFSocketConfig setConfig() {
// return config;
// }
//
//
// public ApplicationContext getSpring() {
// return spring;
// }
// }
//
// Path: src/wtf/socket/exception/WTFSocketException.java
// public abstract class WTFSocketException extends Exception {
//
//
// public WTFSocketException(String msg) {
// super(msg);
// }
//
// public abstract int getErrCode();
//
// }
//
// Path: src/wtf/socket/exception/fatal/WTFSocketKeepWordsException.java
// public class WTFSocketKeepWordsException extends WTFSocketFatalException {
// public WTFSocketKeepWordsException(String msg) {
// super(msg);
// }
//
// @Override
// public int getErrCode() {
// return 69;
// }
// }
//
// Path: src/wtf/socket/protocol/WTFSocketMsg.java
// public interface WTFSocketMsg {
//
// String getIoTag();
//
// void setIoTag(String ioTag);
//
// String getFrom();
//
// void setFrom(String from);
//
// String getTo();
//
// void setTo(String to);
//
// int getMsgId();
//
// void setMsgId(int msgId);
//
// int getMsgType();
//
// void setMsgType(int msgType);
//
// int getState();
//
// void setState(int state);
//
// void setConnectType(String connectType);
//
// String getConnectType();
//
// String getVersion();
//
// void setVersion(String version);
//
// Object getBody();
//
// <T> T getBody(Class<T> tClass);
//
// void setBody(Object body);
//
// WTFSocketMsg makeResponse();
// }
// Path: src/wtf/socket/secure/strategy/impl/WTFSocketTargetKeepWordsSecureStrategyImpl.java
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Component;
import wtf.socket.WTFSocketServer;
import wtf.socket.exception.WTFSocketException;
import wtf.socket.exception.fatal.WTFSocketKeepWordsException;
import wtf.socket.protocol.WTFSocketMsg;
package wtf.socket.secure.strategy.impl;
/**
* 是否使用了系统保留关键字
* <p>
* Created by ZFly on 2017/4/25.
*/
@Component
public final class WTFSocketTargetKeepWordsSecureStrategyImpl extends WTFSocketBaseSecureStrategyImpl {
@Override | public void check(WTFSocketServer context, WTFSocketMsg msg) throws WTFSocketException { |
ZhangFly/WTFSocket_Server_JAVA | src/wtf/socket/secure/strategy/impl/WTFSocketTargetKeepWordsSecureStrategyImpl.java | // Path: src/wtf/socket/WTFSocketServer.java
// public final class WTFSocketServer {
//
// /**
// * Spring 上下文
// */
// private ApplicationContext spring = new ClassPathXmlApplicationContext("spring.wtf.socket.xml");
//
// /**
// * 消息调度组件
// * 根据消息的头信息将消息投递到指定的目的地
// */
// @Resource()
// private WTFSocketScheduler scheduler;
//
// /**
// * 路由组件
// * 查询和记录连接的地址
// */
// @Resource
// private WTFSocketRouting routing;
//
// /**
// * 协议族组件
// * IO层收到数据后选择合适的解析器将数据解析为标准消息格式
// */
// @Resource
// private WTFSocketProtocolFamily protocolFamily;
//
// /**
// * 安全组件
// * 可用添加一些安全策略,如发送数据的授权许可等
// */
// @Resource
// private WTFSocketSecureDelegatesGroup secureDelegatesGroup;
//
// /**
// * 事件组组件
// * 包含了一些服务器的监听事件
// */
// @Resource
// private WTFSocketEventListenersGroup eventsGroup;
//
// /**
// * 服务器配置
// */
// private WTFSocketConfig config;
//
// public WTFSocketServer() {
// spring.getAutowireCapableBeanFactory().autowireBean(this);
// scheduler.setContext(this);
// routing.setContext(this);
// }
//
// public void run(WTFSocketConfig config) {
// this.config = config;
// scheduler.run();
// }
//
// public WTFSocketServer addController(WTFSocketController controller) {
// if (scheduler.getHandler() instanceof WTFSocketControllersGroup) {
// ((WTFSocketControllersGroup) scheduler.getHandler()).addController(controller);
// }
// return this;
// }
//
// public WTFSocketScheduler getScheduler() {
// return scheduler;
// }
//
// public WTFSocketProtocolFamily getProtocolFamily() {
// return protocolFamily;
// }
//
// public WTFSocketSecureDelegatesGroup getSecureDelegatesGroup() {
// return secureDelegatesGroup;
// }
//
// public WTFSocketRouting getRouting() {
// return routing;
// }
//
// public WTFSocketEventListenersGroup getEventsGroup() {
// return eventsGroup;
// }
//
// public WTFSocketConfig getConfig() {
// return config;
// }
//
// public void setScheduler(WTFSocketScheduler scheduler) {
// this.scheduler = scheduler;
// }
//
// public void setProtocolFamily(WTFSocketProtocolFamily protocolFamily) {
// this.protocolFamily = protocolFamily;
// }
//
// public void setSecureDelegatesGroup(WTFSocketSecureDelegatesGroup secureDelegatesGroup) {
// this.secureDelegatesGroup = secureDelegatesGroup;
// }
//
// public void setRouting(WTFSocketRouting routing) {
// this.routing = routing;
// }
//
// public void setEventsGroup(WTFSocketEventListenersGroup eventsGroup) {
// this.eventsGroup = eventsGroup;
// }
//
// public WTFSocketConfig setConfig() {
// return config;
// }
//
//
// public ApplicationContext getSpring() {
// return spring;
// }
// }
//
// Path: src/wtf/socket/exception/WTFSocketException.java
// public abstract class WTFSocketException extends Exception {
//
//
// public WTFSocketException(String msg) {
// super(msg);
// }
//
// public abstract int getErrCode();
//
// }
//
// Path: src/wtf/socket/exception/fatal/WTFSocketKeepWordsException.java
// public class WTFSocketKeepWordsException extends WTFSocketFatalException {
// public WTFSocketKeepWordsException(String msg) {
// super(msg);
// }
//
// @Override
// public int getErrCode() {
// return 69;
// }
// }
//
// Path: src/wtf/socket/protocol/WTFSocketMsg.java
// public interface WTFSocketMsg {
//
// String getIoTag();
//
// void setIoTag(String ioTag);
//
// String getFrom();
//
// void setFrom(String from);
//
// String getTo();
//
// void setTo(String to);
//
// int getMsgId();
//
// void setMsgId(int msgId);
//
// int getMsgType();
//
// void setMsgType(int msgType);
//
// int getState();
//
// void setState(int state);
//
// void setConnectType(String connectType);
//
// String getConnectType();
//
// String getVersion();
//
// void setVersion(String version);
//
// Object getBody();
//
// <T> T getBody(Class<T> tClass);
//
// void setBody(Object body);
//
// WTFSocketMsg makeResponse();
// }
| import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Component;
import wtf.socket.WTFSocketServer;
import wtf.socket.exception.WTFSocketException;
import wtf.socket.exception.fatal.WTFSocketKeepWordsException;
import wtf.socket.protocol.WTFSocketMsg; | package wtf.socket.secure.strategy.impl;
/**
* 是否使用了系统保留关键字
* <p>
* Created by ZFly on 2017/4/25.
*/
@Component
public final class WTFSocketTargetKeepWordsSecureStrategyImpl extends WTFSocketBaseSecureStrategyImpl {
@Override | // Path: src/wtf/socket/WTFSocketServer.java
// public final class WTFSocketServer {
//
// /**
// * Spring 上下文
// */
// private ApplicationContext spring = new ClassPathXmlApplicationContext("spring.wtf.socket.xml");
//
// /**
// * 消息调度组件
// * 根据消息的头信息将消息投递到指定的目的地
// */
// @Resource()
// private WTFSocketScheduler scheduler;
//
// /**
// * 路由组件
// * 查询和记录连接的地址
// */
// @Resource
// private WTFSocketRouting routing;
//
// /**
// * 协议族组件
// * IO层收到数据后选择合适的解析器将数据解析为标准消息格式
// */
// @Resource
// private WTFSocketProtocolFamily protocolFamily;
//
// /**
// * 安全组件
// * 可用添加一些安全策略,如发送数据的授权许可等
// */
// @Resource
// private WTFSocketSecureDelegatesGroup secureDelegatesGroup;
//
// /**
// * 事件组组件
// * 包含了一些服务器的监听事件
// */
// @Resource
// private WTFSocketEventListenersGroup eventsGroup;
//
// /**
// * 服务器配置
// */
// private WTFSocketConfig config;
//
// public WTFSocketServer() {
// spring.getAutowireCapableBeanFactory().autowireBean(this);
// scheduler.setContext(this);
// routing.setContext(this);
// }
//
// public void run(WTFSocketConfig config) {
// this.config = config;
// scheduler.run();
// }
//
// public WTFSocketServer addController(WTFSocketController controller) {
// if (scheduler.getHandler() instanceof WTFSocketControllersGroup) {
// ((WTFSocketControllersGroup) scheduler.getHandler()).addController(controller);
// }
// return this;
// }
//
// public WTFSocketScheduler getScheduler() {
// return scheduler;
// }
//
// public WTFSocketProtocolFamily getProtocolFamily() {
// return protocolFamily;
// }
//
// public WTFSocketSecureDelegatesGroup getSecureDelegatesGroup() {
// return secureDelegatesGroup;
// }
//
// public WTFSocketRouting getRouting() {
// return routing;
// }
//
// public WTFSocketEventListenersGroup getEventsGroup() {
// return eventsGroup;
// }
//
// public WTFSocketConfig getConfig() {
// return config;
// }
//
// public void setScheduler(WTFSocketScheduler scheduler) {
// this.scheduler = scheduler;
// }
//
// public void setProtocolFamily(WTFSocketProtocolFamily protocolFamily) {
// this.protocolFamily = protocolFamily;
// }
//
// public void setSecureDelegatesGroup(WTFSocketSecureDelegatesGroup secureDelegatesGroup) {
// this.secureDelegatesGroup = secureDelegatesGroup;
// }
//
// public void setRouting(WTFSocketRouting routing) {
// this.routing = routing;
// }
//
// public void setEventsGroup(WTFSocketEventListenersGroup eventsGroup) {
// this.eventsGroup = eventsGroup;
// }
//
// public WTFSocketConfig setConfig() {
// return config;
// }
//
//
// public ApplicationContext getSpring() {
// return spring;
// }
// }
//
// Path: src/wtf/socket/exception/WTFSocketException.java
// public abstract class WTFSocketException extends Exception {
//
//
// public WTFSocketException(String msg) {
// super(msg);
// }
//
// public abstract int getErrCode();
//
// }
//
// Path: src/wtf/socket/exception/fatal/WTFSocketKeepWordsException.java
// public class WTFSocketKeepWordsException extends WTFSocketFatalException {
// public WTFSocketKeepWordsException(String msg) {
// super(msg);
// }
//
// @Override
// public int getErrCode() {
// return 69;
// }
// }
//
// Path: src/wtf/socket/protocol/WTFSocketMsg.java
// public interface WTFSocketMsg {
//
// String getIoTag();
//
// void setIoTag(String ioTag);
//
// String getFrom();
//
// void setFrom(String from);
//
// String getTo();
//
// void setTo(String to);
//
// int getMsgId();
//
// void setMsgId(int msgId);
//
// int getMsgType();
//
// void setMsgType(int msgType);
//
// int getState();
//
// void setState(int state);
//
// void setConnectType(String connectType);
//
// String getConnectType();
//
// String getVersion();
//
// void setVersion(String version);
//
// Object getBody();
//
// <T> T getBody(Class<T> tClass);
//
// void setBody(Object body);
//
// WTFSocketMsg makeResponse();
// }
// Path: src/wtf/socket/secure/strategy/impl/WTFSocketTargetKeepWordsSecureStrategyImpl.java
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Component;
import wtf.socket.WTFSocketServer;
import wtf.socket.exception.WTFSocketException;
import wtf.socket.exception.fatal.WTFSocketKeepWordsException;
import wtf.socket.protocol.WTFSocketMsg;
package wtf.socket.secure.strategy.impl;
/**
* 是否使用了系统保留关键字
* <p>
* Created by ZFly on 2017/4/25.
*/
@Component
public final class WTFSocketTargetKeepWordsSecureStrategyImpl extends WTFSocketBaseSecureStrategyImpl {
@Override | public void check(WTFSocketServer context, WTFSocketMsg msg) throws WTFSocketException { |
ZhangFly/WTFSocket_Server_JAVA | src/wtf/socket/secure/strategy/impl/WTFSocketTargetKeepWordsSecureStrategyImpl.java | // Path: src/wtf/socket/WTFSocketServer.java
// public final class WTFSocketServer {
//
// /**
// * Spring 上下文
// */
// private ApplicationContext spring = new ClassPathXmlApplicationContext("spring.wtf.socket.xml");
//
// /**
// * 消息调度组件
// * 根据消息的头信息将消息投递到指定的目的地
// */
// @Resource()
// private WTFSocketScheduler scheduler;
//
// /**
// * 路由组件
// * 查询和记录连接的地址
// */
// @Resource
// private WTFSocketRouting routing;
//
// /**
// * 协议族组件
// * IO层收到数据后选择合适的解析器将数据解析为标准消息格式
// */
// @Resource
// private WTFSocketProtocolFamily protocolFamily;
//
// /**
// * 安全组件
// * 可用添加一些安全策略,如发送数据的授权许可等
// */
// @Resource
// private WTFSocketSecureDelegatesGroup secureDelegatesGroup;
//
// /**
// * 事件组组件
// * 包含了一些服务器的监听事件
// */
// @Resource
// private WTFSocketEventListenersGroup eventsGroup;
//
// /**
// * 服务器配置
// */
// private WTFSocketConfig config;
//
// public WTFSocketServer() {
// spring.getAutowireCapableBeanFactory().autowireBean(this);
// scheduler.setContext(this);
// routing.setContext(this);
// }
//
// public void run(WTFSocketConfig config) {
// this.config = config;
// scheduler.run();
// }
//
// public WTFSocketServer addController(WTFSocketController controller) {
// if (scheduler.getHandler() instanceof WTFSocketControllersGroup) {
// ((WTFSocketControllersGroup) scheduler.getHandler()).addController(controller);
// }
// return this;
// }
//
// public WTFSocketScheduler getScheduler() {
// return scheduler;
// }
//
// public WTFSocketProtocolFamily getProtocolFamily() {
// return protocolFamily;
// }
//
// public WTFSocketSecureDelegatesGroup getSecureDelegatesGroup() {
// return secureDelegatesGroup;
// }
//
// public WTFSocketRouting getRouting() {
// return routing;
// }
//
// public WTFSocketEventListenersGroup getEventsGroup() {
// return eventsGroup;
// }
//
// public WTFSocketConfig getConfig() {
// return config;
// }
//
// public void setScheduler(WTFSocketScheduler scheduler) {
// this.scheduler = scheduler;
// }
//
// public void setProtocolFamily(WTFSocketProtocolFamily protocolFamily) {
// this.protocolFamily = protocolFamily;
// }
//
// public void setSecureDelegatesGroup(WTFSocketSecureDelegatesGroup secureDelegatesGroup) {
// this.secureDelegatesGroup = secureDelegatesGroup;
// }
//
// public void setRouting(WTFSocketRouting routing) {
// this.routing = routing;
// }
//
// public void setEventsGroup(WTFSocketEventListenersGroup eventsGroup) {
// this.eventsGroup = eventsGroup;
// }
//
// public WTFSocketConfig setConfig() {
// return config;
// }
//
//
// public ApplicationContext getSpring() {
// return spring;
// }
// }
//
// Path: src/wtf/socket/exception/WTFSocketException.java
// public abstract class WTFSocketException extends Exception {
//
//
// public WTFSocketException(String msg) {
// super(msg);
// }
//
// public abstract int getErrCode();
//
// }
//
// Path: src/wtf/socket/exception/fatal/WTFSocketKeepWordsException.java
// public class WTFSocketKeepWordsException extends WTFSocketFatalException {
// public WTFSocketKeepWordsException(String msg) {
// super(msg);
// }
//
// @Override
// public int getErrCode() {
// return 69;
// }
// }
//
// Path: src/wtf/socket/protocol/WTFSocketMsg.java
// public interface WTFSocketMsg {
//
// String getIoTag();
//
// void setIoTag(String ioTag);
//
// String getFrom();
//
// void setFrom(String from);
//
// String getTo();
//
// void setTo(String to);
//
// int getMsgId();
//
// void setMsgId(int msgId);
//
// int getMsgType();
//
// void setMsgType(int msgType);
//
// int getState();
//
// void setState(int state);
//
// void setConnectType(String connectType);
//
// String getConnectType();
//
// String getVersion();
//
// void setVersion(String version);
//
// Object getBody();
//
// <T> T getBody(Class<T> tClass);
//
// void setBody(Object body);
//
// WTFSocketMsg makeResponse();
// }
| import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Component;
import wtf.socket.WTFSocketServer;
import wtf.socket.exception.WTFSocketException;
import wtf.socket.exception.fatal.WTFSocketKeepWordsException;
import wtf.socket.protocol.WTFSocketMsg; | package wtf.socket.secure.strategy.impl;
/**
* 是否使用了系统保留关键字
* <p>
* Created by ZFly on 2017/4/25.
*/
@Component
public final class WTFSocketTargetKeepWordsSecureStrategyImpl extends WTFSocketBaseSecureStrategyImpl {
@Override
public void check(WTFSocketServer context, WTFSocketMsg msg) throws WTFSocketException {
if (StringUtils.equals("server", msg.getTo())) | // Path: src/wtf/socket/WTFSocketServer.java
// public final class WTFSocketServer {
//
// /**
// * Spring 上下文
// */
// private ApplicationContext spring = new ClassPathXmlApplicationContext("spring.wtf.socket.xml");
//
// /**
// * 消息调度组件
// * 根据消息的头信息将消息投递到指定的目的地
// */
// @Resource()
// private WTFSocketScheduler scheduler;
//
// /**
// * 路由组件
// * 查询和记录连接的地址
// */
// @Resource
// private WTFSocketRouting routing;
//
// /**
// * 协议族组件
// * IO层收到数据后选择合适的解析器将数据解析为标准消息格式
// */
// @Resource
// private WTFSocketProtocolFamily protocolFamily;
//
// /**
// * 安全组件
// * 可用添加一些安全策略,如发送数据的授权许可等
// */
// @Resource
// private WTFSocketSecureDelegatesGroup secureDelegatesGroup;
//
// /**
// * 事件组组件
// * 包含了一些服务器的监听事件
// */
// @Resource
// private WTFSocketEventListenersGroup eventsGroup;
//
// /**
// * 服务器配置
// */
// private WTFSocketConfig config;
//
// public WTFSocketServer() {
// spring.getAutowireCapableBeanFactory().autowireBean(this);
// scheduler.setContext(this);
// routing.setContext(this);
// }
//
// public void run(WTFSocketConfig config) {
// this.config = config;
// scheduler.run();
// }
//
// public WTFSocketServer addController(WTFSocketController controller) {
// if (scheduler.getHandler() instanceof WTFSocketControllersGroup) {
// ((WTFSocketControllersGroup) scheduler.getHandler()).addController(controller);
// }
// return this;
// }
//
// public WTFSocketScheduler getScheduler() {
// return scheduler;
// }
//
// public WTFSocketProtocolFamily getProtocolFamily() {
// return protocolFamily;
// }
//
// public WTFSocketSecureDelegatesGroup getSecureDelegatesGroup() {
// return secureDelegatesGroup;
// }
//
// public WTFSocketRouting getRouting() {
// return routing;
// }
//
// public WTFSocketEventListenersGroup getEventsGroup() {
// return eventsGroup;
// }
//
// public WTFSocketConfig getConfig() {
// return config;
// }
//
// public void setScheduler(WTFSocketScheduler scheduler) {
// this.scheduler = scheduler;
// }
//
// public void setProtocolFamily(WTFSocketProtocolFamily protocolFamily) {
// this.protocolFamily = protocolFamily;
// }
//
// public void setSecureDelegatesGroup(WTFSocketSecureDelegatesGroup secureDelegatesGroup) {
// this.secureDelegatesGroup = secureDelegatesGroup;
// }
//
// public void setRouting(WTFSocketRouting routing) {
// this.routing = routing;
// }
//
// public void setEventsGroup(WTFSocketEventListenersGroup eventsGroup) {
// this.eventsGroup = eventsGroup;
// }
//
// public WTFSocketConfig setConfig() {
// return config;
// }
//
//
// public ApplicationContext getSpring() {
// return spring;
// }
// }
//
// Path: src/wtf/socket/exception/WTFSocketException.java
// public abstract class WTFSocketException extends Exception {
//
//
// public WTFSocketException(String msg) {
// super(msg);
// }
//
// public abstract int getErrCode();
//
// }
//
// Path: src/wtf/socket/exception/fatal/WTFSocketKeepWordsException.java
// public class WTFSocketKeepWordsException extends WTFSocketFatalException {
// public WTFSocketKeepWordsException(String msg) {
// super(msg);
// }
//
// @Override
// public int getErrCode() {
// return 69;
// }
// }
//
// Path: src/wtf/socket/protocol/WTFSocketMsg.java
// public interface WTFSocketMsg {
//
// String getIoTag();
//
// void setIoTag(String ioTag);
//
// String getFrom();
//
// void setFrom(String from);
//
// String getTo();
//
// void setTo(String to);
//
// int getMsgId();
//
// void setMsgId(int msgId);
//
// int getMsgType();
//
// void setMsgType(int msgType);
//
// int getState();
//
// void setState(int state);
//
// void setConnectType(String connectType);
//
// String getConnectType();
//
// String getVersion();
//
// void setVersion(String version);
//
// Object getBody();
//
// <T> T getBody(Class<T> tClass);
//
// void setBody(Object body);
//
// WTFSocketMsg makeResponse();
// }
// Path: src/wtf/socket/secure/strategy/impl/WTFSocketTargetKeepWordsSecureStrategyImpl.java
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Component;
import wtf.socket.WTFSocketServer;
import wtf.socket.exception.WTFSocketException;
import wtf.socket.exception.fatal.WTFSocketKeepWordsException;
import wtf.socket.protocol.WTFSocketMsg;
package wtf.socket.secure.strategy.impl;
/**
* 是否使用了系统保留关键字
* <p>
* Created by ZFly on 2017/4/25.
*/
@Component
public final class WTFSocketTargetKeepWordsSecureStrategyImpl extends WTFSocketBaseSecureStrategyImpl {
@Override
public void check(WTFSocketServer context, WTFSocketMsg msg) throws WTFSocketException {
if (StringUtils.equals("server", msg.getTo())) | throw new WTFSocketKeepWordsException("Target can not be [" + msg.getTo() + "]"); |
ZhangFly/WTFSocket_Server_JAVA | src/wtf/socket/routing/item/WTFSocketRoutingDebugItem.java | // Path: src/wtf/socket/exception/WTFSocketException.java
// public abstract class WTFSocketException extends Exception {
//
//
// public WTFSocketException(String msg) {
// super(msg);
// }
//
// public abstract int getErrCode();
//
// }
| import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import wtf.socket.exception.WTFSocketException;
import java.util.ArrayList;
import java.util.List; | package wtf.socket.routing.item;
/**
* 调试者客户端
* <p>
* Created by ZFly on 2017/4/23.
*/
@Component
@Scope("prototype")
public class WTFSocketRoutingDebugItem extends WTFSocketRoutingFormalItem {
/**
* 拦截器规则
*/
private List<String> filterGreps;
public WTFSocketRoutingDebugItem() {
addAuthTarget("server");
}
public void addFilterGrep(String grep) {
if (filterGreps == null) {
filterGreps = new ArrayList<>();
}
filterGreps.add(grep);
}
public void removeFilterGrep(String grep) {
if (filterGreps != null) {
filterGreps.remove(grep);
}
}
public boolean isFilter(String msg) {
if (filterGreps == null || filterGreps.isEmpty()) {
return true;
}
boolean flag = false;
for (String grep : filterGreps) {
flag = flag || msg.contains("<" + grep + ">");
}
return flag;
}
| // Path: src/wtf/socket/exception/WTFSocketException.java
// public abstract class WTFSocketException extends Exception {
//
//
// public WTFSocketException(String msg) {
// super(msg);
// }
//
// public abstract int getErrCode();
//
// }
// Path: src/wtf/socket/routing/item/WTFSocketRoutingDebugItem.java
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import wtf.socket.exception.WTFSocketException;
import java.util.ArrayList;
import java.util.List;
package wtf.socket.routing.item;
/**
* 调试者客户端
* <p>
* Created by ZFly on 2017/4/23.
*/
@Component
@Scope("prototype")
public class WTFSocketRoutingDebugItem extends WTFSocketRoutingFormalItem {
/**
* 拦截器规则
*/
private List<String> filterGreps;
public WTFSocketRoutingDebugItem() {
addAuthTarget("server");
}
public void addFilterGrep(String grep) {
if (filterGreps == null) {
filterGreps = new ArrayList<>();
}
filterGreps.add(grep);
}
public void removeFilterGrep(String grep) {
if (filterGreps != null) {
filterGreps.remove(grep);
}
}
public boolean isFilter(String msg) {
if (filterGreps == null || filterGreps.isEmpty()) {
return true;
}
boolean flag = false;
for (String grep : filterGreps) {
flag = flag || msg.contains("<" + grep + ">");
}
return flag;
}
| public void close() throws WTFSocketException { |
ZhangFly/WTFSocket_Server_JAVA | src/wtf/socket/secure/strategy/impl/WTFSocketContainsTargetSecureStrategyImpl.java | // Path: src/wtf/socket/WTFSocketServer.java
// public final class WTFSocketServer {
//
// /**
// * Spring 上下文
// */
// private ApplicationContext spring = new ClassPathXmlApplicationContext("spring.wtf.socket.xml");
//
// /**
// * 消息调度组件
// * 根据消息的头信息将消息投递到指定的目的地
// */
// @Resource()
// private WTFSocketScheduler scheduler;
//
// /**
// * 路由组件
// * 查询和记录连接的地址
// */
// @Resource
// private WTFSocketRouting routing;
//
// /**
// * 协议族组件
// * IO层收到数据后选择合适的解析器将数据解析为标准消息格式
// */
// @Resource
// private WTFSocketProtocolFamily protocolFamily;
//
// /**
// * 安全组件
// * 可用添加一些安全策略,如发送数据的授权许可等
// */
// @Resource
// private WTFSocketSecureDelegatesGroup secureDelegatesGroup;
//
// /**
// * 事件组组件
// * 包含了一些服务器的监听事件
// */
// @Resource
// private WTFSocketEventListenersGroup eventsGroup;
//
// /**
// * 服务器配置
// */
// private WTFSocketConfig config;
//
// public WTFSocketServer() {
// spring.getAutowireCapableBeanFactory().autowireBean(this);
// scheduler.setContext(this);
// routing.setContext(this);
// }
//
// public void run(WTFSocketConfig config) {
// this.config = config;
// scheduler.run();
// }
//
// public WTFSocketServer addController(WTFSocketController controller) {
// if (scheduler.getHandler() instanceof WTFSocketControllersGroup) {
// ((WTFSocketControllersGroup) scheduler.getHandler()).addController(controller);
// }
// return this;
// }
//
// public WTFSocketScheduler getScheduler() {
// return scheduler;
// }
//
// public WTFSocketProtocolFamily getProtocolFamily() {
// return protocolFamily;
// }
//
// public WTFSocketSecureDelegatesGroup getSecureDelegatesGroup() {
// return secureDelegatesGroup;
// }
//
// public WTFSocketRouting getRouting() {
// return routing;
// }
//
// public WTFSocketEventListenersGroup getEventsGroup() {
// return eventsGroup;
// }
//
// public WTFSocketConfig getConfig() {
// return config;
// }
//
// public void setScheduler(WTFSocketScheduler scheduler) {
// this.scheduler = scheduler;
// }
//
// public void setProtocolFamily(WTFSocketProtocolFamily protocolFamily) {
// this.protocolFamily = protocolFamily;
// }
//
// public void setSecureDelegatesGroup(WTFSocketSecureDelegatesGroup secureDelegatesGroup) {
// this.secureDelegatesGroup = secureDelegatesGroup;
// }
//
// public void setRouting(WTFSocketRouting routing) {
// this.routing = routing;
// }
//
// public void setEventsGroup(WTFSocketEventListenersGroup eventsGroup) {
// this.eventsGroup = eventsGroup;
// }
//
// public WTFSocketConfig setConfig() {
// return config;
// }
//
//
// public ApplicationContext getSpring() {
// return spring;
// }
// }
//
// Path: src/wtf/socket/exception/WTFSocketException.java
// public abstract class WTFSocketException extends Exception {
//
//
// public WTFSocketException(String msg) {
// super(msg);
// }
//
// public abstract int getErrCode();
//
// }
//
// Path: src/wtf/socket/exception/normal/WTFSocketInvalidTargetException.java
// public class WTFSocketInvalidTargetException extends WTFSocketNormalException {
//
// public WTFSocketInvalidTargetException(String msg) {
// super(msg);
// }
//
// public int getErrCode() {
// return 16;
// }
//
// }
//
// Path: src/wtf/socket/protocol/WTFSocketMsg.java
// public interface WTFSocketMsg {
//
// String getIoTag();
//
// void setIoTag(String ioTag);
//
// String getFrom();
//
// void setFrom(String from);
//
// String getTo();
//
// void setTo(String to);
//
// int getMsgId();
//
// void setMsgId(int msgId);
//
// int getMsgType();
//
// void setMsgType(int msgType);
//
// int getState();
//
// void setState(int state);
//
// void setConnectType(String connectType);
//
// String getConnectType();
//
// String getVersion();
//
// void setVersion(String version);
//
// Object getBody();
//
// <T> T getBody(Class<T> tClass);
//
// void setBody(Object body);
//
// WTFSocketMsg makeResponse();
// }
| import org.springframework.stereotype.Component;
import wtf.socket.WTFSocketServer;
import wtf.socket.exception.WTFSocketException;
import wtf.socket.exception.normal.WTFSocketInvalidTargetException;
import wtf.socket.protocol.WTFSocketMsg; | package wtf.socket.secure.strategy.impl;
/**
* 发送目标是否已注册为正式客户端
* <p>
* Created by ZFly on 2017/4/25.
*/
@Component
public final class WTFSocketContainsTargetSecureStrategyImpl extends WTFSocketBaseSecureStrategyImpl {
@Override | // Path: src/wtf/socket/WTFSocketServer.java
// public final class WTFSocketServer {
//
// /**
// * Spring 上下文
// */
// private ApplicationContext spring = new ClassPathXmlApplicationContext("spring.wtf.socket.xml");
//
// /**
// * 消息调度组件
// * 根据消息的头信息将消息投递到指定的目的地
// */
// @Resource()
// private WTFSocketScheduler scheduler;
//
// /**
// * 路由组件
// * 查询和记录连接的地址
// */
// @Resource
// private WTFSocketRouting routing;
//
// /**
// * 协议族组件
// * IO层收到数据后选择合适的解析器将数据解析为标准消息格式
// */
// @Resource
// private WTFSocketProtocolFamily protocolFamily;
//
// /**
// * 安全组件
// * 可用添加一些安全策略,如发送数据的授权许可等
// */
// @Resource
// private WTFSocketSecureDelegatesGroup secureDelegatesGroup;
//
// /**
// * 事件组组件
// * 包含了一些服务器的监听事件
// */
// @Resource
// private WTFSocketEventListenersGroup eventsGroup;
//
// /**
// * 服务器配置
// */
// private WTFSocketConfig config;
//
// public WTFSocketServer() {
// spring.getAutowireCapableBeanFactory().autowireBean(this);
// scheduler.setContext(this);
// routing.setContext(this);
// }
//
// public void run(WTFSocketConfig config) {
// this.config = config;
// scheduler.run();
// }
//
// public WTFSocketServer addController(WTFSocketController controller) {
// if (scheduler.getHandler() instanceof WTFSocketControllersGroup) {
// ((WTFSocketControllersGroup) scheduler.getHandler()).addController(controller);
// }
// return this;
// }
//
// public WTFSocketScheduler getScheduler() {
// return scheduler;
// }
//
// public WTFSocketProtocolFamily getProtocolFamily() {
// return protocolFamily;
// }
//
// public WTFSocketSecureDelegatesGroup getSecureDelegatesGroup() {
// return secureDelegatesGroup;
// }
//
// public WTFSocketRouting getRouting() {
// return routing;
// }
//
// public WTFSocketEventListenersGroup getEventsGroup() {
// return eventsGroup;
// }
//
// public WTFSocketConfig getConfig() {
// return config;
// }
//
// public void setScheduler(WTFSocketScheduler scheduler) {
// this.scheduler = scheduler;
// }
//
// public void setProtocolFamily(WTFSocketProtocolFamily protocolFamily) {
// this.protocolFamily = protocolFamily;
// }
//
// public void setSecureDelegatesGroup(WTFSocketSecureDelegatesGroup secureDelegatesGroup) {
// this.secureDelegatesGroup = secureDelegatesGroup;
// }
//
// public void setRouting(WTFSocketRouting routing) {
// this.routing = routing;
// }
//
// public void setEventsGroup(WTFSocketEventListenersGroup eventsGroup) {
// this.eventsGroup = eventsGroup;
// }
//
// public WTFSocketConfig setConfig() {
// return config;
// }
//
//
// public ApplicationContext getSpring() {
// return spring;
// }
// }
//
// Path: src/wtf/socket/exception/WTFSocketException.java
// public abstract class WTFSocketException extends Exception {
//
//
// public WTFSocketException(String msg) {
// super(msg);
// }
//
// public abstract int getErrCode();
//
// }
//
// Path: src/wtf/socket/exception/normal/WTFSocketInvalidTargetException.java
// public class WTFSocketInvalidTargetException extends WTFSocketNormalException {
//
// public WTFSocketInvalidTargetException(String msg) {
// super(msg);
// }
//
// public int getErrCode() {
// return 16;
// }
//
// }
//
// Path: src/wtf/socket/protocol/WTFSocketMsg.java
// public interface WTFSocketMsg {
//
// String getIoTag();
//
// void setIoTag(String ioTag);
//
// String getFrom();
//
// void setFrom(String from);
//
// String getTo();
//
// void setTo(String to);
//
// int getMsgId();
//
// void setMsgId(int msgId);
//
// int getMsgType();
//
// void setMsgType(int msgType);
//
// int getState();
//
// void setState(int state);
//
// void setConnectType(String connectType);
//
// String getConnectType();
//
// String getVersion();
//
// void setVersion(String version);
//
// Object getBody();
//
// <T> T getBody(Class<T> tClass);
//
// void setBody(Object body);
//
// WTFSocketMsg makeResponse();
// }
// Path: src/wtf/socket/secure/strategy/impl/WTFSocketContainsTargetSecureStrategyImpl.java
import org.springframework.stereotype.Component;
import wtf.socket.WTFSocketServer;
import wtf.socket.exception.WTFSocketException;
import wtf.socket.exception.normal.WTFSocketInvalidTargetException;
import wtf.socket.protocol.WTFSocketMsg;
package wtf.socket.secure.strategy.impl;
/**
* 发送目标是否已注册为正式客户端
* <p>
* Created by ZFly on 2017/4/25.
*/
@Component
public final class WTFSocketContainsTargetSecureStrategyImpl extends WTFSocketBaseSecureStrategyImpl {
@Override | public void check(WTFSocketServer context, WTFSocketMsg msg) throws WTFSocketException { |
ZhangFly/WTFSocket_Server_JAVA | src/wtf/socket/secure/strategy/impl/WTFSocketContainsTargetSecureStrategyImpl.java | // Path: src/wtf/socket/WTFSocketServer.java
// public final class WTFSocketServer {
//
// /**
// * Spring 上下文
// */
// private ApplicationContext spring = new ClassPathXmlApplicationContext("spring.wtf.socket.xml");
//
// /**
// * 消息调度组件
// * 根据消息的头信息将消息投递到指定的目的地
// */
// @Resource()
// private WTFSocketScheduler scheduler;
//
// /**
// * 路由组件
// * 查询和记录连接的地址
// */
// @Resource
// private WTFSocketRouting routing;
//
// /**
// * 协议族组件
// * IO层收到数据后选择合适的解析器将数据解析为标准消息格式
// */
// @Resource
// private WTFSocketProtocolFamily protocolFamily;
//
// /**
// * 安全组件
// * 可用添加一些安全策略,如发送数据的授权许可等
// */
// @Resource
// private WTFSocketSecureDelegatesGroup secureDelegatesGroup;
//
// /**
// * 事件组组件
// * 包含了一些服务器的监听事件
// */
// @Resource
// private WTFSocketEventListenersGroup eventsGroup;
//
// /**
// * 服务器配置
// */
// private WTFSocketConfig config;
//
// public WTFSocketServer() {
// spring.getAutowireCapableBeanFactory().autowireBean(this);
// scheduler.setContext(this);
// routing.setContext(this);
// }
//
// public void run(WTFSocketConfig config) {
// this.config = config;
// scheduler.run();
// }
//
// public WTFSocketServer addController(WTFSocketController controller) {
// if (scheduler.getHandler() instanceof WTFSocketControllersGroup) {
// ((WTFSocketControllersGroup) scheduler.getHandler()).addController(controller);
// }
// return this;
// }
//
// public WTFSocketScheduler getScheduler() {
// return scheduler;
// }
//
// public WTFSocketProtocolFamily getProtocolFamily() {
// return protocolFamily;
// }
//
// public WTFSocketSecureDelegatesGroup getSecureDelegatesGroup() {
// return secureDelegatesGroup;
// }
//
// public WTFSocketRouting getRouting() {
// return routing;
// }
//
// public WTFSocketEventListenersGroup getEventsGroup() {
// return eventsGroup;
// }
//
// public WTFSocketConfig getConfig() {
// return config;
// }
//
// public void setScheduler(WTFSocketScheduler scheduler) {
// this.scheduler = scheduler;
// }
//
// public void setProtocolFamily(WTFSocketProtocolFamily protocolFamily) {
// this.protocolFamily = protocolFamily;
// }
//
// public void setSecureDelegatesGroup(WTFSocketSecureDelegatesGroup secureDelegatesGroup) {
// this.secureDelegatesGroup = secureDelegatesGroup;
// }
//
// public void setRouting(WTFSocketRouting routing) {
// this.routing = routing;
// }
//
// public void setEventsGroup(WTFSocketEventListenersGroup eventsGroup) {
// this.eventsGroup = eventsGroup;
// }
//
// public WTFSocketConfig setConfig() {
// return config;
// }
//
//
// public ApplicationContext getSpring() {
// return spring;
// }
// }
//
// Path: src/wtf/socket/exception/WTFSocketException.java
// public abstract class WTFSocketException extends Exception {
//
//
// public WTFSocketException(String msg) {
// super(msg);
// }
//
// public abstract int getErrCode();
//
// }
//
// Path: src/wtf/socket/exception/normal/WTFSocketInvalidTargetException.java
// public class WTFSocketInvalidTargetException extends WTFSocketNormalException {
//
// public WTFSocketInvalidTargetException(String msg) {
// super(msg);
// }
//
// public int getErrCode() {
// return 16;
// }
//
// }
//
// Path: src/wtf/socket/protocol/WTFSocketMsg.java
// public interface WTFSocketMsg {
//
// String getIoTag();
//
// void setIoTag(String ioTag);
//
// String getFrom();
//
// void setFrom(String from);
//
// String getTo();
//
// void setTo(String to);
//
// int getMsgId();
//
// void setMsgId(int msgId);
//
// int getMsgType();
//
// void setMsgType(int msgType);
//
// int getState();
//
// void setState(int state);
//
// void setConnectType(String connectType);
//
// String getConnectType();
//
// String getVersion();
//
// void setVersion(String version);
//
// Object getBody();
//
// <T> T getBody(Class<T> tClass);
//
// void setBody(Object body);
//
// WTFSocketMsg makeResponse();
// }
| import org.springframework.stereotype.Component;
import wtf.socket.WTFSocketServer;
import wtf.socket.exception.WTFSocketException;
import wtf.socket.exception.normal.WTFSocketInvalidTargetException;
import wtf.socket.protocol.WTFSocketMsg; | package wtf.socket.secure.strategy.impl;
/**
* 发送目标是否已注册为正式客户端
* <p>
* Created by ZFly on 2017/4/25.
*/
@Component
public final class WTFSocketContainsTargetSecureStrategyImpl extends WTFSocketBaseSecureStrategyImpl {
@Override | // Path: src/wtf/socket/WTFSocketServer.java
// public final class WTFSocketServer {
//
// /**
// * Spring 上下文
// */
// private ApplicationContext spring = new ClassPathXmlApplicationContext("spring.wtf.socket.xml");
//
// /**
// * 消息调度组件
// * 根据消息的头信息将消息投递到指定的目的地
// */
// @Resource()
// private WTFSocketScheduler scheduler;
//
// /**
// * 路由组件
// * 查询和记录连接的地址
// */
// @Resource
// private WTFSocketRouting routing;
//
// /**
// * 协议族组件
// * IO层收到数据后选择合适的解析器将数据解析为标准消息格式
// */
// @Resource
// private WTFSocketProtocolFamily protocolFamily;
//
// /**
// * 安全组件
// * 可用添加一些安全策略,如发送数据的授权许可等
// */
// @Resource
// private WTFSocketSecureDelegatesGroup secureDelegatesGroup;
//
// /**
// * 事件组组件
// * 包含了一些服务器的监听事件
// */
// @Resource
// private WTFSocketEventListenersGroup eventsGroup;
//
// /**
// * 服务器配置
// */
// private WTFSocketConfig config;
//
// public WTFSocketServer() {
// spring.getAutowireCapableBeanFactory().autowireBean(this);
// scheduler.setContext(this);
// routing.setContext(this);
// }
//
// public void run(WTFSocketConfig config) {
// this.config = config;
// scheduler.run();
// }
//
// public WTFSocketServer addController(WTFSocketController controller) {
// if (scheduler.getHandler() instanceof WTFSocketControllersGroup) {
// ((WTFSocketControllersGroup) scheduler.getHandler()).addController(controller);
// }
// return this;
// }
//
// public WTFSocketScheduler getScheduler() {
// return scheduler;
// }
//
// public WTFSocketProtocolFamily getProtocolFamily() {
// return protocolFamily;
// }
//
// public WTFSocketSecureDelegatesGroup getSecureDelegatesGroup() {
// return secureDelegatesGroup;
// }
//
// public WTFSocketRouting getRouting() {
// return routing;
// }
//
// public WTFSocketEventListenersGroup getEventsGroup() {
// return eventsGroup;
// }
//
// public WTFSocketConfig getConfig() {
// return config;
// }
//
// public void setScheduler(WTFSocketScheduler scheduler) {
// this.scheduler = scheduler;
// }
//
// public void setProtocolFamily(WTFSocketProtocolFamily protocolFamily) {
// this.protocolFamily = protocolFamily;
// }
//
// public void setSecureDelegatesGroup(WTFSocketSecureDelegatesGroup secureDelegatesGroup) {
// this.secureDelegatesGroup = secureDelegatesGroup;
// }
//
// public void setRouting(WTFSocketRouting routing) {
// this.routing = routing;
// }
//
// public void setEventsGroup(WTFSocketEventListenersGroup eventsGroup) {
// this.eventsGroup = eventsGroup;
// }
//
// public WTFSocketConfig setConfig() {
// return config;
// }
//
//
// public ApplicationContext getSpring() {
// return spring;
// }
// }
//
// Path: src/wtf/socket/exception/WTFSocketException.java
// public abstract class WTFSocketException extends Exception {
//
//
// public WTFSocketException(String msg) {
// super(msg);
// }
//
// public abstract int getErrCode();
//
// }
//
// Path: src/wtf/socket/exception/normal/WTFSocketInvalidTargetException.java
// public class WTFSocketInvalidTargetException extends WTFSocketNormalException {
//
// public WTFSocketInvalidTargetException(String msg) {
// super(msg);
// }
//
// public int getErrCode() {
// return 16;
// }
//
// }
//
// Path: src/wtf/socket/protocol/WTFSocketMsg.java
// public interface WTFSocketMsg {
//
// String getIoTag();
//
// void setIoTag(String ioTag);
//
// String getFrom();
//
// void setFrom(String from);
//
// String getTo();
//
// void setTo(String to);
//
// int getMsgId();
//
// void setMsgId(int msgId);
//
// int getMsgType();
//
// void setMsgType(int msgType);
//
// int getState();
//
// void setState(int state);
//
// void setConnectType(String connectType);
//
// String getConnectType();
//
// String getVersion();
//
// void setVersion(String version);
//
// Object getBody();
//
// <T> T getBody(Class<T> tClass);
//
// void setBody(Object body);
//
// WTFSocketMsg makeResponse();
// }
// Path: src/wtf/socket/secure/strategy/impl/WTFSocketContainsTargetSecureStrategyImpl.java
import org.springframework.stereotype.Component;
import wtf.socket.WTFSocketServer;
import wtf.socket.exception.WTFSocketException;
import wtf.socket.exception.normal.WTFSocketInvalidTargetException;
import wtf.socket.protocol.WTFSocketMsg;
package wtf.socket.secure.strategy.impl;
/**
* 发送目标是否已注册为正式客户端
* <p>
* Created by ZFly on 2017/4/25.
*/
@Component
public final class WTFSocketContainsTargetSecureStrategyImpl extends WTFSocketBaseSecureStrategyImpl {
@Override | public void check(WTFSocketServer context, WTFSocketMsg msg) throws WTFSocketException { |
ZhangFly/WTFSocket_Server_JAVA | src/wtf/socket/secure/strategy/impl/WTFSocketContainsTargetSecureStrategyImpl.java | // Path: src/wtf/socket/WTFSocketServer.java
// public final class WTFSocketServer {
//
// /**
// * Spring 上下文
// */
// private ApplicationContext spring = new ClassPathXmlApplicationContext("spring.wtf.socket.xml");
//
// /**
// * 消息调度组件
// * 根据消息的头信息将消息投递到指定的目的地
// */
// @Resource()
// private WTFSocketScheduler scheduler;
//
// /**
// * 路由组件
// * 查询和记录连接的地址
// */
// @Resource
// private WTFSocketRouting routing;
//
// /**
// * 协议族组件
// * IO层收到数据后选择合适的解析器将数据解析为标准消息格式
// */
// @Resource
// private WTFSocketProtocolFamily protocolFamily;
//
// /**
// * 安全组件
// * 可用添加一些安全策略,如发送数据的授权许可等
// */
// @Resource
// private WTFSocketSecureDelegatesGroup secureDelegatesGroup;
//
// /**
// * 事件组组件
// * 包含了一些服务器的监听事件
// */
// @Resource
// private WTFSocketEventListenersGroup eventsGroup;
//
// /**
// * 服务器配置
// */
// private WTFSocketConfig config;
//
// public WTFSocketServer() {
// spring.getAutowireCapableBeanFactory().autowireBean(this);
// scheduler.setContext(this);
// routing.setContext(this);
// }
//
// public void run(WTFSocketConfig config) {
// this.config = config;
// scheduler.run();
// }
//
// public WTFSocketServer addController(WTFSocketController controller) {
// if (scheduler.getHandler() instanceof WTFSocketControllersGroup) {
// ((WTFSocketControllersGroup) scheduler.getHandler()).addController(controller);
// }
// return this;
// }
//
// public WTFSocketScheduler getScheduler() {
// return scheduler;
// }
//
// public WTFSocketProtocolFamily getProtocolFamily() {
// return protocolFamily;
// }
//
// public WTFSocketSecureDelegatesGroup getSecureDelegatesGroup() {
// return secureDelegatesGroup;
// }
//
// public WTFSocketRouting getRouting() {
// return routing;
// }
//
// public WTFSocketEventListenersGroup getEventsGroup() {
// return eventsGroup;
// }
//
// public WTFSocketConfig getConfig() {
// return config;
// }
//
// public void setScheduler(WTFSocketScheduler scheduler) {
// this.scheduler = scheduler;
// }
//
// public void setProtocolFamily(WTFSocketProtocolFamily protocolFamily) {
// this.protocolFamily = protocolFamily;
// }
//
// public void setSecureDelegatesGroup(WTFSocketSecureDelegatesGroup secureDelegatesGroup) {
// this.secureDelegatesGroup = secureDelegatesGroup;
// }
//
// public void setRouting(WTFSocketRouting routing) {
// this.routing = routing;
// }
//
// public void setEventsGroup(WTFSocketEventListenersGroup eventsGroup) {
// this.eventsGroup = eventsGroup;
// }
//
// public WTFSocketConfig setConfig() {
// return config;
// }
//
//
// public ApplicationContext getSpring() {
// return spring;
// }
// }
//
// Path: src/wtf/socket/exception/WTFSocketException.java
// public abstract class WTFSocketException extends Exception {
//
//
// public WTFSocketException(String msg) {
// super(msg);
// }
//
// public abstract int getErrCode();
//
// }
//
// Path: src/wtf/socket/exception/normal/WTFSocketInvalidTargetException.java
// public class WTFSocketInvalidTargetException extends WTFSocketNormalException {
//
// public WTFSocketInvalidTargetException(String msg) {
// super(msg);
// }
//
// public int getErrCode() {
// return 16;
// }
//
// }
//
// Path: src/wtf/socket/protocol/WTFSocketMsg.java
// public interface WTFSocketMsg {
//
// String getIoTag();
//
// void setIoTag(String ioTag);
//
// String getFrom();
//
// void setFrom(String from);
//
// String getTo();
//
// void setTo(String to);
//
// int getMsgId();
//
// void setMsgId(int msgId);
//
// int getMsgType();
//
// void setMsgType(int msgType);
//
// int getState();
//
// void setState(int state);
//
// void setConnectType(String connectType);
//
// String getConnectType();
//
// String getVersion();
//
// void setVersion(String version);
//
// Object getBody();
//
// <T> T getBody(Class<T> tClass);
//
// void setBody(Object body);
//
// WTFSocketMsg makeResponse();
// }
| import org.springframework.stereotype.Component;
import wtf.socket.WTFSocketServer;
import wtf.socket.exception.WTFSocketException;
import wtf.socket.exception.normal.WTFSocketInvalidTargetException;
import wtf.socket.protocol.WTFSocketMsg; | package wtf.socket.secure.strategy.impl;
/**
* 发送目标是否已注册为正式客户端
* <p>
* Created by ZFly on 2017/4/25.
*/
@Component
public final class WTFSocketContainsTargetSecureStrategyImpl extends WTFSocketBaseSecureStrategyImpl {
@Override | // Path: src/wtf/socket/WTFSocketServer.java
// public final class WTFSocketServer {
//
// /**
// * Spring 上下文
// */
// private ApplicationContext spring = new ClassPathXmlApplicationContext("spring.wtf.socket.xml");
//
// /**
// * 消息调度组件
// * 根据消息的头信息将消息投递到指定的目的地
// */
// @Resource()
// private WTFSocketScheduler scheduler;
//
// /**
// * 路由组件
// * 查询和记录连接的地址
// */
// @Resource
// private WTFSocketRouting routing;
//
// /**
// * 协议族组件
// * IO层收到数据后选择合适的解析器将数据解析为标准消息格式
// */
// @Resource
// private WTFSocketProtocolFamily protocolFamily;
//
// /**
// * 安全组件
// * 可用添加一些安全策略,如发送数据的授权许可等
// */
// @Resource
// private WTFSocketSecureDelegatesGroup secureDelegatesGroup;
//
// /**
// * 事件组组件
// * 包含了一些服务器的监听事件
// */
// @Resource
// private WTFSocketEventListenersGroup eventsGroup;
//
// /**
// * 服务器配置
// */
// private WTFSocketConfig config;
//
// public WTFSocketServer() {
// spring.getAutowireCapableBeanFactory().autowireBean(this);
// scheduler.setContext(this);
// routing.setContext(this);
// }
//
// public void run(WTFSocketConfig config) {
// this.config = config;
// scheduler.run();
// }
//
// public WTFSocketServer addController(WTFSocketController controller) {
// if (scheduler.getHandler() instanceof WTFSocketControllersGroup) {
// ((WTFSocketControllersGroup) scheduler.getHandler()).addController(controller);
// }
// return this;
// }
//
// public WTFSocketScheduler getScheduler() {
// return scheduler;
// }
//
// public WTFSocketProtocolFamily getProtocolFamily() {
// return protocolFamily;
// }
//
// public WTFSocketSecureDelegatesGroup getSecureDelegatesGroup() {
// return secureDelegatesGroup;
// }
//
// public WTFSocketRouting getRouting() {
// return routing;
// }
//
// public WTFSocketEventListenersGroup getEventsGroup() {
// return eventsGroup;
// }
//
// public WTFSocketConfig getConfig() {
// return config;
// }
//
// public void setScheduler(WTFSocketScheduler scheduler) {
// this.scheduler = scheduler;
// }
//
// public void setProtocolFamily(WTFSocketProtocolFamily protocolFamily) {
// this.protocolFamily = protocolFamily;
// }
//
// public void setSecureDelegatesGroup(WTFSocketSecureDelegatesGroup secureDelegatesGroup) {
// this.secureDelegatesGroup = secureDelegatesGroup;
// }
//
// public void setRouting(WTFSocketRouting routing) {
// this.routing = routing;
// }
//
// public void setEventsGroup(WTFSocketEventListenersGroup eventsGroup) {
// this.eventsGroup = eventsGroup;
// }
//
// public WTFSocketConfig setConfig() {
// return config;
// }
//
//
// public ApplicationContext getSpring() {
// return spring;
// }
// }
//
// Path: src/wtf/socket/exception/WTFSocketException.java
// public abstract class WTFSocketException extends Exception {
//
//
// public WTFSocketException(String msg) {
// super(msg);
// }
//
// public abstract int getErrCode();
//
// }
//
// Path: src/wtf/socket/exception/normal/WTFSocketInvalidTargetException.java
// public class WTFSocketInvalidTargetException extends WTFSocketNormalException {
//
// public WTFSocketInvalidTargetException(String msg) {
// super(msg);
// }
//
// public int getErrCode() {
// return 16;
// }
//
// }
//
// Path: src/wtf/socket/protocol/WTFSocketMsg.java
// public interface WTFSocketMsg {
//
// String getIoTag();
//
// void setIoTag(String ioTag);
//
// String getFrom();
//
// void setFrom(String from);
//
// String getTo();
//
// void setTo(String to);
//
// int getMsgId();
//
// void setMsgId(int msgId);
//
// int getMsgType();
//
// void setMsgType(int msgType);
//
// int getState();
//
// void setState(int state);
//
// void setConnectType(String connectType);
//
// String getConnectType();
//
// String getVersion();
//
// void setVersion(String version);
//
// Object getBody();
//
// <T> T getBody(Class<T> tClass);
//
// void setBody(Object body);
//
// WTFSocketMsg makeResponse();
// }
// Path: src/wtf/socket/secure/strategy/impl/WTFSocketContainsTargetSecureStrategyImpl.java
import org.springframework.stereotype.Component;
import wtf.socket.WTFSocketServer;
import wtf.socket.exception.WTFSocketException;
import wtf.socket.exception.normal.WTFSocketInvalidTargetException;
import wtf.socket.protocol.WTFSocketMsg;
package wtf.socket.secure.strategy.impl;
/**
* 发送目标是否已注册为正式客户端
* <p>
* Created by ZFly on 2017/4/25.
*/
@Component
public final class WTFSocketContainsTargetSecureStrategyImpl extends WTFSocketBaseSecureStrategyImpl {
@Override | public void check(WTFSocketServer context, WTFSocketMsg msg) throws WTFSocketException { |
ZhangFly/WTFSocket_Server_JAVA | src/wtf/socket/protocol/WTFSocketProtocolParser.java | // Path: src/wtf/socket/exception/fatal/WTFSocketProtocolBrokenException.java
// public class WTFSocketProtocolBrokenException extends WTFSocketFatalException {
//
// public WTFSocketProtocolBrokenException(String msg) {
// super(msg);
// }
//
// public int getErrCode() {
// return 64;
// }
// }
//
// Path: src/wtf/socket/util/WTFSocketPriority.java
// public final class WTFSocketPriority {
//
// private WTFSocketPriority() {
// }
//
// public final static int HIGHEST = -3;
// public final static int HIGH = -2;
// public final static int MEDIUM_HIGH = -1;
// public final static int MEDIUM = 0;
// public final static int MEDIUM_LOW = 1;
// public final static int LOW = 2;
// public final static int LOWEST = 3;
//
// }
| import wtf.socket.exception.fatal.WTFSocketProtocolBrokenException;
import wtf.socket.util.WTFSocketPriority; | package wtf.socket.protocol;
/**
* 协议解析器接口
* <p>
* Created by ZFly on 2017/4/21.
*/
public interface WTFSocketProtocolParser {
/**
* 优先级
*
* @return 优先级
*/
default int getPriority() { | // Path: src/wtf/socket/exception/fatal/WTFSocketProtocolBrokenException.java
// public class WTFSocketProtocolBrokenException extends WTFSocketFatalException {
//
// public WTFSocketProtocolBrokenException(String msg) {
// super(msg);
// }
//
// public int getErrCode() {
// return 64;
// }
// }
//
// Path: src/wtf/socket/util/WTFSocketPriority.java
// public final class WTFSocketPriority {
//
// private WTFSocketPriority() {
// }
//
// public final static int HIGHEST = -3;
// public final static int HIGH = -2;
// public final static int MEDIUM_HIGH = -1;
// public final static int MEDIUM = 0;
// public final static int MEDIUM_LOW = 1;
// public final static int LOW = 2;
// public final static int LOWEST = 3;
//
// }
// Path: src/wtf/socket/protocol/WTFSocketProtocolParser.java
import wtf.socket.exception.fatal.WTFSocketProtocolBrokenException;
import wtf.socket.util.WTFSocketPriority;
package wtf.socket.protocol;
/**
* 协议解析器接口
* <p>
* Created by ZFly on 2017/4/21.
*/
public interface WTFSocketProtocolParser {
/**
* 优先级
*
* @return 优先级
*/
default int getPriority() { | return WTFSocketPriority.MEDIUM; |
ZhangFly/WTFSocket_Server_JAVA | src/wtf/socket/protocol/WTFSocketProtocolParser.java | // Path: src/wtf/socket/exception/fatal/WTFSocketProtocolBrokenException.java
// public class WTFSocketProtocolBrokenException extends WTFSocketFatalException {
//
// public WTFSocketProtocolBrokenException(String msg) {
// super(msg);
// }
//
// public int getErrCode() {
// return 64;
// }
// }
//
// Path: src/wtf/socket/util/WTFSocketPriority.java
// public final class WTFSocketPriority {
//
// private WTFSocketPriority() {
// }
//
// public final static int HIGHEST = -3;
// public final static int HIGH = -2;
// public final static int MEDIUM_HIGH = -1;
// public final static int MEDIUM = 0;
// public final static int MEDIUM_LOW = 1;
// public final static int LOW = 2;
// public final static int LOWEST = 3;
//
// }
| import wtf.socket.exception.fatal.WTFSocketProtocolBrokenException;
import wtf.socket.util.WTFSocketPriority; | package wtf.socket.protocol;
/**
* 协议解析器接口
* <p>
* Created by ZFly on 2017/4/21.
*/
public interface WTFSocketProtocolParser {
/**
* 优先级
*
* @return 优先级
*/
default int getPriority() {
return WTFSocketPriority.MEDIUM;
}
/**
* 是否负责该字符串数据
*
* @param data 原始数据
*
* @return 是否负责
*/
boolean isResponse(String data);
/**
* 是否负责该消息对象
*
* @param msg 消息对象
*
* @return 是否负责
*/
boolean isResponse(WTFSocketMsg msg);
/**
* 从字符串数据中解析数据生产消息对象
*
* @param data 原始数据
*
* @return 消息对象
*/ | // Path: src/wtf/socket/exception/fatal/WTFSocketProtocolBrokenException.java
// public class WTFSocketProtocolBrokenException extends WTFSocketFatalException {
//
// public WTFSocketProtocolBrokenException(String msg) {
// super(msg);
// }
//
// public int getErrCode() {
// return 64;
// }
// }
//
// Path: src/wtf/socket/util/WTFSocketPriority.java
// public final class WTFSocketPriority {
//
// private WTFSocketPriority() {
// }
//
// public final static int HIGHEST = -3;
// public final static int HIGH = -2;
// public final static int MEDIUM_HIGH = -1;
// public final static int MEDIUM = 0;
// public final static int MEDIUM_LOW = 1;
// public final static int LOW = 2;
// public final static int LOWEST = 3;
//
// }
// Path: src/wtf/socket/protocol/WTFSocketProtocolParser.java
import wtf.socket.exception.fatal.WTFSocketProtocolBrokenException;
import wtf.socket.util.WTFSocketPriority;
package wtf.socket.protocol;
/**
* 协议解析器接口
* <p>
* Created by ZFly on 2017/4/21.
*/
public interface WTFSocketProtocolParser {
/**
* 优先级
*
* @return 优先级
*/
default int getPriority() {
return WTFSocketPriority.MEDIUM;
}
/**
* 是否负责该字符串数据
*
* @param data 原始数据
*
* @return 是否负责
*/
boolean isResponse(String data);
/**
* 是否负责该消息对象
*
* @param msg 消息对象
*
* @return 是否负责
*/
boolean isResponse(WTFSocketMsg msg);
/**
* 从字符串数据中解析数据生产消息对象
*
* @param data 原始数据
*
* @return 消息对象
*/ | WTFSocketMsg parse(String data) throws WTFSocketProtocolBrokenException; |
ZhangFly/WTFSocket_Server_JAVA | src/wtf/socket/util/WTFSocketLogUtils.java | // Path: src/wtf/socket/WTFSocketServer.java
// public final class WTFSocketServer {
//
// /**
// * Spring 上下文
// */
// private ApplicationContext spring = new ClassPathXmlApplicationContext("spring.wtf.socket.xml");
//
// /**
// * 消息调度组件
// * 根据消息的头信息将消息投递到指定的目的地
// */
// @Resource()
// private WTFSocketScheduler scheduler;
//
// /**
// * 路由组件
// * 查询和记录连接的地址
// */
// @Resource
// private WTFSocketRouting routing;
//
// /**
// * 协议族组件
// * IO层收到数据后选择合适的解析器将数据解析为标准消息格式
// */
// @Resource
// private WTFSocketProtocolFamily protocolFamily;
//
// /**
// * 安全组件
// * 可用添加一些安全策略,如发送数据的授权许可等
// */
// @Resource
// private WTFSocketSecureDelegatesGroup secureDelegatesGroup;
//
// /**
// * 事件组组件
// * 包含了一些服务器的监听事件
// */
// @Resource
// private WTFSocketEventListenersGroup eventsGroup;
//
// /**
// * 服务器配置
// */
// private WTFSocketConfig config;
//
// public WTFSocketServer() {
// spring.getAutowireCapableBeanFactory().autowireBean(this);
// scheduler.setContext(this);
// routing.setContext(this);
// }
//
// public void run(WTFSocketConfig config) {
// this.config = config;
// scheduler.run();
// }
//
// public WTFSocketServer addController(WTFSocketController controller) {
// if (scheduler.getHandler() instanceof WTFSocketControllersGroup) {
// ((WTFSocketControllersGroup) scheduler.getHandler()).addController(controller);
// }
// return this;
// }
//
// public WTFSocketScheduler getScheduler() {
// return scheduler;
// }
//
// public WTFSocketProtocolFamily getProtocolFamily() {
// return protocolFamily;
// }
//
// public WTFSocketSecureDelegatesGroup getSecureDelegatesGroup() {
// return secureDelegatesGroup;
// }
//
// public WTFSocketRouting getRouting() {
// return routing;
// }
//
// public WTFSocketEventListenersGroup getEventsGroup() {
// return eventsGroup;
// }
//
// public WTFSocketConfig getConfig() {
// return config;
// }
//
// public void setScheduler(WTFSocketScheduler scheduler) {
// this.scheduler = scheduler;
// }
//
// public void setProtocolFamily(WTFSocketProtocolFamily protocolFamily) {
// this.protocolFamily = protocolFamily;
// }
//
// public void setSecureDelegatesGroup(WTFSocketSecureDelegatesGroup secureDelegatesGroup) {
// this.secureDelegatesGroup = secureDelegatesGroup;
// }
//
// public void setRouting(WTFSocketRouting routing) {
// this.routing = routing;
// }
//
// public void setEventsGroup(WTFSocketEventListenersGroup eventsGroup) {
// this.eventsGroup = eventsGroup;
// }
//
// public WTFSocketConfig setConfig() {
// return config;
// }
//
//
// public ApplicationContext getSpring() {
// return spring;
// }
// }
//
// Path: src/wtf/socket/protocol/WTFSocketMsg.java
// public interface WTFSocketMsg {
//
// String getIoTag();
//
// void setIoTag(String ioTag);
//
// String getFrom();
//
// void setFrom(String from);
//
// String getTo();
//
// void setTo(String to);
//
// int getMsgId();
//
// void setMsgId(int msgId);
//
// int getMsgType();
//
// void setMsgType(int msgType);
//
// int getState();
//
// void setState(int state);
//
// void setConnectType(String connectType);
//
// String getConnectType();
//
// String getVersion();
//
// void setVersion(String version);
//
// Object getBody();
//
// <T> T getBody(Class<T> tClass);
//
// void setBody(Object body);
//
// WTFSocketMsg makeResponse();
// }
| import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import wtf.socket.WTFSocketServer;
import wtf.socket.protocol.WTFSocketMsg;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date; | package wtf.socket.util;
/**
* 调试信息辅助日志工具类
* <p>
* Created by ZFly on 2017/4/21.
*/
public final class WTFSocketLogUtils {
private WTFSocketLogUtils() {
}
private static final Log logger = LogFactory.getLog(WTFSocketLogUtils.class);
| // Path: src/wtf/socket/WTFSocketServer.java
// public final class WTFSocketServer {
//
// /**
// * Spring 上下文
// */
// private ApplicationContext spring = new ClassPathXmlApplicationContext("spring.wtf.socket.xml");
//
// /**
// * 消息调度组件
// * 根据消息的头信息将消息投递到指定的目的地
// */
// @Resource()
// private WTFSocketScheduler scheduler;
//
// /**
// * 路由组件
// * 查询和记录连接的地址
// */
// @Resource
// private WTFSocketRouting routing;
//
// /**
// * 协议族组件
// * IO层收到数据后选择合适的解析器将数据解析为标准消息格式
// */
// @Resource
// private WTFSocketProtocolFamily protocolFamily;
//
// /**
// * 安全组件
// * 可用添加一些安全策略,如发送数据的授权许可等
// */
// @Resource
// private WTFSocketSecureDelegatesGroup secureDelegatesGroup;
//
// /**
// * 事件组组件
// * 包含了一些服务器的监听事件
// */
// @Resource
// private WTFSocketEventListenersGroup eventsGroup;
//
// /**
// * 服务器配置
// */
// private WTFSocketConfig config;
//
// public WTFSocketServer() {
// spring.getAutowireCapableBeanFactory().autowireBean(this);
// scheduler.setContext(this);
// routing.setContext(this);
// }
//
// public void run(WTFSocketConfig config) {
// this.config = config;
// scheduler.run();
// }
//
// public WTFSocketServer addController(WTFSocketController controller) {
// if (scheduler.getHandler() instanceof WTFSocketControllersGroup) {
// ((WTFSocketControllersGroup) scheduler.getHandler()).addController(controller);
// }
// return this;
// }
//
// public WTFSocketScheduler getScheduler() {
// return scheduler;
// }
//
// public WTFSocketProtocolFamily getProtocolFamily() {
// return protocolFamily;
// }
//
// public WTFSocketSecureDelegatesGroup getSecureDelegatesGroup() {
// return secureDelegatesGroup;
// }
//
// public WTFSocketRouting getRouting() {
// return routing;
// }
//
// public WTFSocketEventListenersGroup getEventsGroup() {
// return eventsGroup;
// }
//
// public WTFSocketConfig getConfig() {
// return config;
// }
//
// public void setScheduler(WTFSocketScheduler scheduler) {
// this.scheduler = scheduler;
// }
//
// public void setProtocolFamily(WTFSocketProtocolFamily protocolFamily) {
// this.protocolFamily = protocolFamily;
// }
//
// public void setSecureDelegatesGroup(WTFSocketSecureDelegatesGroup secureDelegatesGroup) {
// this.secureDelegatesGroup = secureDelegatesGroup;
// }
//
// public void setRouting(WTFSocketRouting routing) {
// this.routing = routing;
// }
//
// public void setEventsGroup(WTFSocketEventListenersGroup eventsGroup) {
// this.eventsGroup = eventsGroup;
// }
//
// public WTFSocketConfig setConfig() {
// return config;
// }
//
//
// public ApplicationContext getSpring() {
// return spring;
// }
// }
//
// Path: src/wtf/socket/protocol/WTFSocketMsg.java
// public interface WTFSocketMsg {
//
// String getIoTag();
//
// void setIoTag(String ioTag);
//
// String getFrom();
//
// void setFrom(String from);
//
// String getTo();
//
// void setTo(String to);
//
// int getMsgId();
//
// void setMsgId(int msgId);
//
// int getMsgType();
//
// void setMsgType(int msgType);
//
// int getState();
//
// void setState(int state);
//
// void setConnectType(String connectType);
//
// String getConnectType();
//
// String getVersion();
//
// void setVersion(String version);
//
// Object getBody();
//
// <T> T getBody(Class<T> tClass);
//
// void setBody(Object body);
//
// WTFSocketMsg makeResponse();
// }
// Path: src/wtf/socket/util/WTFSocketLogUtils.java
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import wtf.socket.WTFSocketServer;
import wtf.socket.protocol.WTFSocketMsg;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
package wtf.socket.util;
/**
* 调试信息辅助日志工具类
* <p>
* Created by ZFly on 2017/4/21.
*/
public final class WTFSocketLogUtils {
private WTFSocketLogUtils() {
}
private static final Log logger = LogFactory.getLog(WTFSocketLogUtils.class);
| public static void received(WTFSocketServer context, String packet, WTFSocketMsg msg) { |
ZhangFly/WTFSocket_Server_JAVA | src/wtf/socket/util/WTFSocketLogUtils.java | // Path: src/wtf/socket/WTFSocketServer.java
// public final class WTFSocketServer {
//
// /**
// * Spring 上下文
// */
// private ApplicationContext spring = new ClassPathXmlApplicationContext("spring.wtf.socket.xml");
//
// /**
// * 消息调度组件
// * 根据消息的头信息将消息投递到指定的目的地
// */
// @Resource()
// private WTFSocketScheduler scheduler;
//
// /**
// * 路由组件
// * 查询和记录连接的地址
// */
// @Resource
// private WTFSocketRouting routing;
//
// /**
// * 协议族组件
// * IO层收到数据后选择合适的解析器将数据解析为标准消息格式
// */
// @Resource
// private WTFSocketProtocolFamily protocolFamily;
//
// /**
// * 安全组件
// * 可用添加一些安全策略,如发送数据的授权许可等
// */
// @Resource
// private WTFSocketSecureDelegatesGroup secureDelegatesGroup;
//
// /**
// * 事件组组件
// * 包含了一些服务器的监听事件
// */
// @Resource
// private WTFSocketEventListenersGroup eventsGroup;
//
// /**
// * 服务器配置
// */
// private WTFSocketConfig config;
//
// public WTFSocketServer() {
// spring.getAutowireCapableBeanFactory().autowireBean(this);
// scheduler.setContext(this);
// routing.setContext(this);
// }
//
// public void run(WTFSocketConfig config) {
// this.config = config;
// scheduler.run();
// }
//
// public WTFSocketServer addController(WTFSocketController controller) {
// if (scheduler.getHandler() instanceof WTFSocketControllersGroup) {
// ((WTFSocketControllersGroup) scheduler.getHandler()).addController(controller);
// }
// return this;
// }
//
// public WTFSocketScheduler getScheduler() {
// return scheduler;
// }
//
// public WTFSocketProtocolFamily getProtocolFamily() {
// return protocolFamily;
// }
//
// public WTFSocketSecureDelegatesGroup getSecureDelegatesGroup() {
// return secureDelegatesGroup;
// }
//
// public WTFSocketRouting getRouting() {
// return routing;
// }
//
// public WTFSocketEventListenersGroup getEventsGroup() {
// return eventsGroup;
// }
//
// public WTFSocketConfig getConfig() {
// return config;
// }
//
// public void setScheduler(WTFSocketScheduler scheduler) {
// this.scheduler = scheduler;
// }
//
// public void setProtocolFamily(WTFSocketProtocolFamily protocolFamily) {
// this.protocolFamily = protocolFamily;
// }
//
// public void setSecureDelegatesGroup(WTFSocketSecureDelegatesGroup secureDelegatesGroup) {
// this.secureDelegatesGroup = secureDelegatesGroup;
// }
//
// public void setRouting(WTFSocketRouting routing) {
// this.routing = routing;
// }
//
// public void setEventsGroup(WTFSocketEventListenersGroup eventsGroup) {
// this.eventsGroup = eventsGroup;
// }
//
// public WTFSocketConfig setConfig() {
// return config;
// }
//
//
// public ApplicationContext getSpring() {
// return spring;
// }
// }
//
// Path: src/wtf/socket/protocol/WTFSocketMsg.java
// public interface WTFSocketMsg {
//
// String getIoTag();
//
// void setIoTag(String ioTag);
//
// String getFrom();
//
// void setFrom(String from);
//
// String getTo();
//
// void setTo(String to);
//
// int getMsgId();
//
// void setMsgId(int msgId);
//
// int getMsgType();
//
// void setMsgType(int msgType);
//
// int getState();
//
// void setState(int state);
//
// void setConnectType(String connectType);
//
// String getConnectType();
//
// String getVersion();
//
// void setVersion(String version);
//
// Object getBody();
//
// <T> T getBody(Class<T> tClass);
//
// void setBody(Object body);
//
// WTFSocketMsg makeResponse();
// }
| import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import wtf.socket.WTFSocketServer;
import wtf.socket.protocol.WTFSocketMsg;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date; | package wtf.socket.util;
/**
* 调试信息辅助日志工具类
* <p>
* Created by ZFly on 2017/4/21.
*/
public final class WTFSocketLogUtils {
private WTFSocketLogUtils() {
}
private static final Log logger = LogFactory.getLog(WTFSocketLogUtils.class);
| // Path: src/wtf/socket/WTFSocketServer.java
// public final class WTFSocketServer {
//
// /**
// * Spring 上下文
// */
// private ApplicationContext spring = new ClassPathXmlApplicationContext("spring.wtf.socket.xml");
//
// /**
// * 消息调度组件
// * 根据消息的头信息将消息投递到指定的目的地
// */
// @Resource()
// private WTFSocketScheduler scheduler;
//
// /**
// * 路由组件
// * 查询和记录连接的地址
// */
// @Resource
// private WTFSocketRouting routing;
//
// /**
// * 协议族组件
// * IO层收到数据后选择合适的解析器将数据解析为标准消息格式
// */
// @Resource
// private WTFSocketProtocolFamily protocolFamily;
//
// /**
// * 安全组件
// * 可用添加一些安全策略,如发送数据的授权许可等
// */
// @Resource
// private WTFSocketSecureDelegatesGroup secureDelegatesGroup;
//
// /**
// * 事件组组件
// * 包含了一些服务器的监听事件
// */
// @Resource
// private WTFSocketEventListenersGroup eventsGroup;
//
// /**
// * 服务器配置
// */
// private WTFSocketConfig config;
//
// public WTFSocketServer() {
// spring.getAutowireCapableBeanFactory().autowireBean(this);
// scheduler.setContext(this);
// routing.setContext(this);
// }
//
// public void run(WTFSocketConfig config) {
// this.config = config;
// scheduler.run();
// }
//
// public WTFSocketServer addController(WTFSocketController controller) {
// if (scheduler.getHandler() instanceof WTFSocketControllersGroup) {
// ((WTFSocketControllersGroup) scheduler.getHandler()).addController(controller);
// }
// return this;
// }
//
// public WTFSocketScheduler getScheduler() {
// return scheduler;
// }
//
// public WTFSocketProtocolFamily getProtocolFamily() {
// return protocolFamily;
// }
//
// public WTFSocketSecureDelegatesGroup getSecureDelegatesGroup() {
// return secureDelegatesGroup;
// }
//
// public WTFSocketRouting getRouting() {
// return routing;
// }
//
// public WTFSocketEventListenersGroup getEventsGroup() {
// return eventsGroup;
// }
//
// public WTFSocketConfig getConfig() {
// return config;
// }
//
// public void setScheduler(WTFSocketScheduler scheduler) {
// this.scheduler = scheduler;
// }
//
// public void setProtocolFamily(WTFSocketProtocolFamily protocolFamily) {
// this.protocolFamily = protocolFamily;
// }
//
// public void setSecureDelegatesGroup(WTFSocketSecureDelegatesGroup secureDelegatesGroup) {
// this.secureDelegatesGroup = secureDelegatesGroup;
// }
//
// public void setRouting(WTFSocketRouting routing) {
// this.routing = routing;
// }
//
// public void setEventsGroup(WTFSocketEventListenersGroup eventsGroup) {
// this.eventsGroup = eventsGroup;
// }
//
// public WTFSocketConfig setConfig() {
// return config;
// }
//
//
// public ApplicationContext getSpring() {
// return spring;
// }
// }
//
// Path: src/wtf/socket/protocol/WTFSocketMsg.java
// public interface WTFSocketMsg {
//
// String getIoTag();
//
// void setIoTag(String ioTag);
//
// String getFrom();
//
// void setFrom(String from);
//
// String getTo();
//
// void setTo(String to);
//
// int getMsgId();
//
// void setMsgId(int msgId);
//
// int getMsgType();
//
// void setMsgType(int msgType);
//
// int getState();
//
// void setState(int state);
//
// void setConnectType(String connectType);
//
// String getConnectType();
//
// String getVersion();
//
// void setVersion(String version);
//
// Object getBody();
//
// <T> T getBody(Class<T> tClass);
//
// void setBody(Object body);
//
// WTFSocketMsg makeResponse();
// }
// Path: src/wtf/socket/util/WTFSocketLogUtils.java
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import wtf.socket.WTFSocketServer;
import wtf.socket.protocol.WTFSocketMsg;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
package wtf.socket.util;
/**
* 调试信息辅助日志工具类
* <p>
* Created by ZFly on 2017/4/21.
*/
public final class WTFSocketLogUtils {
private WTFSocketLogUtils() {
}
private static final Log logger = LogFactory.getLog(WTFSocketLogUtils.class);
| public static void received(WTFSocketServer context, String packet, WTFSocketMsg msg) { |
ZhangFly/WTFSocket_Server_JAVA | src/wtf/socket/routing/item/WTFSocketRoutingFormalItem.java | // Path: src/wtf/socket/exception/WTFSocketException.java
// public abstract class WTFSocketException extends Exception {
//
//
// public WTFSocketException(String msg) {
// super(msg);
// }
//
// public abstract int getErrCode();
//
// }
| import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import wtf.socket.exception.WTFSocketException;
import java.util.HashSet;
import java.util.Set; | package wtf.socket.routing.item;
/**
* 正式客户端
* <p>
* Created by ZFly on 2017/4/23.
*/
@Component
@Scope("prototype")
public class WTFSocketRoutingFormalItem extends WTFSocketRoutingItem {
/**
* 授权通讯地址
*/
private Set<String> authTargetsAddress;
public boolean isAuthTarget(String targetAddress) {
return authTargetsAddress != null && (authTargetsAddress.contains("*") || authTargetsAddress.contains(targetAddress));
}
public void addAuthTarget(String targetAddress) {
if (authTargetsAddress == null) {
authTargetsAddress = new HashSet<String>() {{
add("server");
}};
}
authTargetsAddress.add(targetAddress);
}
public void removeAuthTarget(String targetAddress) {
if (authTargetsAddress != null) {
authTargetsAddress.remove(targetAddress);
}
}
| // Path: src/wtf/socket/exception/WTFSocketException.java
// public abstract class WTFSocketException extends Exception {
//
//
// public WTFSocketException(String msg) {
// super(msg);
// }
//
// public abstract int getErrCode();
//
// }
// Path: src/wtf/socket/routing/item/WTFSocketRoutingFormalItem.java
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import wtf.socket.exception.WTFSocketException;
import java.util.HashSet;
import java.util.Set;
package wtf.socket.routing.item;
/**
* 正式客户端
* <p>
* Created by ZFly on 2017/4/23.
*/
@Component
@Scope("prototype")
public class WTFSocketRoutingFormalItem extends WTFSocketRoutingItem {
/**
* 授权通讯地址
*/
private Set<String> authTargetsAddress;
public boolean isAuthTarget(String targetAddress) {
return authTargetsAddress != null && (authTargetsAddress.contains("*") || authTargetsAddress.contains(targetAddress));
}
public void addAuthTarget(String targetAddress) {
if (authTargetsAddress == null) {
authTargetsAddress = new HashSet<String>() {{
add("server");
}};
}
authTargetsAddress.add(targetAddress);
}
public void removeAuthTarget(String targetAddress) {
if (authTargetsAddress != null) {
authTargetsAddress.remove(targetAddress);
}
}
| public void close() throws WTFSocketException { |
ZhangFly/WTFSocket_Server_JAVA | src/wtf/socket/secure/strategy/impl/WTFSocketContainsSourceSecureStrategyImpl.java | // Path: src/wtf/socket/WTFSocketServer.java
// public final class WTFSocketServer {
//
// /**
// * Spring 上下文
// */
// private ApplicationContext spring = new ClassPathXmlApplicationContext("spring.wtf.socket.xml");
//
// /**
// * 消息调度组件
// * 根据消息的头信息将消息投递到指定的目的地
// */
// @Resource()
// private WTFSocketScheduler scheduler;
//
// /**
// * 路由组件
// * 查询和记录连接的地址
// */
// @Resource
// private WTFSocketRouting routing;
//
// /**
// * 协议族组件
// * IO层收到数据后选择合适的解析器将数据解析为标准消息格式
// */
// @Resource
// private WTFSocketProtocolFamily protocolFamily;
//
// /**
// * 安全组件
// * 可用添加一些安全策略,如发送数据的授权许可等
// */
// @Resource
// private WTFSocketSecureDelegatesGroup secureDelegatesGroup;
//
// /**
// * 事件组组件
// * 包含了一些服务器的监听事件
// */
// @Resource
// private WTFSocketEventListenersGroup eventsGroup;
//
// /**
// * 服务器配置
// */
// private WTFSocketConfig config;
//
// public WTFSocketServer() {
// spring.getAutowireCapableBeanFactory().autowireBean(this);
// scheduler.setContext(this);
// routing.setContext(this);
// }
//
// public void run(WTFSocketConfig config) {
// this.config = config;
// scheduler.run();
// }
//
// public WTFSocketServer addController(WTFSocketController controller) {
// if (scheduler.getHandler() instanceof WTFSocketControllersGroup) {
// ((WTFSocketControllersGroup) scheduler.getHandler()).addController(controller);
// }
// return this;
// }
//
// public WTFSocketScheduler getScheduler() {
// return scheduler;
// }
//
// public WTFSocketProtocolFamily getProtocolFamily() {
// return protocolFamily;
// }
//
// public WTFSocketSecureDelegatesGroup getSecureDelegatesGroup() {
// return secureDelegatesGroup;
// }
//
// public WTFSocketRouting getRouting() {
// return routing;
// }
//
// public WTFSocketEventListenersGroup getEventsGroup() {
// return eventsGroup;
// }
//
// public WTFSocketConfig getConfig() {
// return config;
// }
//
// public void setScheduler(WTFSocketScheduler scheduler) {
// this.scheduler = scheduler;
// }
//
// public void setProtocolFamily(WTFSocketProtocolFamily protocolFamily) {
// this.protocolFamily = protocolFamily;
// }
//
// public void setSecureDelegatesGroup(WTFSocketSecureDelegatesGroup secureDelegatesGroup) {
// this.secureDelegatesGroup = secureDelegatesGroup;
// }
//
// public void setRouting(WTFSocketRouting routing) {
// this.routing = routing;
// }
//
// public void setEventsGroup(WTFSocketEventListenersGroup eventsGroup) {
// this.eventsGroup = eventsGroup;
// }
//
// public WTFSocketConfig setConfig() {
// return config;
// }
//
//
// public ApplicationContext getSpring() {
// return spring;
// }
// }
//
// Path: src/wtf/socket/exception/WTFSocketException.java
// public abstract class WTFSocketException extends Exception {
//
//
// public WTFSocketException(String msg) {
// super(msg);
// }
//
// public abstract int getErrCode();
//
// }
//
// Path: src/wtf/socket/exception/fatal/WTFSocketInvalidSourceException.java
// public class WTFSocketInvalidSourceException extends WTFSocketFatalException {
//
// public WTFSocketInvalidSourceException(String msg) {
// super(msg);
// }
//
// @Override
// public int getErrCode() {
// return 66;
// }
// }
//
// Path: src/wtf/socket/protocol/WTFSocketMsg.java
// public interface WTFSocketMsg {
//
// String getIoTag();
//
// void setIoTag(String ioTag);
//
// String getFrom();
//
// void setFrom(String from);
//
// String getTo();
//
// void setTo(String to);
//
// int getMsgId();
//
// void setMsgId(int msgId);
//
// int getMsgType();
//
// void setMsgType(int msgType);
//
// int getState();
//
// void setState(int state);
//
// void setConnectType(String connectType);
//
// String getConnectType();
//
// String getVersion();
//
// void setVersion(String version);
//
// Object getBody();
//
// <T> T getBody(Class<T> tClass);
//
// void setBody(Object body);
//
// WTFSocketMsg makeResponse();
// }
| import org.springframework.stereotype.Component;
import wtf.socket.WTFSocketServer;
import wtf.socket.exception.WTFSocketException;
import wtf.socket.exception.fatal.WTFSocketInvalidSourceException;
import wtf.socket.protocol.WTFSocketMsg; | package wtf.socket.secure.strategy.impl;
/**
* 发送源是否已注册为正式客户端
* <p>
* Created by ZFly on 2017/4/25.
*/
@Component
public final class WTFSocketContainsSourceSecureStrategyImpl extends WTFSocketBaseSecureStrategyImpl {
@Override | // Path: src/wtf/socket/WTFSocketServer.java
// public final class WTFSocketServer {
//
// /**
// * Spring 上下文
// */
// private ApplicationContext spring = new ClassPathXmlApplicationContext("spring.wtf.socket.xml");
//
// /**
// * 消息调度组件
// * 根据消息的头信息将消息投递到指定的目的地
// */
// @Resource()
// private WTFSocketScheduler scheduler;
//
// /**
// * 路由组件
// * 查询和记录连接的地址
// */
// @Resource
// private WTFSocketRouting routing;
//
// /**
// * 协议族组件
// * IO层收到数据后选择合适的解析器将数据解析为标准消息格式
// */
// @Resource
// private WTFSocketProtocolFamily protocolFamily;
//
// /**
// * 安全组件
// * 可用添加一些安全策略,如发送数据的授权许可等
// */
// @Resource
// private WTFSocketSecureDelegatesGroup secureDelegatesGroup;
//
// /**
// * 事件组组件
// * 包含了一些服务器的监听事件
// */
// @Resource
// private WTFSocketEventListenersGroup eventsGroup;
//
// /**
// * 服务器配置
// */
// private WTFSocketConfig config;
//
// public WTFSocketServer() {
// spring.getAutowireCapableBeanFactory().autowireBean(this);
// scheduler.setContext(this);
// routing.setContext(this);
// }
//
// public void run(WTFSocketConfig config) {
// this.config = config;
// scheduler.run();
// }
//
// public WTFSocketServer addController(WTFSocketController controller) {
// if (scheduler.getHandler() instanceof WTFSocketControllersGroup) {
// ((WTFSocketControllersGroup) scheduler.getHandler()).addController(controller);
// }
// return this;
// }
//
// public WTFSocketScheduler getScheduler() {
// return scheduler;
// }
//
// public WTFSocketProtocolFamily getProtocolFamily() {
// return protocolFamily;
// }
//
// public WTFSocketSecureDelegatesGroup getSecureDelegatesGroup() {
// return secureDelegatesGroup;
// }
//
// public WTFSocketRouting getRouting() {
// return routing;
// }
//
// public WTFSocketEventListenersGroup getEventsGroup() {
// return eventsGroup;
// }
//
// public WTFSocketConfig getConfig() {
// return config;
// }
//
// public void setScheduler(WTFSocketScheduler scheduler) {
// this.scheduler = scheduler;
// }
//
// public void setProtocolFamily(WTFSocketProtocolFamily protocolFamily) {
// this.protocolFamily = protocolFamily;
// }
//
// public void setSecureDelegatesGroup(WTFSocketSecureDelegatesGroup secureDelegatesGroup) {
// this.secureDelegatesGroup = secureDelegatesGroup;
// }
//
// public void setRouting(WTFSocketRouting routing) {
// this.routing = routing;
// }
//
// public void setEventsGroup(WTFSocketEventListenersGroup eventsGroup) {
// this.eventsGroup = eventsGroup;
// }
//
// public WTFSocketConfig setConfig() {
// return config;
// }
//
//
// public ApplicationContext getSpring() {
// return spring;
// }
// }
//
// Path: src/wtf/socket/exception/WTFSocketException.java
// public abstract class WTFSocketException extends Exception {
//
//
// public WTFSocketException(String msg) {
// super(msg);
// }
//
// public abstract int getErrCode();
//
// }
//
// Path: src/wtf/socket/exception/fatal/WTFSocketInvalidSourceException.java
// public class WTFSocketInvalidSourceException extends WTFSocketFatalException {
//
// public WTFSocketInvalidSourceException(String msg) {
// super(msg);
// }
//
// @Override
// public int getErrCode() {
// return 66;
// }
// }
//
// Path: src/wtf/socket/protocol/WTFSocketMsg.java
// public interface WTFSocketMsg {
//
// String getIoTag();
//
// void setIoTag(String ioTag);
//
// String getFrom();
//
// void setFrom(String from);
//
// String getTo();
//
// void setTo(String to);
//
// int getMsgId();
//
// void setMsgId(int msgId);
//
// int getMsgType();
//
// void setMsgType(int msgType);
//
// int getState();
//
// void setState(int state);
//
// void setConnectType(String connectType);
//
// String getConnectType();
//
// String getVersion();
//
// void setVersion(String version);
//
// Object getBody();
//
// <T> T getBody(Class<T> tClass);
//
// void setBody(Object body);
//
// WTFSocketMsg makeResponse();
// }
// Path: src/wtf/socket/secure/strategy/impl/WTFSocketContainsSourceSecureStrategyImpl.java
import org.springframework.stereotype.Component;
import wtf.socket.WTFSocketServer;
import wtf.socket.exception.WTFSocketException;
import wtf.socket.exception.fatal.WTFSocketInvalidSourceException;
import wtf.socket.protocol.WTFSocketMsg;
package wtf.socket.secure.strategy.impl;
/**
* 发送源是否已注册为正式客户端
* <p>
* Created by ZFly on 2017/4/25.
*/
@Component
public final class WTFSocketContainsSourceSecureStrategyImpl extends WTFSocketBaseSecureStrategyImpl {
@Override | public void check(WTFSocketServer context, WTFSocketMsg msg) throws WTFSocketException { |
ZhangFly/WTFSocket_Server_JAVA | src/wtf/socket/secure/strategy/impl/WTFSocketContainsSourceSecureStrategyImpl.java | // Path: src/wtf/socket/WTFSocketServer.java
// public final class WTFSocketServer {
//
// /**
// * Spring 上下文
// */
// private ApplicationContext spring = new ClassPathXmlApplicationContext("spring.wtf.socket.xml");
//
// /**
// * 消息调度组件
// * 根据消息的头信息将消息投递到指定的目的地
// */
// @Resource()
// private WTFSocketScheduler scheduler;
//
// /**
// * 路由组件
// * 查询和记录连接的地址
// */
// @Resource
// private WTFSocketRouting routing;
//
// /**
// * 协议族组件
// * IO层收到数据后选择合适的解析器将数据解析为标准消息格式
// */
// @Resource
// private WTFSocketProtocolFamily protocolFamily;
//
// /**
// * 安全组件
// * 可用添加一些安全策略,如发送数据的授权许可等
// */
// @Resource
// private WTFSocketSecureDelegatesGroup secureDelegatesGroup;
//
// /**
// * 事件组组件
// * 包含了一些服务器的监听事件
// */
// @Resource
// private WTFSocketEventListenersGroup eventsGroup;
//
// /**
// * 服务器配置
// */
// private WTFSocketConfig config;
//
// public WTFSocketServer() {
// spring.getAutowireCapableBeanFactory().autowireBean(this);
// scheduler.setContext(this);
// routing.setContext(this);
// }
//
// public void run(WTFSocketConfig config) {
// this.config = config;
// scheduler.run();
// }
//
// public WTFSocketServer addController(WTFSocketController controller) {
// if (scheduler.getHandler() instanceof WTFSocketControllersGroup) {
// ((WTFSocketControllersGroup) scheduler.getHandler()).addController(controller);
// }
// return this;
// }
//
// public WTFSocketScheduler getScheduler() {
// return scheduler;
// }
//
// public WTFSocketProtocolFamily getProtocolFamily() {
// return protocolFamily;
// }
//
// public WTFSocketSecureDelegatesGroup getSecureDelegatesGroup() {
// return secureDelegatesGroup;
// }
//
// public WTFSocketRouting getRouting() {
// return routing;
// }
//
// public WTFSocketEventListenersGroup getEventsGroup() {
// return eventsGroup;
// }
//
// public WTFSocketConfig getConfig() {
// return config;
// }
//
// public void setScheduler(WTFSocketScheduler scheduler) {
// this.scheduler = scheduler;
// }
//
// public void setProtocolFamily(WTFSocketProtocolFamily protocolFamily) {
// this.protocolFamily = protocolFamily;
// }
//
// public void setSecureDelegatesGroup(WTFSocketSecureDelegatesGroup secureDelegatesGroup) {
// this.secureDelegatesGroup = secureDelegatesGroup;
// }
//
// public void setRouting(WTFSocketRouting routing) {
// this.routing = routing;
// }
//
// public void setEventsGroup(WTFSocketEventListenersGroup eventsGroup) {
// this.eventsGroup = eventsGroup;
// }
//
// public WTFSocketConfig setConfig() {
// return config;
// }
//
//
// public ApplicationContext getSpring() {
// return spring;
// }
// }
//
// Path: src/wtf/socket/exception/WTFSocketException.java
// public abstract class WTFSocketException extends Exception {
//
//
// public WTFSocketException(String msg) {
// super(msg);
// }
//
// public abstract int getErrCode();
//
// }
//
// Path: src/wtf/socket/exception/fatal/WTFSocketInvalidSourceException.java
// public class WTFSocketInvalidSourceException extends WTFSocketFatalException {
//
// public WTFSocketInvalidSourceException(String msg) {
// super(msg);
// }
//
// @Override
// public int getErrCode() {
// return 66;
// }
// }
//
// Path: src/wtf/socket/protocol/WTFSocketMsg.java
// public interface WTFSocketMsg {
//
// String getIoTag();
//
// void setIoTag(String ioTag);
//
// String getFrom();
//
// void setFrom(String from);
//
// String getTo();
//
// void setTo(String to);
//
// int getMsgId();
//
// void setMsgId(int msgId);
//
// int getMsgType();
//
// void setMsgType(int msgType);
//
// int getState();
//
// void setState(int state);
//
// void setConnectType(String connectType);
//
// String getConnectType();
//
// String getVersion();
//
// void setVersion(String version);
//
// Object getBody();
//
// <T> T getBody(Class<T> tClass);
//
// void setBody(Object body);
//
// WTFSocketMsg makeResponse();
// }
| import org.springframework.stereotype.Component;
import wtf.socket.WTFSocketServer;
import wtf.socket.exception.WTFSocketException;
import wtf.socket.exception.fatal.WTFSocketInvalidSourceException;
import wtf.socket.protocol.WTFSocketMsg; | package wtf.socket.secure.strategy.impl;
/**
* 发送源是否已注册为正式客户端
* <p>
* Created by ZFly on 2017/4/25.
*/
@Component
public final class WTFSocketContainsSourceSecureStrategyImpl extends WTFSocketBaseSecureStrategyImpl {
@Override | // Path: src/wtf/socket/WTFSocketServer.java
// public final class WTFSocketServer {
//
// /**
// * Spring 上下文
// */
// private ApplicationContext spring = new ClassPathXmlApplicationContext("spring.wtf.socket.xml");
//
// /**
// * 消息调度组件
// * 根据消息的头信息将消息投递到指定的目的地
// */
// @Resource()
// private WTFSocketScheduler scheduler;
//
// /**
// * 路由组件
// * 查询和记录连接的地址
// */
// @Resource
// private WTFSocketRouting routing;
//
// /**
// * 协议族组件
// * IO层收到数据后选择合适的解析器将数据解析为标准消息格式
// */
// @Resource
// private WTFSocketProtocolFamily protocolFamily;
//
// /**
// * 安全组件
// * 可用添加一些安全策略,如发送数据的授权许可等
// */
// @Resource
// private WTFSocketSecureDelegatesGroup secureDelegatesGroup;
//
// /**
// * 事件组组件
// * 包含了一些服务器的监听事件
// */
// @Resource
// private WTFSocketEventListenersGroup eventsGroup;
//
// /**
// * 服务器配置
// */
// private WTFSocketConfig config;
//
// public WTFSocketServer() {
// spring.getAutowireCapableBeanFactory().autowireBean(this);
// scheduler.setContext(this);
// routing.setContext(this);
// }
//
// public void run(WTFSocketConfig config) {
// this.config = config;
// scheduler.run();
// }
//
// public WTFSocketServer addController(WTFSocketController controller) {
// if (scheduler.getHandler() instanceof WTFSocketControllersGroup) {
// ((WTFSocketControllersGroup) scheduler.getHandler()).addController(controller);
// }
// return this;
// }
//
// public WTFSocketScheduler getScheduler() {
// return scheduler;
// }
//
// public WTFSocketProtocolFamily getProtocolFamily() {
// return protocolFamily;
// }
//
// public WTFSocketSecureDelegatesGroup getSecureDelegatesGroup() {
// return secureDelegatesGroup;
// }
//
// public WTFSocketRouting getRouting() {
// return routing;
// }
//
// public WTFSocketEventListenersGroup getEventsGroup() {
// return eventsGroup;
// }
//
// public WTFSocketConfig getConfig() {
// return config;
// }
//
// public void setScheduler(WTFSocketScheduler scheduler) {
// this.scheduler = scheduler;
// }
//
// public void setProtocolFamily(WTFSocketProtocolFamily protocolFamily) {
// this.protocolFamily = protocolFamily;
// }
//
// public void setSecureDelegatesGroup(WTFSocketSecureDelegatesGroup secureDelegatesGroup) {
// this.secureDelegatesGroup = secureDelegatesGroup;
// }
//
// public void setRouting(WTFSocketRouting routing) {
// this.routing = routing;
// }
//
// public void setEventsGroup(WTFSocketEventListenersGroup eventsGroup) {
// this.eventsGroup = eventsGroup;
// }
//
// public WTFSocketConfig setConfig() {
// return config;
// }
//
//
// public ApplicationContext getSpring() {
// return spring;
// }
// }
//
// Path: src/wtf/socket/exception/WTFSocketException.java
// public abstract class WTFSocketException extends Exception {
//
//
// public WTFSocketException(String msg) {
// super(msg);
// }
//
// public abstract int getErrCode();
//
// }
//
// Path: src/wtf/socket/exception/fatal/WTFSocketInvalidSourceException.java
// public class WTFSocketInvalidSourceException extends WTFSocketFatalException {
//
// public WTFSocketInvalidSourceException(String msg) {
// super(msg);
// }
//
// @Override
// public int getErrCode() {
// return 66;
// }
// }
//
// Path: src/wtf/socket/protocol/WTFSocketMsg.java
// public interface WTFSocketMsg {
//
// String getIoTag();
//
// void setIoTag(String ioTag);
//
// String getFrom();
//
// void setFrom(String from);
//
// String getTo();
//
// void setTo(String to);
//
// int getMsgId();
//
// void setMsgId(int msgId);
//
// int getMsgType();
//
// void setMsgType(int msgType);
//
// int getState();
//
// void setState(int state);
//
// void setConnectType(String connectType);
//
// String getConnectType();
//
// String getVersion();
//
// void setVersion(String version);
//
// Object getBody();
//
// <T> T getBody(Class<T> tClass);
//
// void setBody(Object body);
//
// WTFSocketMsg makeResponse();
// }
// Path: src/wtf/socket/secure/strategy/impl/WTFSocketContainsSourceSecureStrategyImpl.java
import org.springframework.stereotype.Component;
import wtf.socket.WTFSocketServer;
import wtf.socket.exception.WTFSocketException;
import wtf.socket.exception.fatal.WTFSocketInvalidSourceException;
import wtf.socket.protocol.WTFSocketMsg;
package wtf.socket.secure.strategy.impl;
/**
* 发送源是否已注册为正式客户端
* <p>
* Created by ZFly on 2017/4/25.
*/
@Component
public final class WTFSocketContainsSourceSecureStrategyImpl extends WTFSocketBaseSecureStrategyImpl {
@Override | public void check(WTFSocketServer context, WTFSocketMsg msg) throws WTFSocketException { |
ZhangFly/WTFSocket_Server_JAVA | src/wtf/socket/secure/strategy/impl/WTFSocketContainsSourceSecureStrategyImpl.java | // Path: src/wtf/socket/WTFSocketServer.java
// public final class WTFSocketServer {
//
// /**
// * Spring 上下文
// */
// private ApplicationContext spring = new ClassPathXmlApplicationContext("spring.wtf.socket.xml");
//
// /**
// * 消息调度组件
// * 根据消息的头信息将消息投递到指定的目的地
// */
// @Resource()
// private WTFSocketScheduler scheduler;
//
// /**
// * 路由组件
// * 查询和记录连接的地址
// */
// @Resource
// private WTFSocketRouting routing;
//
// /**
// * 协议族组件
// * IO层收到数据后选择合适的解析器将数据解析为标准消息格式
// */
// @Resource
// private WTFSocketProtocolFamily protocolFamily;
//
// /**
// * 安全组件
// * 可用添加一些安全策略,如发送数据的授权许可等
// */
// @Resource
// private WTFSocketSecureDelegatesGroup secureDelegatesGroup;
//
// /**
// * 事件组组件
// * 包含了一些服务器的监听事件
// */
// @Resource
// private WTFSocketEventListenersGroup eventsGroup;
//
// /**
// * 服务器配置
// */
// private WTFSocketConfig config;
//
// public WTFSocketServer() {
// spring.getAutowireCapableBeanFactory().autowireBean(this);
// scheduler.setContext(this);
// routing.setContext(this);
// }
//
// public void run(WTFSocketConfig config) {
// this.config = config;
// scheduler.run();
// }
//
// public WTFSocketServer addController(WTFSocketController controller) {
// if (scheduler.getHandler() instanceof WTFSocketControllersGroup) {
// ((WTFSocketControllersGroup) scheduler.getHandler()).addController(controller);
// }
// return this;
// }
//
// public WTFSocketScheduler getScheduler() {
// return scheduler;
// }
//
// public WTFSocketProtocolFamily getProtocolFamily() {
// return protocolFamily;
// }
//
// public WTFSocketSecureDelegatesGroup getSecureDelegatesGroup() {
// return secureDelegatesGroup;
// }
//
// public WTFSocketRouting getRouting() {
// return routing;
// }
//
// public WTFSocketEventListenersGroup getEventsGroup() {
// return eventsGroup;
// }
//
// public WTFSocketConfig getConfig() {
// return config;
// }
//
// public void setScheduler(WTFSocketScheduler scheduler) {
// this.scheduler = scheduler;
// }
//
// public void setProtocolFamily(WTFSocketProtocolFamily protocolFamily) {
// this.protocolFamily = protocolFamily;
// }
//
// public void setSecureDelegatesGroup(WTFSocketSecureDelegatesGroup secureDelegatesGroup) {
// this.secureDelegatesGroup = secureDelegatesGroup;
// }
//
// public void setRouting(WTFSocketRouting routing) {
// this.routing = routing;
// }
//
// public void setEventsGroup(WTFSocketEventListenersGroup eventsGroup) {
// this.eventsGroup = eventsGroup;
// }
//
// public WTFSocketConfig setConfig() {
// return config;
// }
//
//
// public ApplicationContext getSpring() {
// return spring;
// }
// }
//
// Path: src/wtf/socket/exception/WTFSocketException.java
// public abstract class WTFSocketException extends Exception {
//
//
// public WTFSocketException(String msg) {
// super(msg);
// }
//
// public abstract int getErrCode();
//
// }
//
// Path: src/wtf/socket/exception/fatal/WTFSocketInvalidSourceException.java
// public class WTFSocketInvalidSourceException extends WTFSocketFatalException {
//
// public WTFSocketInvalidSourceException(String msg) {
// super(msg);
// }
//
// @Override
// public int getErrCode() {
// return 66;
// }
// }
//
// Path: src/wtf/socket/protocol/WTFSocketMsg.java
// public interface WTFSocketMsg {
//
// String getIoTag();
//
// void setIoTag(String ioTag);
//
// String getFrom();
//
// void setFrom(String from);
//
// String getTo();
//
// void setTo(String to);
//
// int getMsgId();
//
// void setMsgId(int msgId);
//
// int getMsgType();
//
// void setMsgType(int msgType);
//
// int getState();
//
// void setState(int state);
//
// void setConnectType(String connectType);
//
// String getConnectType();
//
// String getVersion();
//
// void setVersion(String version);
//
// Object getBody();
//
// <T> T getBody(Class<T> tClass);
//
// void setBody(Object body);
//
// WTFSocketMsg makeResponse();
// }
| import org.springframework.stereotype.Component;
import wtf.socket.WTFSocketServer;
import wtf.socket.exception.WTFSocketException;
import wtf.socket.exception.fatal.WTFSocketInvalidSourceException;
import wtf.socket.protocol.WTFSocketMsg; | package wtf.socket.secure.strategy.impl;
/**
* 发送源是否已注册为正式客户端
* <p>
* Created by ZFly on 2017/4/25.
*/
@Component
public final class WTFSocketContainsSourceSecureStrategyImpl extends WTFSocketBaseSecureStrategyImpl {
@Override | // Path: src/wtf/socket/WTFSocketServer.java
// public final class WTFSocketServer {
//
// /**
// * Spring 上下文
// */
// private ApplicationContext spring = new ClassPathXmlApplicationContext("spring.wtf.socket.xml");
//
// /**
// * 消息调度组件
// * 根据消息的头信息将消息投递到指定的目的地
// */
// @Resource()
// private WTFSocketScheduler scheduler;
//
// /**
// * 路由组件
// * 查询和记录连接的地址
// */
// @Resource
// private WTFSocketRouting routing;
//
// /**
// * 协议族组件
// * IO层收到数据后选择合适的解析器将数据解析为标准消息格式
// */
// @Resource
// private WTFSocketProtocolFamily protocolFamily;
//
// /**
// * 安全组件
// * 可用添加一些安全策略,如发送数据的授权许可等
// */
// @Resource
// private WTFSocketSecureDelegatesGroup secureDelegatesGroup;
//
// /**
// * 事件组组件
// * 包含了一些服务器的监听事件
// */
// @Resource
// private WTFSocketEventListenersGroup eventsGroup;
//
// /**
// * 服务器配置
// */
// private WTFSocketConfig config;
//
// public WTFSocketServer() {
// spring.getAutowireCapableBeanFactory().autowireBean(this);
// scheduler.setContext(this);
// routing.setContext(this);
// }
//
// public void run(WTFSocketConfig config) {
// this.config = config;
// scheduler.run();
// }
//
// public WTFSocketServer addController(WTFSocketController controller) {
// if (scheduler.getHandler() instanceof WTFSocketControllersGroup) {
// ((WTFSocketControllersGroup) scheduler.getHandler()).addController(controller);
// }
// return this;
// }
//
// public WTFSocketScheduler getScheduler() {
// return scheduler;
// }
//
// public WTFSocketProtocolFamily getProtocolFamily() {
// return protocolFamily;
// }
//
// public WTFSocketSecureDelegatesGroup getSecureDelegatesGroup() {
// return secureDelegatesGroup;
// }
//
// public WTFSocketRouting getRouting() {
// return routing;
// }
//
// public WTFSocketEventListenersGroup getEventsGroup() {
// return eventsGroup;
// }
//
// public WTFSocketConfig getConfig() {
// return config;
// }
//
// public void setScheduler(WTFSocketScheduler scheduler) {
// this.scheduler = scheduler;
// }
//
// public void setProtocolFamily(WTFSocketProtocolFamily protocolFamily) {
// this.protocolFamily = protocolFamily;
// }
//
// public void setSecureDelegatesGroup(WTFSocketSecureDelegatesGroup secureDelegatesGroup) {
// this.secureDelegatesGroup = secureDelegatesGroup;
// }
//
// public void setRouting(WTFSocketRouting routing) {
// this.routing = routing;
// }
//
// public void setEventsGroup(WTFSocketEventListenersGroup eventsGroup) {
// this.eventsGroup = eventsGroup;
// }
//
// public WTFSocketConfig setConfig() {
// return config;
// }
//
//
// public ApplicationContext getSpring() {
// return spring;
// }
// }
//
// Path: src/wtf/socket/exception/WTFSocketException.java
// public abstract class WTFSocketException extends Exception {
//
//
// public WTFSocketException(String msg) {
// super(msg);
// }
//
// public abstract int getErrCode();
//
// }
//
// Path: src/wtf/socket/exception/fatal/WTFSocketInvalidSourceException.java
// public class WTFSocketInvalidSourceException extends WTFSocketFatalException {
//
// public WTFSocketInvalidSourceException(String msg) {
// super(msg);
// }
//
// @Override
// public int getErrCode() {
// return 66;
// }
// }
//
// Path: src/wtf/socket/protocol/WTFSocketMsg.java
// public interface WTFSocketMsg {
//
// String getIoTag();
//
// void setIoTag(String ioTag);
//
// String getFrom();
//
// void setFrom(String from);
//
// String getTo();
//
// void setTo(String to);
//
// int getMsgId();
//
// void setMsgId(int msgId);
//
// int getMsgType();
//
// void setMsgType(int msgType);
//
// int getState();
//
// void setState(int state);
//
// void setConnectType(String connectType);
//
// String getConnectType();
//
// String getVersion();
//
// void setVersion(String version);
//
// Object getBody();
//
// <T> T getBody(Class<T> tClass);
//
// void setBody(Object body);
//
// WTFSocketMsg makeResponse();
// }
// Path: src/wtf/socket/secure/strategy/impl/WTFSocketContainsSourceSecureStrategyImpl.java
import org.springframework.stereotype.Component;
import wtf.socket.WTFSocketServer;
import wtf.socket.exception.WTFSocketException;
import wtf.socket.exception.fatal.WTFSocketInvalidSourceException;
import wtf.socket.protocol.WTFSocketMsg;
package wtf.socket.secure.strategy.impl;
/**
* 发送源是否已注册为正式客户端
* <p>
* Created by ZFly on 2017/4/25.
*/
@Component
public final class WTFSocketContainsSourceSecureStrategyImpl extends WTFSocketBaseSecureStrategyImpl {
@Override | public void check(WTFSocketServer context, WTFSocketMsg msg) throws WTFSocketException { |
ZhangFly/WTFSocket_Server_JAVA | src/wtf/socket/exception/normal/WTFSocketNormalException.java | // Path: src/wtf/socket/exception/WTFSocketException.java
// public abstract class WTFSocketException extends Exception {
//
//
// public WTFSocketException(String msg) {
// super(msg);
// }
//
// public abstract int getErrCode();
//
// }
//
// Path: src/wtf/socket/protocol/WTFSocketMsg.java
// public interface WTFSocketMsg {
//
// String getIoTag();
//
// void setIoTag(String ioTag);
//
// String getFrom();
//
// void setFrom(String from);
//
// String getTo();
//
// void setTo(String to);
//
// int getMsgId();
//
// void setMsgId(int msgId);
//
// int getMsgType();
//
// void setMsgType(int msgType);
//
// int getState();
//
// void setState(int state);
//
// void setConnectType(String connectType);
//
// String getConnectType();
//
// String getVersion();
//
// void setVersion(String version);
//
// Object getBody();
//
// <T> T getBody(Class<T> tClass);
//
// void setBody(Object body);
//
// WTFSocketMsg makeResponse();
// }
| import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import wtf.socket.exception.WTFSocketException;
import wtf.socket.protocol.WTFSocketMsg; | package wtf.socket.exception.normal;
/**
* 普通异常
* 一般指协议已被正常解析
* 可回溯发送源的异常
*
* Created by ZFly on 2017/4/22.
*/
public abstract class WTFSocketNormalException extends WTFSocketException {
private static final Log logger = LogFactory.getLog(WTFSocketNormalException.class);
/**
* 造成异常的源数据
*/ | // Path: src/wtf/socket/exception/WTFSocketException.java
// public abstract class WTFSocketException extends Exception {
//
//
// public WTFSocketException(String msg) {
// super(msg);
// }
//
// public abstract int getErrCode();
//
// }
//
// Path: src/wtf/socket/protocol/WTFSocketMsg.java
// public interface WTFSocketMsg {
//
// String getIoTag();
//
// void setIoTag(String ioTag);
//
// String getFrom();
//
// void setFrom(String from);
//
// String getTo();
//
// void setTo(String to);
//
// int getMsgId();
//
// void setMsgId(int msgId);
//
// int getMsgType();
//
// void setMsgType(int msgType);
//
// int getState();
//
// void setState(int state);
//
// void setConnectType(String connectType);
//
// String getConnectType();
//
// String getVersion();
//
// void setVersion(String version);
//
// Object getBody();
//
// <T> T getBody(Class<T> tClass);
//
// void setBody(Object body);
//
// WTFSocketMsg makeResponse();
// }
// Path: src/wtf/socket/exception/normal/WTFSocketNormalException.java
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import wtf.socket.exception.WTFSocketException;
import wtf.socket.protocol.WTFSocketMsg;
package wtf.socket.exception.normal;
/**
* 普通异常
* 一般指协议已被正常解析
* 可回溯发送源的异常
*
* Created by ZFly on 2017/4/22.
*/
public abstract class WTFSocketNormalException extends WTFSocketException {
private static final Log logger = LogFactory.getLog(WTFSocketNormalException.class);
/**
* 造成异常的源数据
*/ | private WTFSocketMsg originalMsg; |
ZhangFly/WTFSocket_Server_JAVA | src/wtf/socket/io/netty/WTFSocketNettyBooterImpl.java | // Path: src/wtf/socket/WTFSocketServer.java
// public final class WTFSocketServer {
//
// /**
// * Spring 上下文
// */
// private ApplicationContext spring = new ClassPathXmlApplicationContext("spring.wtf.socket.xml");
//
// /**
// * 消息调度组件
// * 根据消息的头信息将消息投递到指定的目的地
// */
// @Resource()
// private WTFSocketScheduler scheduler;
//
// /**
// * 路由组件
// * 查询和记录连接的地址
// */
// @Resource
// private WTFSocketRouting routing;
//
// /**
// * 协议族组件
// * IO层收到数据后选择合适的解析器将数据解析为标准消息格式
// */
// @Resource
// private WTFSocketProtocolFamily protocolFamily;
//
// /**
// * 安全组件
// * 可用添加一些安全策略,如发送数据的授权许可等
// */
// @Resource
// private WTFSocketSecureDelegatesGroup secureDelegatesGroup;
//
// /**
// * 事件组组件
// * 包含了一些服务器的监听事件
// */
// @Resource
// private WTFSocketEventListenersGroup eventsGroup;
//
// /**
// * 服务器配置
// */
// private WTFSocketConfig config;
//
// public WTFSocketServer() {
// spring.getAutowireCapableBeanFactory().autowireBean(this);
// scheduler.setContext(this);
// routing.setContext(this);
// }
//
// public void run(WTFSocketConfig config) {
// this.config = config;
// scheduler.run();
// }
//
// public WTFSocketServer addController(WTFSocketController controller) {
// if (scheduler.getHandler() instanceof WTFSocketControllersGroup) {
// ((WTFSocketControllersGroup) scheduler.getHandler()).addController(controller);
// }
// return this;
// }
//
// public WTFSocketScheduler getScheduler() {
// return scheduler;
// }
//
// public WTFSocketProtocolFamily getProtocolFamily() {
// return protocolFamily;
// }
//
// public WTFSocketSecureDelegatesGroup getSecureDelegatesGroup() {
// return secureDelegatesGroup;
// }
//
// public WTFSocketRouting getRouting() {
// return routing;
// }
//
// public WTFSocketEventListenersGroup getEventsGroup() {
// return eventsGroup;
// }
//
// public WTFSocketConfig getConfig() {
// return config;
// }
//
// public void setScheduler(WTFSocketScheduler scheduler) {
// this.scheduler = scheduler;
// }
//
// public void setProtocolFamily(WTFSocketProtocolFamily protocolFamily) {
// this.protocolFamily = protocolFamily;
// }
//
// public void setSecureDelegatesGroup(WTFSocketSecureDelegatesGroup secureDelegatesGroup) {
// this.secureDelegatesGroup = secureDelegatesGroup;
// }
//
// public void setRouting(WTFSocketRouting routing) {
// this.routing = routing;
// }
//
// public void setEventsGroup(WTFSocketEventListenersGroup eventsGroup) {
// this.eventsGroup = eventsGroup;
// }
//
// public WTFSocketConfig setConfig() {
// return config;
// }
//
//
// public ApplicationContext getSpring() {
// return spring;
// }
// }
//
// Path: src/wtf/socket/event/WTFSocketEventListener.java
// @FunctionalInterface
// public interface WTFSocketEventListener {
// void eventOccurred(WTFSocketRoutingItem item, Object info) throws WTFSocketException;
// }
//
// Path: src/wtf/socket/io/WTFSocketIOBooter.java
// public interface WTFSocketIOBooter {
// void work(Map<String, Object> config);
// }
| import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelOption;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.nio.NioServerSocketChannel;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.stereotype.Component;
import wtf.socket.WTFSocketServer;
import wtf.socket.event.WTFSocketEventListener;
import wtf.socket.io.WTFSocketIOBooter;
import java.util.Map; | package wtf.socket.io.netty;
/**
* Netty 启动器
* <p>
* Created by ZFly on 2017/4/25.
*/
@Component("wtf.socket.nettyBooter")
public class WTFSocketNettyBooterImpl implements WTFSocketIOBooter {
private static final Log logger = LogFactory.getLog(WTFSocketNettyBooterImpl.class);
public void work(Map<String, Object> config) { | // Path: src/wtf/socket/WTFSocketServer.java
// public final class WTFSocketServer {
//
// /**
// * Spring 上下文
// */
// private ApplicationContext spring = new ClassPathXmlApplicationContext("spring.wtf.socket.xml");
//
// /**
// * 消息调度组件
// * 根据消息的头信息将消息投递到指定的目的地
// */
// @Resource()
// private WTFSocketScheduler scheduler;
//
// /**
// * 路由组件
// * 查询和记录连接的地址
// */
// @Resource
// private WTFSocketRouting routing;
//
// /**
// * 协议族组件
// * IO层收到数据后选择合适的解析器将数据解析为标准消息格式
// */
// @Resource
// private WTFSocketProtocolFamily protocolFamily;
//
// /**
// * 安全组件
// * 可用添加一些安全策略,如发送数据的授权许可等
// */
// @Resource
// private WTFSocketSecureDelegatesGroup secureDelegatesGroup;
//
// /**
// * 事件组组件
// * 包含了一些服务器的监听事件
// */
// @Resource
// private WTFSocketEventListenersGroup eventsGroup;
//
// /**
// * 服务器配置
// */
// private WTFSocketConfig config;
//
// public WTFSocketServer() {
// spring.getAutowireCapableBeanFactory().autowireBean(this);
// scheduler.setContext(this);
// routing.setContext(this);
// }
//
// public void run(WTFSocketConfig config) {
// this.config = config;
// scheduler.run();
// }
//
// public WTFSocketServer addController(WTFSocketController controller) {
// if (scheduler.getHandler() instanceof WTFSocketControllersGroup) {
// ((WTFSocketControllersGroup) scheduler.getHandler()).addController(controller);
// }
// return this;
// }
//
// public WTFSocketScheduler getScheduler() {
// return scheduler;
// }
//
// public WTFSocketProtocolFamily getProtocolFamily() {
// return protocolFamily;
// }
//
// public WTFSocketSecureDelegatesGroup getSecureDelegatesGroup() {
// return secureDelegatesGroup;
// }
//
// public WTFSocketRouting getRouting() {
// return routing;
// }
//
// public WTFSocketEventListenersGroup getEventsGroup() {
// return eventsGroup;
// }
//
// public WTFSocketConfig getConfig() {
// return config;
// }
//
// public void setScheduler(WTFSocketScheduler scheduler) {
// this.scheduler = scheduler;
// }
//
// public void setProtocolFamily(WTFSocketProtocolFamily protocolFamily) {
// this.protocolFamily = protocolFamily;
// }
//
// public void setSecureDelegatesGroup(WTFSocketSecureDelegatesGroup secureDelegatesGroup) {
// this.secureDelegatesGroup = secureDelegatesGroup;
// }
//
// public void setRouting(WTFSocketRouting routing) {
// this.routing = routing;
// }
//
// public void setEventsGroup(WTFSocketEventListenersGroup eventsGroup) {
// this.eventsGroup = eventsGroup;
// }
//
// public WTFSocketConfig setConfig() {
// return config;
// }
//
//
// public ApplicationContext getSpring() {
// return spring;
// }
// }
//
// Path: src/wtf/socket/event/WTFSocketEventListener.java
// @FunctionalInterface
// public interface WTFSocketEventListener {
// void eventOccurred(WTFSocketRoutingItem item, Object info) throws WTFSocketException;
// }
//
// Path: src/wtf/socket/io/WTFSocketIOBooter.java
// public interface WTFSocketIOBooter {
// void work(Map<String, Object> config);
// }
// Path: src/wtf/socket/io/netty/WTFSocketNettyBooterImpl.java
import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelOption;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.nio.NioServerSocketChannel;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.stereotype.Component;
import wtf.socket.WTFSocketServer;
import wtf.socket.event.WTFSocketEventListener;
import wtf.socket.io.WTFSocketIOBooter;
import java.util.Map;
package wtf.socket.io.netty;
/**
* Netty 启动器
* <p>
* Created by ZFly on 2017/4/25.
*/
@Component("wtf.socket.nettyBooter")
public class WTFSocketNettyBooterImpl implements WTFSocketIOBooter {
private static final Log logger = LogFactory.getLog(WTFSocketNettyBooterImpl.class);
public void work(Map<String, Object> config) { | final WTFSocketServer context = (WTFSocketServer) config.get("context"); |
ZhangFly/WTFSocket_Server_JAVA | src/wtf/socket/io/netty/WTFSocketNettyBooterImpl.java | // Path: src/wtf/socket/WTFSocketServer.java
// public final class WTFSocketServer {
//
// /**
// * Spring 上下文
// */
// private ApplicationContext spring = new ClassPathXmlApplicationContext("spring.wtf.socket.xml");
//
// /**
// * 消息调度组件
// * 根据消息的头信息将消息投递到指定的目的地
// */
// @Resource()
// private WTFSocketScheduler scheduler;
//
// /**
// * 路由组件
// * 查询和记录连接的地址
// */
// @Resource
// private WTFSocketRouting routing;
//
// /**
// * 协议族组件
// * IO层收到数据后选择合适的解析器将数据解析为标准消息格式
// */
// @Resource
// private WTFSocketProtocolFamily protocolFamily;
//
// /**
// * 安全组件
// * 可用添加一些安全策略,如发送数据的授权许可等
// */
// @Resource
// private WTFSocketSecureDelegatesGroup secureDelegatesGroup;
//
// /**
// * 事件组组件
// * 包含了一些服务器的监听事件
// */
// @Resource
// private WTFSocketEventListenersGroup eventsGroup;
//
// /**
// * 服务器配置
// */
// private WTFSocketConfig config;
//
// public WTFSocketServer() {
// spring.getAutowireCapableBeanFactory().autowireBean(this);
// scheduler.setContext(this);
// routing.setContext(this);
// }
//
// public void run(WTFSocketConfig config) {
// this.config = config;
// scheduler.run();
// }
//
// public WTFSocketServer addController(WTFSocketController controller) {
// if (scheduler.getHandler() instanceof WTFSocketControllersGroup) {
// ((WTFSocketControllersGroup) scheduler.getHandler()).addController(controller);
// }
// return this;
// }
//
// public WTFSocketScheduler getScheduler() {
// return scheduler;
// }
//
// public WTFSocketProtocolFamily getProtocolFamily() {
// return protocolFamily;
// }
//
// public WTFSocketSecureDelegatesGroup getSecureDelegatesGroup() {
// return secureDelegatesGroup;
// }
//
// public WTFSocketRouting getRouting() {
// return routing;
// }
//
// public WTFSocketEventListenersGroup getEventsGroup() {
// return eventsGroup;
// }
//
// public WTFSocketConfig getConfig() {
// return config;
// }
//
// public void setScheduler(WTFSocketScheduler scheduler) {
// this.scheduler = scheduler;
// }
//
// public void setProtocolFamily(WTFSocketProtocolFamily protocolFamily) {
// this.protocolFamily = protocolFamily;
// }
//
// public void setSecureDelegatesGroup(WTFSocketSecureDelegatesGroup secureDelegatesGroup) {
// this.secureDelegatesGroup = secureDelegatesGroup;
// }
//
// public void setRouting(WTFSocketRouting routing) {
// this.routing = routing;
// }
//
// public void setEventsGroup(WTFSocketEventListenersGroup eventsGroup) {
// this.eventsGroup = eventsGroup;
// }
//
// public WTFSocketConfig setConfig() {
// return config;
// }
//
//
// public ApplicationContext getSpring() {
// return spring;
// }
// }
//
// Path: src/wtf/socket/event/WTFSocketEventListener.java
// @FunctionalInterface
// public interface WTFSocketEventListener {
// void eventOccurred(WTFSocketRoutingItem item, Object info) throws WTFSocketException;
// }
//
// Path: src/wtf/socket/io/WTFSocketIOBooter.java
// public interface WTFSocketIOBooter {
// void work(Map<String, Object> config);
// }
| import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelOption;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.nio.NioServerSocketChannel;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.stereotype.Component;
import wtf.socket.WTFSocketServer;
import wtf.socket.event.WTFSocketEventListener;
import wtf.socket.io.WTFSocketIOBooter;
import java.util.Map; | package wtf.socket.io.netty;
/**
* Netty 启动器
* <p>
* Created by ZFly on 2017/4/25.
*/
@Component("wtf.socket.nettyBooter")
public class WTFSocketNettyBooterImpl implements WTFSocketIOBooter {
private static final Log logger = LogFactory.getLog(WTFSocketNettyBooterImpl.class);
public void work(Map<String, Object> config) {
final WTFSocketServer context = (WTFSocketServer) config.get("context");
final Integer tcpPort = (Integer) config.get("tcpPort");
final Integer webSocketPort = (Integer) config.get("webSocketPort");
final Boolean keepAlive = (Boolean) config.get("keepAlive");
if (tcpPort != null && tcpPort > 0)
startTcpServer(context, tcpPort, keepAlive, (item, info) -> logger.info("Listening Port[TCP] on [" + tcpPort + "]..."));
if (webSocketPort != null && webSocketPort > 0)
startWebSocketServer(context, webSocketPort, keepAlive, (item, info) -> logger.info("Listening Port[WebSocket] on [" + webSocketPort + "]..."));
}
// 开启WebSocket服务器 | // Path: src/wtf/socket/WTFSocketServer.java
// public final class WTFSocketServer {
//
// /**
// * Spring 上下文
// */
// private ApplicationContext spring = new ClassPathXmlApplicationContext("spring.wtf.socket.xml");
//
// /**
// * 消息调度组件
// * 根据消息的头信息将消息投递到指定的目的地
// */
// @Resource()
// private WTFSocketScheduler scheduler;
//
// /**
// * 路由组件
// * 查询和记录连接的地址
// */
// @Resource
// private WTFSocketRouting routing;
//
// /**
// * 协议族组件
// * IO层收到数据后选择合适的解析器将数据解析为标准消息格式
// */
// @Resource
// private WTFSocketProtocolFamily protocolFamily;
//
// /**
// * 安全组件
// * 可用添加一些安全策略,如发送数据的授权许可等
// */
// @Resource
// private WTFSocketSecureDelegatesGroup secureDelegatesGroup;
//
// /**
// * 事件组组件
// * 包含了一些服务器的监听事件
// */
// @Resource
// private WTFSocketEventListenersGroup eventsGroup;
//
// /**
// * 服务器配置
// */
// private WTFSocketConfig config;
//
// public WTFSocketServer() {
// spring.getAutowireCapableBeanFactory().autowireBean(this);
// scheduler.setContext(this);
// routing.setContext(this);
// }
//
// public void run(WTFSocketConfig config) {
// this.config = config;
// scheduler.run();
// }
//
// public WTFSocketServer addController(WTFSocketController controller) {
// if (scheduler.getHandler() instanceof WTFSocketControllersGroup) {
// ((WTFSocketControllersGroup) scheduler.getHandler()).addController(controller);
// }
// return this;
// }
//
// public WTFSocketScheduler getScheduler() {
// return scheduler;
// }
//
// public WTFSocketProtocolFamily getProtocolFamily() {
// return protocolFamily;
// }
//
// public WTFSocketSecureDelegatesGroup getSecureDelegatesGroup() {
// return secureDelegatesGroup;
// }
//
// public WTFSocketRouting getRouting() {
// return routing;
// }
//
// public WTFSocketEventListenersGroup getEventsGroup() {
// return eventsGroup;
// }
//
// public WTFSocketConfig getConfig() {
// return config;
// }
//
// public void setScheduler(WTFSocketScheduler scheduler) {
// this.scheduler = scheduler;
// }
//
// public void setProtocolFamily(WTFSocketProtocolFamily protocolFamily) {
// this.protocolFamily = protocolFamily;
// }
//
// public void setSecureDelegatesGroup(WTFSocketSecureDelegatesGroup secureDelegatesGroup) {
// this.secureDelegatesGroup = secureDelegatesGroup;
// }
//
// public void setRouting(WTFSocketRouting routing) {
// this.routing = routing;
// }
//
// public void setEventsGroup(WTFSocketEventListenersGroup eventsGroup) {
// this.eventsGroup = eventsGroup;
// }
//
// public WTFSocketConfig setConfig() {
// return config;
// }
//
//
// public ApplicationContext getSpring() {
// return spring;
// }
// }
//
// Path: src/wtf/socket/event/WTFSocketEventListener.java
// @FunctionalInterface
// public interface WTFSocketEventListener {
// void eventOccurred(WTFSocketRoutingItem item, Object info) throws WTFSocketException;
// }
//
// Path: src/wtf/socket/io/WTFSocketIOBooter.java
// public interface WTFSocketIOBooter {
// void work(Map<String, Object> config);
// }
// Path: src/wtf/socket/io/netty/WTFSocketNettyBooterImpl.java
import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelOption;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.nio.NioServerSocketChannel;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.stereotype.Component;
import wtf.socket.WTFSocketServer;
import wtf.socket.event.WTFSocketEventListener;
import wtf.socket.io.WTFSocketIOBooter;
import java.util.Map;
package wtf.socket.io.netty;
/**
* Netty 启动器
* <p>
* Created by ZFly on 2017/4/25.
*/
@Component("wtf.socket.nettyBooter")
public class WTFSocketNettyBooterImpl implements WTFSocketIOBooter {
private static final Log logger = LogFactory.getLog(WTFSocketNettyBooterImpl.class);
public void work(Map<String, Object> config) {
final WTFSocketServer context = (WTFSocketServer) config.get("context");
final Integer tcpPort = (Integer) config.get("tcpPort");
final Integer webSocketPort = (Integer) config.get("webSocketPort");
final Boolean keepAlive = (Boolean) config.get("keepAlive");
if (tcpPort != null && tcpPort > 0)
startTcpServer(context, tcpPort, keepAlive, (item, info) -> logger.info("Listening Port[TCP] on [" + tcpPort + "]..."));
if (webSocketPort != null && webSocketPort > 0)
startWebSocketServer(context, webSocketPort, keepAlive, (item, info) -> logger.info("Listening Port[WebSocket] on [" + webSocketPort + "]..."));
}
// 开启WebSocket服务器 | private void startWebSocketServer(WTFSocketServer context, int port, boolean keepAlive, WTFSocketEventListener startedListener) { |
ZhangFly/WTFSocket_Server_JAVA | src/wtf/socket/protocol/msg/WTFSocketDefaultProtocolParser.java | // Path: src/wtf/socket/exception/fatal/WTFSocketProtocolBrokenException.java
// public class WTFSocketProtocolBrokenException extends WTFSocketFatalException {
//
// public WTFSocketProtocolBrokenException(String msg) {
// super(msg);
// }
//
// public int getErrCode() {
// return 64;
// }
// }
//
// Path: src/wtf/socket/protocol/WTFSocketMsg.java
// public interface WTFSocketMsg {
//
// String getIoTag();
//
// void setIoTag(String ioTag);
//
// String getFrom();
//
// void setFrom(String from);
//
// String getTo();
//
// void setTo(String to);
//
// int getMsgId();
//
// void setMsgId(int msgId);
//
// int getMsgType();
//
// void setMsgType(int msgType);
//
// int getState();
//
// void setState(int state);
//
// void setConnectType(String connectType);
//
// String getConnectType();
//
// String getVersion();
//
// void setVersion(String version);
//
// Object getBody();
//
// <T> T getBody(Class<T> tClass);
//
// void setBody(Object body);
//
// WTFSocketMsg makeResponse();
// }
//
// Path: src/wtf/socket/protocol/WTFSocketProtocolParser.java
// public interface WTFSocketProtocolParser {
//
// /**
// * 优先级
// *
// * @return 优先级
// */
// default int getPriority() {
// return WTFSocketPriority.MEDIUM;
// }
//
// /**
// * 是否负责该字符串数据
// *
// * @param data 原始数据
// *
// * @return 是否负责
// */
// boolean isResponse(String data);
//
// /**
// * 是否负责该消息对象
// *
// * @param msg 消息对象
// *
// * @return 是否负责
// */
// boolean isResponse(WTFSocketMsg msg);
//
// /**
// * 从字符串数据中解析数据生产消息对象
// *
// * @param data 原始数据
// *
// * @return 消息对象
// */
// WTFSocketMsg parse(String data) throws WTFSocketProtocolBrokenException;
//
// /**
// * 将消息对象打包成字符串数据
// *
// * @param msg 消息对象
// *
// * @return 打包后的字符串
// */
// String parse(WTFSocketMsg msg);
// }
//
// Path: src/wtf/socket/util/WTFSocketPriority.java
// public final class WTFSocketPriority {
//
// private WTFSocketPriority() {
// }
//
// public final static int HIGHEST = -3;
// public final static int HIGH = -2;
// public final static int MEDIUM_HIGH = -1;
// public final static int MEDIUM = 0;
// public final static int MEDIUM_LOW = 1;
// public final static int LOW = 2;
// public final static int LOWEST = 3;
//
// }
| import com.alibaba.fastjson.JSON;
import org.apache.commons.lang.StringUtils;
import wtf.socket.exception.fatal.WTFSocketProtocolBrokenException;
import wtf.socket.protocol.WTFSocketMsg;
import wtf.socket.protocol.WTFSocketProtocolParser;
import wtf.socket.util.WTFSocketPriority; | package wtf.socket.protocol.msg;
/**
* 默认协议解析器实现
* 支持 JSON 格式,使用 FastJson 进行转换
* 使用的实体类模板为 WTFSocketDefaultMsg
* 优先级为 WTFSocketPriority.LOWEST
* <p>
* Created by ZFly on 2017/4/21.
*/
public class WTFSocketDefaultProtocolParser implements WTFSocketProtocolParser {
@Override
public int getPriority() { | // Path: src/wtf/socket/exception/fatal/WTFSocketProtocolBrokenException.java
// public class WTFSocketProtocolBrokenException extends WTFSocketFatalException {
//
// public WTFSocketProtocolBrokenException(String msg) {
// super(msg);
// }
//
// public int getErrCode() {
// return 64;
// }
// }
//
// Path: src/wtf/socket/protocol/WTFSocketMsg.java
// public interface WTFSocketMsg {
//
// String getIoTag();
//
// void setIoTag(String ioTag);
//
// String getFrom();
//
// void setFrom(String from);
//
// String getTo();
//
// void setTo(String to);
//
// int getMsgId();
//
// void setMsgId(int msgId);
//
// int getMsgType();
//
// void setMsgType(int msgType);
//
// int getState();
//
// void setState(int state);
//
// void setConnectType(String connectType);
//
// String getConnectType();
//
// String getVersion();
//
// void setVersion(String version);
//
// Object getBody();
//
// <T> T getBody(Class<T> tClass);
//
// void setBody(Object body);
//
// WTFSocketMsg makeResponse();
// }
//
// Path: src/wtf/socket/protocol/WTFSocketProtocolParser.java
// public interface WTFSocketProtocolParser {
//
// /**
// * 优先级
// *
// * @return 优先级
// */
// default int getPriority() {
// return WTFSocketPriority.MEDIUM;
// }
//
// /**
// * 是否负责该字符串数据
// *
// * @param data 原始数据
// *
// * @return 是否负责
// */
// boolean isResponse(String data);
//
// /**
// * 是否负责该消息对象
// *
// * @param msg 消息对象
// *
// * @return 是否负责
// */
// boolean isResponse(WTFSocketMsg msg);
//
// /**
// * 从字符串数据中解析数据生产消息对象
// *
// * @param data 原始数据
// *
// * @return 消息对象
// */
// WTFSocketMsg parse(String data) throws WTFSocketProtocolBrokenException;
//
// /**
// * 将消息对象打包成字符串数据
// *
// * @param msg 消息对象
// *
// * @return 打包后的字符串
// */
// String parse(WTFSocketMsg msg);
// }
//
// Path: src/wtf/socket/util/WTFSocketPriority.java
// public final class WTFSocketPriority {
//
// private WTFSocketPriority() {
// }
//
// public final static int HIGHEST = -3;
// public final static int HIGH = -2;
// public final static int MEDIUM_HIGH = -1;
// public final static int MEDIUM = 0;
// public final static int MEDIUM_LOW = 1;
// public final static int LOW = 2;
// public final static int LOWEST = 3;
//
// }
// Path: src/wtf/socket/protocol/msg/WTFSocketDefaultProtocolParser.java
import com.alibaba.fastjson.JSON;
import org.apache.commons.lang.StringUtils;
import wtf.socket.exception.fatal.WTFSocketProtocolBrokenException;
import wtf.socket.protocol.WTFSocketMsg;
import wtf.socket.protocol.WTFSocketProtocolParser;
import wtf.socket.util.WTFSocketPriority;
package wtf.socket.protocol.msg;
/**
* 默认协议解析器实现
* 支持 JSON 格式,使用 FastJson 进行转换
* 使用的实体类模板为 WTFSocketDefaultMsg
* 优先级为 WTFSocketPriority.LOWEST
* <p>
* Created by ZFly on 2017/4/21.
*/
public class WTFSocketDefaultProtocolParser implements WTFSocketProtocolParser {
@Override
public int getPriority() { | return WTFSocketPriority.LOWEST; |
ZhangFly/WTFSocket_Server_JAVA | src/wtf/socket/protocol/msg/WTFSocketDefaultProtocolParser.java | // Path: src/wtf/socket/exception/fatal/WTFSocketProtocolBrokenException.java
// public class WTFSocketProtocolBrokenException extends WTFSocketFatalException {
//
// public WTFSocketProtocolBrokenException(String msg) {
// super(msg);
// }
//
// public int getErrCode() {
// return 64;
// }
// }
//
// Path: src/wtf/socket/protocol/WTFSocketMsg.java
// public interface WTFSocketMsg {
//
// String getIoTag();
//
// void setIoTag(String ioTag);
//
// String getFrom();
//
// void setFrom(String from);
//
// String getTo();
//
// void setTo(String to);
//
// int getMsgId();
//
// void setMsgId(int msgId);
//
// int getMsgType();
//
// void setMsgType(int msgType);
//
// int getState();
//
// void setState(int state);
//
// void setConnectType(String connectType);
//
// String getConnectType();
//
// String getVersion();
//
// void setVersion(String version);
//
// Object getBody();
//
// <T> T getBody(Class<T> tClass);
//
// void setBody(Object body);
//
// WTFSocketMsg makeResponse();
// }
//
// Path: src/wtf/socket/protocol/WTFSocketProtocolParser.java
// public interface WTFSocketProtocolParser {
//
// /**
// * 优先级
// *
// * @return 优先级
// */
// default int getPriority() {
// return WTFSocketPriority.MEDIUM;
// }
//
// /**
// * 是否负责该字符串数据
// *
// * @param data 原始数据
// *
// * @return 是否负责
// */
// boolean isResponse(String data);
//
// /**
// * 是否负责该消息对象
// *
// * @param msg 消息对象
// *
// * @return 是否负责
// */
// boolean isResponse(WTFSocketMsg msg);
//
// /**
// * 从字符串数据中解析数据生产消息对象
// *
// * @param data 原始数据
// *
// * @return 消息对象
// */
// WTFSocketMsg parse(String data) throws WTFSocketProtocolBrokenException;
//
// /**
// * 将消息对象打包成字符串数据
// *
// * @param msg 消息对象
// *
// * @return 打包后的字符串
// */
// String parse(WTFSocketMsg msg);
// }
//
// Path: src/wtf/socket/util/WTFSocketPriority.java
// public final class WTFSocketPriority {
//
// private WTFSocketPriority() {
// }
//
// public final static int HIGHEST = -3;
// public final static int HIGH = -2;
// public final static int MEDIUM_HIGH = -1;
// public final static int MEDIUM = 0;
// public final static int MEDIUM_LOW = 1;
// public final static int LOW = 2;
// public final static int LOWEST = 3;
//
// }
| import com.alibaba.fastjson.JSON;
import org.apache.commons.lang.StringUtils;
import wtf.socket.exception.fatal.WTFSocketProtocolBrokenException;
import wtf.socket.protocol.WTFSocketMsg;
import wtf.socket.protocol.WTFSocketProtocolParser;
import wtf.socket.util.WTFSocketPriority; | package wtf.socket.protocol.msg;
/**
* 默认协议解析器实现
* 支持 JSON 格式,使用 FastJson 进行转换
* 使用的实体类模板为 WTFSocketDefaultMsg
* 优先级为 WTFSocketPriority.LOWEST
* <p>
* Created by ZFly on 2017/4/21.
*/
public class WTFSocketDefaultProtocolParser implements WTFSocketProtocolParser {
@Override
public int getPriority() {
return WTFSocketPriority.LOWEST;
}
@Override
public boolean isResponse(String data) {
return StringUtils.startsWith(data, "{") && StringUtils.endsWith(data, "}");
}
@Override | // Path: src/wtf/socket/exception/fatal/WTFSocketProtocolBrokenException.java
// public class WTFSocketProtocolBrokenException extends WTFSocketFatalException {
//
// public WTFSocketProtocolBrokenException(String msg) {
// super(msg);
// }
//
// public int getErrCode() {
// return 64;
// }
// }
//
// Path: src/wtf/socket/protocol/WTFSocketMsg.java
// public interface WTFSocketMsg {
//
// String getIoTag();
//
// void setIoTag(String ioTag);
//
// String getFrom();
//
// void setFrom(String from);
//
// String getTo();
//
// void setTo(String to);
//
// int getMsgId();
//
// void setMsgId(int msgId);
//
// int getMsgType();
//
// void setMsgType(int msgType);
//
// int getState();
//
// void setState(int state);
//
// void setConnectType(String connectType);
//
// String getConnectType();
//
// String getVersion();
//
// void setVersion(String version);
//
// Object getBody();
//
// <T> T getBody(Class<T> tClass);
//
// void setBody(Object body);
//
// WTFSocketMsg makeResponse();
// }
//
// Path: src/wtf/socket/protocol/WTFSocketProtocolParser.java
// public interface WTFSocketProtocolParser {
//
// /**
// * 优先级
// *
// * @return 优先级
// */
// default int getPriority() {
// return WTFSocketPriority.MEDIUM;
// }
//
// /**
// * 是否负责该字符串数据
// *
// * @param data 原始数据
// *
// * @return 是否负责
// */
// boolean isResponse(String data);
//
// /**
// * 是否负责该消息对象
// *
// * @param msg 消息对象
// *
// * @return 是否负责
// */
// boolean isResponse(WTFSocketMsg msg);
//
// /**
// * 从字符串数据中解析数据生产消息对象
// *
// * @param data 原始数据
// *
// * @return 消息对象
// */
// WTFSocketMsg parse(String data) throws WTFSocketProtocolBrokenException;
//
// /**
// * 将消息对象打包成字符串数据
// *
// * @param msg 消息对象
// *
// * @return 打包后的字符串
// */
// String parse(WTFSocketMsg msg);
// }
//
// Path: src/wtf/socket/util/WTFSocketPriority.java
// public final class WTFSocketPriority {
//
// private WTFSocketPriority() {
// }
//
// public final static int HIGHEST = -3;
// public final static int HIGH = -2;
// public final static int MEDIUM_HIGH = -1;
// public final static int MEDIUM = 0;
// public final static int MEDIUM_LOW = 1;
// public final static int LOW = 2;
// public final static int LOWEST = 3;
//
// }
// Path: src/wtf/socket/protocol/msg/WTFSocketDefaultProtocolParser.java
import com.alibaba.fastjson.JSON;
import org.apache.commons.lang.StringUtils;
import wtf.socket.exception.fatal.WTFSocketProtocolBrokenException;
import wtf.socket.protocol.WTFSocketMsg;
import wtf.socket.protocol.WTFSocketProtocolParser;
import wtf.socket.util.WTFSocketPriority;
package wtf.socket.protocol.msg;
/**
* 默认协议解析器实现
* 支持 JSON 格式,使用 FastJson 进行转换
* 使用的实体类模板为 WTFSocketDefaultMsg
* 优先级为 WTFSocketPriority.LOWEST
* <p>
* Created by ZFly on 2017/4/21.
*/
public class WTFSocketDefaultProtocolParser implements WTFSocketProtocolParser {
@Override
public int getPriority() {
return WTFSocketPriority.LOWEST;
}
@Override
public boolean isResponse(String data) {
return StringUtils.startsWith(data, "{") && StringUtils.endsWith(data, "}");
}
@Override | public boolean isResponse(WTFSocketMsg msg) { |
ZhangFly/WTFSocket_Server_JAVA | src/wtf/socket/protocol/msg/WTFSocketDefaultProtocolParser.java | // Path: src/wtf/socket/exception/fatal/WTFSocketProtocolBrokenException.java
// public class WTFSocketProtocolBrokenException extends WTFSocketFatalException {
//
// public WTFSocketProtocolBrokenException(String msg) {
// super(msg);
// }
//
// public int getErrCode() {
// return 64;
// }
// }
//
// Path: src/wtf/socket/protocol/WTFSocketMsg.java
// public interface WTFSocketMsg {
//
// String getIoTag();
//
// void setIoTag(String ioTag);
//
// String getFrom();
//
// void setFrom(String from);
//
// String getTo();
//
// void setTo(String to);
//
// int getMsgId();
//
// void setMsgId(int msgId);
//
// int getMsgType();
//
// void setMsgType(int msgType);
//
// int getState();
//
// void setState(int state);
//
// void setConnectType(String connectType);
//
// String getConnectType();
//
// String getVersion();
//
// void setVersion(String version);
//
// Object getBody();
//
// <T> T getBody(Class<T> tClass);
//
// void setBody(Object body);
//
// WTFSocketMsg makeResponse();
// }
//
// Path: src/wtf/socket/protocol/WTFSocketProtocolParser.java
// public interface WTFSocketProtocolParser {
//
// /**
// * 优先级
// *
// * @return 优先级
// */
// default int getPriority() {
// return WTFSocketPriority.MEDIUM;
// }
//
// /**
// * 是否负责该字符串数据
// *
// * @param data 原始数据
// *
// * @return 是否负责
// */
// boolean isResponse(String data);
//
// /**
// * 是否负责该消息对象
// *
// * @param msg 消息对象
// *
// * @return 是否负责
// */
// boolean isResponse(WTFSocketMsg msg);
//
// /**
// * 从字符串数据中解析数据生产消息对象
// *
// * @param data 原始数据
// *
// * @return 消息对象
// */
// WTFSocketMsg parse(String data) throws WTFSocketProtocolBrokenException;
//
// /**
// * 将消息对象打包成字符串数据
// *
// * @param msg 消息对象
// *
// * @return 打包后的字符串
// */
// String parse(WTFSocketMsg msg);
// }
//
// Path: src/wtf/socket/util/WTFSocketPriority.java
// public final class WTFSocketPriority {
//
// private WTFSocketPriority() {
// }
//
// public final static int HIGHEST = -3;
// public final static int HIGH = -2;
// public final static int MEDIUM_HIGH = -1;
// public final static int MEDIUM = 0;
// public final static int MEDIUM_LOW = 1;
// public final static int LOW = 2;
// public final static int LOWEST = 3;
//
// }
| import com.alibaba.fastjson.JSON;
import org.apache.commons.lang.StringUtils;
import wtf.socket.exception.fatal.WTFSocketProtocolBrokenException;
import wtf.socket.protocol.WTFSocketMsg;
import wtf.socket.protocol.WTFSocketProtocolParser;
import wtf.socket.util.WTFSocketPriority; | package wtf.socket.protocol.msg;
/**
* 默认协议解析器实现
* 支持 JSON 格式,使用 FastJson 进行转换
* 使用的实体类模板为 WTFSocketDefaultMsg
* 优先级为 WTFSocketPriority.LOWEST
* <p>
* Created by ZFly on 2017/4/21.
*/
public class WTFSocketDefaultProtocolParser implements WTFSocketProtocolParser {
@Override
public int getPriority() {
return WTFSocketPriority.LOWEST;
}
@Override
public boolean isResponse(String data) {
return StringUtils.startsWith(data, "{") && StringUtils.endsWith(data, "}");
}
@Override
public boolean isResponse(WTFSocketMsg msg) {
return StringUtils.equals(msg.getVersion(), "2.0");
}
@Override | // Path: src/wtf/socket/exception/fatal/WTFSocketProtocolBrokenException.java
// public class WTFSocketProtocolBrokenException extends WTFSocketFatalException {
//
// public WTFSocketProtocolBrokenException(String msg) {
// super(msg);
// }
//
// public int getErrCode() {
// return 64;
// }
// }
//
// Path: src/wtf/socket/protocol/WTFSocketMsg.java
// public interface WTFSocketMsg {
//
// String getIoTag();
//
// void setIoTag(String ioTag);
//
// String getFrom();
//
// void setFrom(String from);
//
// String getTo();
//
// void setTo(String to);
//
// int getMsgId();
//
// void setMsgId(int msgId);
//
// int getMsgType();
//
// void setMsgType(int msgType);
//
// int getState();
//
// void setState(int state);
//
// void setConnectType(String connectType);
//
// String getConnectType();
//
// String getVersion();
//
// void setVersion(String version);
//
// Object getBody();
//
// <T> T getBody(Class<T> tClass);
//
// void setBody(Object body);
//
// WTFSocketMsg makeResponse();
// }
//
// Path: src/wtf/socket/protocol/WTFSocketProtocolParser.java
// public interface WTFSocketProtocolParser {
//
// /**
// * 优先级
// *
// * @return 优先级
// */
// default int getPriority() {
// return WTFSocketPriority.MEDIUM;
// }
//
// /**
// * 是否负责该字符串数据
// *
// * @param data 原始数据
// *
// * @return 是否负责
// */
// boolean isResponse(String data);
//
// /**
// * 是否负责该消息对象
// *
// * @param msg 消息对象
// *
// * @return 是否负责
// */
// boolean isResponse(WTFSocketMsg msg);
//
// /**
// * 从字符串数据中解析数据生产消息对象
// *
// * @param data 原始数据
// *
// * @return 消息对象
// */
// WTFSocketMsg parse(String data) throws WTFSocketProtocolBrokenException;
//
// /**
// * 将消息对象打包成字符串数据
// *
// * @param msg 消息对象
// *
// * @return 打包后的字符串
// */
// String parse(WTFSocketMsg msg);
// }
//
// Path: src/wtf/socket/util/WTFSocketPriority.java
// public final class WTFSocketPriority {
//
// private WTFSocketPriority() {
// }
//
// public final static int HIGHEST = -3;
// public final static int HIGH = -2;
// public final static int MEDIUM_HIGH = -1;
// public final static int MEDIUM = 0;
// public final static int MEDIUM_LOW = 1;
// public final static int LOW = 2;
// public final static int LOWEST = 3;
//
// }
// Path: src/wtf/socket/protocol/msg/WTFSocketDefaultProtocolParser.java
import com.alibaba.fastjson.JSON;
import org.apache.commons.lang.StringUtils;
import wtf.socket.exception.fatal.WTFSocketProtocolBrokenException;
import wtf.socket.protocol.WTFSocketMsg;
import wtf.socket.protocol.WTFSocketProtocolParser;
import wtf.socket.util.WTFSocketPriority;
package wtf.socket.protocol.msg;
/**
* 默认协议解析器实现
* 支持 JSON 格式,使用 FastJson 进行转换
* 使用的实体类模板为 WTFSocketDefaultMsg
* 优先级为 WTFSocketPriority.LOWEST
* <p>
* Created by ZFly on 2017/4/21.
*/
public class WTFSocketDefaultProtocolParser implements WTFSocketProtocolParser {
@Override
public int getPriority() {
return WTFSocketPriority.LOWEST;
}
@Override
public boolean isResponse(String data) {
return StringUtils.startsWith(data, "{") && StringUtils.endsWith(data, "}");
}
@Override
public boolean isResponse(WTFSocketMsg msg) {
return StringUtils.equals(msg.getVersion(), "2.0");
}
@Override | public WTFSocketMsg parse(String data) throws WTFSocketProtocolBrokenException { |
ZhangFly/WTFSocket_Server_JAVA | src/wtf/socket/routing/WTFSocketRoutingItemMap.java | // Path: src/wtf/socket/exception/WTFSocketException.java
// public abstract class WTFSocketException extends Exception {
//
//
// public WTFSocketException(String msg) {
// super(msg);
// }
//
// public abstract int getErrCode();
//
// }
//
// Path: src/wtf/socket/exception/fatal/WTFSocketInvalidSourceException.java
// public class WTFSocketInvalidSourceException extends WTFSocketFatalException {
//
// public WTFSocketInvalidSourceException(String msg) {
// super(msg);
// }
//
// @Override
// public int getErrCode() {
// return 66;
// }
// }
//
// Path: src/wtf/socket/routing/item/WTFSocketRoutingItem.java
// @Component
// @Scope("prototype")
// public abstract class WTFSocketRoutingItem {
//
// /**
// * 自身通讯地址
// */
// private String address;
// /**
// * 终端对象
// */
// private WTFSocketIOTerm term;
// /**
// * 接受的协议类型
// */
// private String accept;
// /**
// * 终端类型(iOS, Android, Hardware)
// */
// private String deviceType = "Unknown";
// /**
// * 是否允许覆盖
// */
// private boolean cover = true;
// /**
// * 允许用户为客户端添加自定义Tag信息
// */
// private Object tag;
//
// private WTFSocketServer context;
//
// public void setAddress(String address) {
// this.address = address;
// }
//
// public String getAddress() {
// return address;
// }
//
// public String getAccept() {
// return accept;
// }
//
// public void setAccept(String accept) {
// this.accept = accept;
// }
//
// public String getDeviceType() {
// return deviceType;
// }
//
// public void setDeviceType(String deviceType) {
// this.deviceType = deviceType == null ? "Unknown" : deviceType;
// }
//
// public WTFSocketIOTerm getTerm() {
// return term;
// }
//
// public void setTerm(WTFSocketIOTerm term) {
// this.term = term;
// }
//
// public boolean isCover() {
// return cover;
// }
//
// public void setCover(boolean cover) {
// this.cover = cover;
// }
//
// public WTFSocketServer getContext() {
// return context;
// }
//
// public void setContext(WTFSocketServer context) {
// this.context = context;
// }
//
// public Object getTag() {
// return tag;
// }
//
// public void setTag(Object tag) {
// this.tag = tag;
// }
//
// public void close() throws WTFSocketException {
// getContext().getEventsGroup().publishEvent(this, null, WTFSocketEventsType.Disconnect);
// getTerm().close();
// }
// }
| import wtf.socket.exception.WTFSocketException;
import wtf.socket.exception.fatal.WTFSocketInvalidSourceException;
import wtf.socket.routing.item.WTFSocketRoutingItem;
import java.util.Collection;
import java.util.concurrent.ConcurrentHashMap; | package wtf.socket.routing;
/**
* 路由表
* <p>
* Created by ZFly on 2017/4/22.
*/
public class WTFSocketRoutingItemMap<T extends WTFSocketRoutingItem> {
private ConcurrentHashMap<String, T> ioAddressMap = new ConcurrentHashMap<>();
private ConcurrentHashMap<String, String> communicationAddressMap = new ConcurrentHashMap<>();
/**
* 向路由表中注册对象
* 如果对象地址不为空,则使用地址作为key
* 如果对象地址为空,则使用ioTag作为key
*
* @param newItem 路由表对象
*/ | // Path: src/wtf/socket/exception/WTFSocketException.java
// public abstract class WTFSocketException extends Exception {
//
//
// public WTFSocketException(String msg) {
// super(msg);
// }
//
// public abstract int getErrCode();
//
// }
//
// Path: src/wtf/socket/exception/fatal/WTFSocketInvalidSourceException.java
// public class WTFSocketInvalidSourceException extends WTFSocketFatalException {
//
// public WTFSocketInvalidSourceException(String msg) {
// super(msg);
// }
//
// @Override
// public int getErrCode() {
// return 66;
// }
// }
//
// Path: src/wtf/socket/routing/item/WTFSocketRoutingItem.java
// @Component
// @Scope("prototype")
// public abstract class WTFSocketRoutingItem {
//
// /**
// * 自身通讯地址
// */
// private String address;
// /**
// * 终端对象
// */
// private WTFSocketIOTerm term;
// /**
// * 接受的协议类型
// */
// private String accept;
// /**
// * 终端类型(iOS, Android, Hardware)
// */
// private String deviceType = "Unknown";
// /**
// * 是否允许覆盖
// */
// private boolean cover = true;
// /**
// * 允许用户为客户端添加自定义Tag信息
// */
// private Object tag;
//
// private WTFSocketServer context;
//
// public void setAddress(String address) {
// this.address = address;
// }
//
// public String getAddress() {
// return address;
// }
//
// public String getAccept() {
// return accept;
// }
//
// public void setAccept(String accept) {
// this.accept = accept;
// }
//
// public String getDeviceType() {
// return deviceType;
// }
//
// public void setDeviceType(String deviceType) {
// this.deviceType = deviceType == null ? "Unknown" : deviceType;
// }
//
// public WTFSocketIOTerm getTerm() {
// return term;
// }
//
// public void setTerm(WTFSocketIOTerm term) {
// this.term = term;
// }
//
// public boolean isCover() {
// return cover;
// }
//
// public void setCover(boolean cover) {
// this.cover = cover;
// }
//
// public WTFSocketServer getContext() {
// return context;
// }
//
// public void setContext(WTFSocketServer context) {
// this.context = context;
// }
//
// public Object getTag() {
// return tag;
// }
//
// public void setTag(Object tag) {
// this.tag = tag;
// }
//
// public void close() throws WTFSocketException {
// getContext().getEventsGroup().publishEvent(this, null, WTFSocketEventsType.Disconnect);
// getTerm().close();
// }
// }
// Path: src/wtf/socket/routing/WTFSocketRoutingItemMap.java
import wtf.socket.exception.WTFSocketException;
import wtf.socket.exception.fatal.WTFSocketInvalidSourceException;
import wtf.socket.routing.item.WTFSocketRoutingItem;
import java.util.Collection;
import java.util.concurrent.ConcurrentHashMap;
package wtf.socket.routing;
/**
* 路由表
* <p>
* Created by ZFly on 2017/4/22.
*/
public class WTFSocketRoutingItemMap<T extends WTFSocketRoutingItem> {
private ConcurrentHashMap<String, T> ioAddressMap = new ConcurrentHashMap<>();
private ConcurrentHashMap<String, String> communicationAddressMap = new ConcurrentHashMap<>();
/**
* 向路由表中注册对象
* 如果对象地址不为空,则使用地址作为key
* 如果对象地址为空,则使用ioTag作为key
*
* @param newItem 路由表对象
*/ | public void add(T newItem) throws WTFSocketException{ |
ZhangFly/WTFSocket_Server_JAVA | src/wtf/socket/routing/WTFSocketRoutingItemMap.java | // Path: src/wtf/socket/exception/WTFSocketException.java
// public abstract class WTFSocketException extends Exception {
//
//
// public WTFSocketException(String msg) {
// super(msg);
// }
//
// public abstract int getErrCode();
//
// }
//
// Path: src/wtf/socket/exception/fatal/WTFSocketInvalidSourceException.java
// public class WTFSocketInvalidSourceException extends WTFSocketFatalException {
//
// public WTFSocketInvalidSourceException(String msg) {
// super(msg);
// }
//
// @Override
// public int getErrCode() {
// return 66;
// }
// }
//
// Path: src/wtf/socket/routing/item/WTFSocketRoutingItem.java
// @Component
// @Scope("prototype")
// public abstract class WTFSocketRoutingItem {
//
// /**
// * 自身通讯地址
// */
// private String address;
// /**
// * 终端对象
// */
// private WTFSocketIOTerm term;
// /**
// * 接受的协议类型
// */
// private String accept;
// /**
// * 终端类型(iOS, Android, Hardware)
// */
// private String deviceType = "Unknown";
// /**
// * 是否允许覆盖
// */
// private boolean cover = true;
// /**
// * 允许用户为客户端添加自定义Tag信息
// */
// private Object tag;
//
// private WTFSocketServer context;
//
// public void setAddress(String address) {
// this.address = address;
// }
//
// public String getAddress() {
// return address;
// }
//
// public String getAccept() {
// return accept;
// }
//
// public void setAccept(String accept) {
// this.accept = accept;
// }
//
// public String getDeviceType() {
// return deviceType;
// }
//
// public void setDeviceType(String deviceType) {
// this.deviceType = deviceType == null ? "Unknown" : deviceType;
// }
//
// public WTFSocketIOTerm getTerm() {
// return term;
// }
//
// public void setTerm(WTFSocketIOTerm term) {
// this.term = term;
// }
//
// public boolean isCover() {
// return cover;
// }
//
// public void setCover(boolean cover) {
// this.cover = cover;
// }
//
// public WTFSocketServer getContext() {
// return context;
// }
//
// public void setContext(WTFSocketServer context) {
// this.context = context;
// }
//
// public Object getTag() {
// return tag;
// }
//
// public void setTag(Object tag) {
// this.tag = tag;
// }
//
// public void close() throws WTFSocketException {
// getContext().getEventsGroup().publishEvent(this, null, WTFSocketEventsType.Disconnect);
// getTerm().close();
// }
// }
| import wtf.socket.exception.WTFSocketException;
import wtf.socket.exception.fatal.WTFSocketInvalidSourceException;
import wtf.socket.routing.item.WTFSocketRoutingItem;
import java.util.Collection;
import java.util.concurrent.ConcurrentHashMap; | package wtf.socket.routing;
/**
* 路由表
* <p>
* Created by ZFly on 2017/4/22.
*/
public class WTFSocketRoutingItemMap<T extends WTFSocketRoutingItem> {
private ConcurrentHashMap<String, T> ioAddressMap = new ConcurrentHashMap<>();
private ConcurrentHashMap<String, String> communicationAddressMap = new ConcurrentHashMap<>();
/**
* 向路由表中注册对象
* 如果对象地址不为空,则使用地址作为key
* 如果对象地址为空,则使用ioTag作为key
*
* @param newItem 路由表对象
*/
public void add(T newItem) throws WTFSocketException{
final String newIOAddress = newItem.getTerm().getIoTag();
final String newCommunicationAddress = newItem.getAddress();
// 如果通讯地址已被注册
if (newCommunicationAddress != null && communicationAddressMap.containsKey(newCommunicationAddress)) {
final String oldIOAddress = communicationAddressMap.get(newCommunicationAddress);
final WTFSocketRoutingItem oldItem = ioAddressMap.get(oldIOAddress);
// 原客户端允许覆盖
// 则关闭原客户端连接,并替换为新连接
if (oldItem.isCover()) {
oldItem.getTerm().close();
ioAddressMap.remove(oldIOAddress);
ioAddressMap.put(newIOAddress, newItem);
communicationAddressMap.put(newCommunicationAddress, newIOAddress);
}else { | // Path: src/wtf/socket/exception/WTFSocketException.java
// public abstract class WTFSocketException extends Exception {
//
//
// public WTFSocketException(String msg) {
// super(msg);
// }
//
// public abstract int getErrCode();
//
// }
//
// Path: src/wtf/socket/exception/fatal/WTFSocketInvalidSourceException.java
// public class WTFSocketInvalidSourceException extends WTFSocketFatalException {
//
// public WTFSocketInvalidSourceException(String msg) {
// super(msg);
// }
//
// @Override
// public int getErrCode() {
// return 66;
// }
// }
//
// Path: src/wtf/socket/routing/item/WTFSocketRoutingItem.java
// @Component
// @Scope("prototype")
// public abstract class WTFSocketRoutingItem {
//
// /**
// * 自身通讯地址
// */
// private String address;
// /**
// * 终端对象
// */
// private WTFSocketIOTerm term;
// /**
// * 接受的协议类型
// */
// private String accept;
// /**
// * 终端类型(iOS, Android, Hardware)
// */
// private String deviceType = "Unknown";
// /**
// * 是否允许覆盖
// */
// private boolean cover = true;
// /**
// * 允许用户为客户端添加自定义Tag信息
// */
// private Object tag;
//
// private WTFSocketServer context;
//
// public void setAddress(String address) {
// this.address = address;
// }
//
// public String getAddress() {
// return address;
// }
//
// public String getAccept() {
// return accept;
// }
//
// public void setAccept(String accept) {
// this.accept = accept;
// }
//
// public String getDeviceType() {
// return deviceType;
// }
//
// public void setDeviceType(String deviceType) {
// this.deviceType = deviceType == null ? "Unknown" : deviceType;
// }
//
// public WTFSocketIOTerm getTerm() {
// return term;
// }
//
// public void setTerm(WTFSocketIOTerm term) {
// this.term = term;
// }
//
// public boolean isCover() {
// return cover;
// }
//
// public void setCover(boolean cover) {
// this.cover = cover;
// }
//
// public WTFSocketServer getContext() {
// return context;
// }
//
// public void setContext(WTFSocketServer context) {
// this.context = context;
// }
//
// public Object getTag() {
// return tag;
// }
//
// public void setTag(Object tag) {
// this.tag = tag;
// }
//
// public void close() throws WTFSocketException {
// getContext().getEventsGroup().publishEvent(this, null, WTFSocketEventsType.Disconnect);
// getTerm().close();
// }
// }
// Path: src/wtf/socket/routing/WTFSocketRoutingItemMap.java
import wtf.socket.exception.WTFSocketException;
import wtf.socket.exception.fatal.WTFSocketInvalidSourceException;
import wtf.socket.routing.item.WTFSocketRoutingItem;
import java.util.Collection;
import java.util.concurrent.ConcurrentHashMap;
package wtf.socket.routing;
/**
* 路由表
* <p>
* Created by ZFly on 2017/4/22.
*/
public class WTFSocketRoutingItemMap<T extends WTFSocketRoutingItem> {
private ConcurrentHashMap<String, T> ioAddressMap = new ConcurrentHashMap<>();
private ConcurrentHashMap<String, String> communicationAddressMap = new ConcurrentHashMap<>();
/**
* 向路由表中注册对象
* 如果对象地址不为空,则使用地址作为key
* 如果对象地址为空,则使用ioTag作为key
*
* @param newItem 路由表对象
*/
public void add(T newItem) throws WTFSocketException{
final String newIOAddress = newItem.getTerm().getIoTag();
final String newCommunicationAddress = newItem.getAddress();
// 如果通讯地址已被注册
if (newCommunicationAddress != null && communicationAddressMap.containsKey(newCommunicationAddress)) {
final String oldIOAddress = communicationAddressMap.get(newCommunicationAddress);
final WTFSocketRoutingItem oldItem = ioAddressMap.get(oldIOAddress);
// 原客户端允许覆盖
// 则关闭原客户端连接,并替换为新连接
if (oldItem.isCover()) {
oldItem.getTerm().close();
ioAddressMap.remove(oldIOAddress);
ioAddressMap.put(newIOAddress, newItem);
communicationAddressMap.put(newCommunicationAddress, newIOAddress);
}else { | throw new WTFSocketInvalidSourceException("[" + newCommunicationAddress + "] has token"); |
ZhangFly/WTFSocket_Server_JAVA | src/wtf/socket/secure/delegate/WTFSocketSecureDelegate.java | // Path: src/wtf/socket/protocol/WTFSocketMsg.java
// public interface WTFSocketMsg {
//
// String getIoTag();
//
// void setIoTag(String ioTag);
//
// String getFrom();
//
// void setFrom(String from);
//
// String getTo();
//
// void setTo(String to);
//
// int getMsgId();
//
// void setMsgId(int msgId);
//
// int getMsgType();
//
// void setMsgType(int msgType);
//
// int getState();
//
// void setState(int state);
//
// void setConnectType(String connectType);
//
// String getConnectType();
//
// String getVersion();
//
// void setVersion(String version);
//
// Object getBody();
//
// <T> T getBody(Class<T> tClass);
//
// void setBody(Object body);
//
// WTFSocketMsg makeResponse();
// }
| import wtf.socket.protocol.WTFSocketMsg; | package wtf.socket.secure.delegate;
/**
* 安全代理
* <p>
* Created by ZFly on 2017/4/25.
*/
@FunctionalInterface
public interface WTFSocketSecureDelegate {
| // Path: src/wtf/socket/protocol/WTFSocketMsg.java
// public interface WTFSocketMsg {
//
// String getIoTag();
//
// void setIoTag(String ioTag);
//
// String getFrom();
//
// void setFrom(String from);
//
// String getTo();
//
// void setTo(String to);
//
// int getMsgId();
//
// void setMsgId(int msgId);
//
// int getMsgType();
//
// void setMsgType(int msgType);
//
// int getState();
//
// void setState(int state);
//
// void setConnectType(String connectType);
//
// String getConnectType();
//
// String getVersion();
//
// void setVersion(String version);
//
// Object getBody();
//
// <T> T getBody(Class<T> tClass);
//
// void setBody(Object body);
//
// WTFSocketMsg makeResponse();
// }
// Path: src/wtf/socket/secure/delegate/WTFSocketSecureDelegate.java
import wtf.socket.protocol.WTFSocketMsg;
package wtf.socket.secure.delegate;
/**
* 安全代理
* <p>
* Created by ZFly on 2017/4/25.
*/
@FunctionalInterface
public interface WTFSocketSecureDelegate {
| Object work(WTFSocketMsg msg); |
ZhangFly/WTFSocket_Server_JAVA | src/wtf/socket/routing/item/WTFSocketRoutingTmpItem.java | // Path: src/wtf/socket/event/WTFSocketEventsType.java
// public enum WTFSocketEventsType {
// /**
// * 客户端断开连接时触发
// */
// Disconnect,
// /**
// * 有新客户端连接时触发
// */
// Connect,
// /**
// * 收到新消息时触发
// * 在安全检查之前
// */
// OnReceiveData,
// /**
// * 发送消息前触发
// * 在安全检查之前
// */
// BeforeSendData,
// /**
// * 服务器启动时触发
// */
// ServerStarted
// }
//
// Path: src/wtf/socket/exception/WTFSocketException.java
// public abstract class WTFSocketException extends Exception {
//
//
// public WTFSocketException(String msg) {
// super(msg);
// }
//
// public abstract int getErrCode();
//
// }
| import org.springframework.beans.BeanUtils;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import wtf.socket.event.WTFSocketEventsType;
import wtf.socket.exception.WTFSocketException;
import java.util.concurrent.TimeUnit; | package wtf.socket.routing.item;
/**
* 临时客户端
* <p>
* Created by ZFly on 2017/4/23.
*/
@Component
@Scope("prototype")
public class WTFSocketRoutingTmpItem extends WTFSocketRoutingItem {
/**
* 过期时间
*/
private long expires = TimeUnit.MINUTES.toMillis(1);
public void setExpires(int duration, TimeUnit unit) {
expires = System.currentTimeMillis() + unit.toMillis(duration);
}
public boolean isExpires() {
return expires < System.currentTimeMillis();
}
| // Path: src/wtf/socket/event/WTFSocketEventsType.java
// public enum WTFSocketEventsType {
// /**
// * 客户端断开连接时触发
// */
// Disconnect,
// /**
// * 有新客户端连接时触发
// */
// Connect,
// /**
// * 收到新消息时触发
// * 在安全检查之前
// */
// OnReceiveData,
// /**
// * 发送消息前触发
// * 在安全检查之前
// */
// BeforeSendData,
// /**
// * 服务器启动时触发
// */
// ServerStarted
// }
//
// Path: src/wtf/socket/exception/WTFSocketException.java
// public abstract class WTFSocketException extends Exception {
//
//
// public WTFSocketException(String msg) {
// super(msg);
// }
//
// public abstract int getErrCode();
//
// }
// Path: src/wtf/socket/routing/item/WTFSocketRoutingTmpItem.java
import org.springframework.beans.BeanUtils;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import wtf.socket.event.WTFSocketEventsType;
import wtf.socket.exception.WTFSocketException;
import java.util.concurrent.TimeUnit;
package wtf.socket.routing.item;
/**
* 临时客户端
* <p>
* Created by ZFly on 2017/4/23.
*/
@Component
@Scope("prototype")
public class WTFSocketRoutingTmpItem extends WTFSocketRoutingItem {
/**
* 过期时间
*/
private long expires = TimeUnit.MINUTES.toMillis(1);
public void setExpires(int duration, TimeUnit unit) {
expires = System.currentTimeMillis() + unit.toMillis(duration);
}
public boolean isExpires() {
return expires < System.currentTimeMillis();
}
| public void shiftToFormal() throws WTFSocketException{ |
ZhangFly/WTFSocket_Server_JAVA | src/wtf/socket/routing/item/WTFSocketRoutingTmpItem.java | // Path: src/wtf/socket/event/WTFSocketEventsType.java
// public enum WTFSocketEventsType {
// /**
// * 客户端断开连接时触发
// */
// Disconnect,
// /**
// * 有新客户端连接时触发
// */
// Connect,
// /**
// * 收到新消息时触发
// * 在安全检查之前
// */
// OnReceiveData,
// /**
// * 发送消息前触发
// * 在安全检查之前
// */
// BeforeSendData,
// /**
// * 服务器启动时触发
// */
// ServerStarted
// }
//
// Path: src/wtf/socket/exception/WTFSocketException.java
// public abstract class WTFSocketException extends Exception {
//
//
// public WTFSocketException(String msg) {
// super(msg);
// }
//
// public abstract int getErrCode();
//
// }
| import org.springframework.beans.BeanUtils;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import wtf.socket.event.WTFSocketEventsType;
import wtf.socket.exception.WTFSocketException;
import java.util.concurrent.TimeUnit; | package wtf.socket.routing.item;
/**
* 临时客户端
* <p>
* Created by ZFly on 2017/4/23.
*/
@Component
@Scope("prototype")
public class WTFSocketRoutingTmpItem extends WTFSocketRoutingItem {
/**
* 过期时间
*/
private long expires = TimeUnit.MINUTES.toMillis(1);
public void setExpires(int duration, TimeUnit unit) {
expires = System.currentTimeMillis() + unit.toMillis(duration);
}
public boolean isExpires() {
return expires < System.currentTimeMillis();
}
public void shiftToFormal() throws WTFSocketException{
getContext().getRouting().getTmpMap().remove(this);
final WTFSocketRoutingFormalItem newFormal = new WTFSocketRoutingFormalItem();
BeanUtils.copyProperties(this, newFormal);
getContext().getRouting().getFormalMap().add(newFormal);
}
public void shiftToDebug() throws WTFSocketException {
getContext().getRouting().getTmpMap().remove(this);
final WTFSocketRoutingDebugItem newDebug = new WTFSocketRoutingDebugItem();
BeanUtils.copyProperties(this, newDebug);
getContext().getRouting().getDebugMap().add(newDebug);
}
public void open() throws WTFSocketException {
getContext().getRouting().getTmpMap().add(this); | // Path: src/wtf/socket/event/WTFSocketEventsType.java
// public enum WTFSocketEventsType {
// /**
// * 客户端断开连接时触发
// */
// Disconnect,
// /**
// * 有新客户端连接时触发
// */
// Connect,
// /**
// * 收到新消息时触发
// * 在安全检查之前
// */
// OnReceiveData,
// /**
// * 发送消息前触发
// * 在安全检查之前
// */
// BeforeSendData,
// /**
// * 服务器启动时触发
// */
// ServerStarted
// }
//
// Path: src/wtf/socket/exception/WTFSocketException.java
// public abstract class WTFSocketException extends Exception {
//
//
// public WTFSocketException(String msg) {
// super(msg);
// }
//
// public abstract int getErrCode();
//
// }
// Path: src/wtf/socket/routing/item/WTFSocketRoutingTmpItem.java
import org.springframework.beans.BeanUtils;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import wtf.socket.event.WTFSocketEventsType;
import wtf.socket.exception.WTFSocketException;
import java.util.concurrent.TimeUnit;
package wtf.socket.routing.item;
/**
* 临时客户端
* <p>
* Created by ZFly on 2017/4/23.
*/
@Component
@Scope("prototype")
public class WTFSocketRoutingTmpItem extends WTFSocketRoutingItem {
/**
* 过期时间
*/
private long expires = TimeUnit.MINUTES.toMillis(1);
public void setExpires(int duration, TimeUnit unit) {
expires = System.currentTimeMillis() + unit.toMillis(duration);
}
public boolean isExpires() {
return expires < System.currentTimeMillis();
}
public void shiftToFormal() throws WTFSocketException{
getContext().getRouting().getTmpMap().remove(this);
final WTFSocketRoutingFormalItem newFormal = new WTFSocketRoutingFormalItem();
BeanUtils.copyProperties(this, newFormal);
getContext().getRouting().getFormalMap().add(newFormal);
}
public void shiftToDebug() throws WTFSocketException {
getContext().getRouting().getTmpMap().remove(this);
final WTFSocketRoutingDebugItem newDebug = new WTFSocketRoutingDebugItem();
BeanUtils.copyProperties(this, newDebug);
getContext().getRouting().getDebugMap().add(newDebug);
}
public void open() throws WTFSocketException {
getContext().getRouting().getTmpMap().add(this); | getContext().getEventsGroup().publishEvent(this, null, WTFSocketEventsType.Connect); |
ZhangFly/WTFSocket_Server_JAVA | src/wtf/socket/event/WTFSocketEventListenersGroup.java | // Path: src/wtf/socket/exception/WTFSocketException.java
// public abstract class WTFSocketException extends Exception {
//
//
// public WTFSocketException(String msg) {
// super(msg);
// }
//
// public abstract int getErrCode();
//
// }
//
// Path: src/wtf/socket/routing/item/WTFSocketRoutingItem.java
// @Component
// @Scope("prototype")
// public abstract class WTFSocketRoutingItem {
//
// /**
// * 自身通讯地址
// */
// private String address;
// /**
// * 终端对象
// */
// private WTFSocketIOTerm term;
// /**
// * 接受的协议类型
// */
// private String accept;
// /**
// * 终端类型(iOS, Android, Hardware)
// */
// private String deviceType = "Unknown";
// /**
// * 是否允许覆盖
// */
// private boolean cover = true;
// /**
// * 允许用户为客户端添加自定义Tag信息
// */
// private Object tag;
//
// private WTFSocketServer context;
//
// public void setAddress(String address) {
// this.address = address;
// }
//
// public String getAddress() {
// return address;
// }
//
// public String getAccept() {
// return accept;
// }
//
// public void setAccept(String accept) {
// this.accept = accept;
// }
//
// public String getDeviceType() {
// return deviceType;
// }
//
// public void setDeviceType(String deviceType) {
// this.deviceType = deviceType == null ? "Unknown" : deviceType;
// }
//
// public WTFSocketIOTerm getTerm() {
// return term;
// }
//
// public void setTerm(WTFSocketIOTerm term) {
// this.term = term;
// }
//
// public boolean isCover() {
// return cover;
// }
//
// public void setCover(boolean cover) {
// this.cover = cover;
// }
//
// public WTFSocketServer getContext() {
// return context;
// }
//
// public void setContext(WTFSocketServer context) {
// this.context = context;
// }
//
// public Object getTag() {
// return tag;
// }
//
// public void setTag(Object tag) {
// this.tag = tag;
// }
//
// public void close() throws WTFSocketException {
// getContext().getEventsGroup().publishEvent(this, null, WTFSocketEventsType.Disconnect);
// getTerm().close();
// }
// }
| import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import wtf.socket.exception.WTFSocketException;
import wtf.socket.routing.item.WTFSocketRoutingItem;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set; | package wtf.socket.event;
/**
* 监听事件组
* <p>
* Created by ZFly on 2017/4/25.
*/
@Component
@Scope("prototype")
public class WTFSocketEventListenersGroup {
private final Map<WTFSocketEventsType, Set<WTFSocketEventListener>> group = new HashMap<WTFSocketEventsType, Set<WTFSocketEventListener>>(WTFSocketEventsType.values().length) {{
for (WTFSocketEventsType eventsType : WTFSocketEventsType.values()) {
put(eventsType, new HashSet<>(1));
}
}};
/**
* 添加事件监听者
*
* @param eventListener 监听者
* @param eventsType 事件类型
*/
public void addEventListener(WTFSocketEventListener eventListener, WTFSocketEventsType eventsType) {
group.get(eventsType).add(eventListener);
}
/**
* 移除事件监听者
*
* @param eventListener 监听者
* @param eventsType 事件类型
*/
public void removeEventListener(WTFSocketEventListener eventListener, WTFSocketEventsType eventsType) {
group.get(eventsType).remove(eventListener);
}
/**
* 发生某类型事件
*
* @param item 发送源客户端
* @param info 附加消息
* @param eventsType 事件类型
*
* @throws WTFSocketException 异常信息
*/ | // Path: src/wtf/socket/exception/WTFSocketException.java
// public abstract class WTFSocketException extends Exception {
//
//
// public WTFSocketException(String msg) {
// super(msg);
// }
//
// public abstract int getErrCode();
//
// }
//
// Path: src/wtf/socket/routing/item/WTFSocketRoutingItem.java
// @Component
// @Scope("prototype")
// public abstract class WTFSocketRoutingItem {
//
// /**
// * 自身通讯地址
// */
// private String address;
// /**
// * 终端对象
// */
// private WTFSocketIOTerm term;
// /**
// * 接受的协议类型
// */
// private String accept;
// /**
// * 终端类型(iOS, Android, Hardware)
// */
// private String deviceType = "Unknown";
// /**
// * 是否允许覆盖
// */
// private boolean cover = true;
// /**
// * 允许用户为客户端添加自定义Tag信息
// */
// private Object tag;
//
// private WTFSocketServer context;
//
// public void setAddress(String address) {
// this.address = address;
// }
//
// public String getAddress() {
// return address;
// }
//
// public String getAccept() {
// return accept;
// }
//
// public void setAccept(String accept) {
// this.accept = accept;
// }
//
// public String getDeviceType() {
// return deviceType;
// }
//
// public void setDeviceType(String deviceType) {
// this.deviceType = deviceType == null ? "Unknown" : deviceType;
// }
//
// public WTFSocketIOTerm getTerm() {
// return term;
// }
//
// public void setTerm(WTFSocketIOTerm term) {
// this.term = term;
// }
//
// public boolean isCover() {
// return cover;
// }
//
// public void setCover(boolean cover) {
// this.cover = cover;
// }
//
// public WTFSocketServer getContext() {
// return context;
// }
//
// public void setContext(WTFSocketServer context) {
// this.context = context;
// }
//
// public Object getTag() {
// return tag;
// }
//
// public void setTag(Object tag) {
// this.tag = tag;
// }
//
// public void close() throws WTFSocketException {
// getContext().getEventsGroup().publishEvent(this, null, WTFSocketEventsType.Disconnect);
// getTerm().close();
// }
// }
// Path: src/wtf/socket/event/WTFSocketEventListenersGroup.java
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import wtf.socket.exception.WTFSocketException;
import wtf.socket.routing.item.WTFSocketRoutingItem;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
package wtf.socket.event;
/**
* 监听事件组
* <p>
* Created by ZFly on 2017/4/25.
*/
@Component
@Scope("prototype")
public class WTFSocketEventListenersGroup {
private final Map<WTFSocketEventsType, Set<WTFSocketEventListener>> group = new HashMap<WTFSocketEventsType, Set<WTFSocketEventListener>>(WTFSocketEventsType.values().length) {{
for (WTFSocketEventsType eventsType : WTFSocketEventsType.values()) {
put(eventsType, new HashSet<>(1));
}
}};
/**
* 添加事件监听者
*
* @param eventListener 监听者
* @param eventsType 事件类型
*/
public void addEventListener(WTFSocketEventListener eventListener, WTFSocketEventsType eventsType) {
group.get(eventsType).add(eventListener);
}
/**
* 移除事件监听者
*
* @param eventListener 监听者
* @param eventsType 事件类型
*/
public void removeEventListener(WTFSocketEventListener eventListener, WTFSocketEventsType eventsType) {
group.get(eventsType).remove(eventListener);
}
/**
* 发生某类型事件
*
* @param item 发送源客户端
* @param info 附加消息
* @param eventsType 事件类型
*
* @throws WTFSocketException 异常信息
*/ | public void publishEvent(WTFSocketRoutingItem item, Object info, WTFSocketEventsType eventsType) throws WTFSocketException { |
ZhangFly/WTFSocket_Server_JAVA | src/wtf/socket/event/WTFSocketEventListenersGroup.java | // Path: src/wtf/socket/exception/WTFSocketException.java
// public abstract class WTFSocketException extends Exception {
//
//
// public WTFSocketException(String msg) {
// super(msg);
// }
//
// public abstract int getErrCode();
//
// }
//
// Path: src/wtf/socket/routing/item/WTFSocketRoutingItem.java
// @Component
// @Scope("prototype")
// public abstract class WTFSocketRoutingItem {
//
// /**
// * 自身通讯地址
// */
// private String address;
// /**
// * 终端对象
// */
// private WTFSocketIOTerm term;
// /**
// * 接受的协议类型
// */
// private String accept;
// /**
// * 终端类型(iOS, Android, Hardware)
// */
// private String deviceType = "Unknown";
// /**
// * 是否允许覆盖
// */
// private boolean cover = true;
// /**
// * 允许用户为客户端添加自定义Tag信息
// */
// private Object tag;
//
// private WTFSocketServer context;
//
// public void setAddress(String address) {
// this.address = address;
// }
//
// public String getAddress() {
// return address;
// }
//
// public String getAccept() {
// return accept;
// }
//
// public void setAccept(String accept) {
// this.accept = accept;
// }
//
// public String getDeviceType() {
// return deviceType;
// }
//
// public void setDeviceType(String deviceType) {
// this.deviceType = deviceType == null ? "Unknown" : deviceType;
// }
//
// public WTFSocketIOTerm getTerm() {
// return term;
// }
//
// public void setTerm(WTFSocketIOTerm term) {
// this.term = term;
// }
//
// public boolean isCover() {
// return cover;
// }
//
// public void setCover(boolean cover) {
// this.cover = cover;
// }
//
// public WTFSocketServer getContext() {
// return context;
// }
//
// public void setContext(WTFSocketServer context) {
// this.context = context;
// }
//
// public Object getTag() {
// return tag;
// }
//
// public void setTag(Object tag) {
// this.tag = tag;
// }
//
// public void close() throws WTFSocketException {
// getContext().getEventsGroup().publishEvent(this, null, WTFSocketEventsType.Disconnect);
// getTerm().close();
// }
// }
| import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import wtf.socket.exception.WTFSocketException;
import wtf.socket.routing.item.WTFSocketRoutingItem;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set; | package wtf.socket.event;
/**
* 监听事件组
* <p>
* Created by ZFly on 2017/4/25.
*/
@Component
@Scope("prototype")
public class WTFSocketEventListenersGroup {
private final Map<WTFSocketEventsType, Set<WTFSocketEventListener>> group = new HashMap<WTFSocketEventsType, Set<WTFSocketEventListener>>(WTFSocketEventsType.values().length) {{
for (WTFSocketEventsType eventsType : WTFSocketEventsType.values()) {
put(eventsType, new HashSet<>(1));
}
}};
/**
* 添加事件监听者
*
* @param eventListener 监听者
* @param eventsType 事件类型
*/
public void addEventListener(WTFSocketEventListener eventListener, WTFSocketEventsType eventsType) {
group.get(eventsType).add(eventListener);
}
/**
* 移除事件监听者
*
* @param eventListener 监听者
* @param eventsType 事件类型
*/
public void removeEventListener(WTFSocketEventListener eventListener, WTFSocketEventsType eventsType) {
group.get(eventsType).remove(eventListener);
}
/**
* 发生某类型事件
*
* @param item 发送源客户端
* @param info 附加消息
* @param eventsType 事件类型
*
* @throws WTFSocketException 异常信息
*/ | // Path: src/wtf/socket/exception/WTFSocketException.java
// public abstract class WTFSocketException extends Exception {
//
//
// public WTFSocketException(String msg) {
// super(msg);
// }
//
// public abstract int getErrCode();
//
// }
//
// Path: src/wtf/socket/routing/item/WTFSocketRoutingItem.java
// @Component
// @Scope("prototype")
// public abstract class WTFSocketRoutingItem {
//
// /**
// * 自身通讯地址
// */
// private String address;
// /**
// * 终端对象
// */
// private WTFSocketIOTerm term;
// /**
// * 接受的协议类型
// */
// private String accept;
// /**
// * 终端类型(iOS, Android, Hardware)
// */
// private String deviceType = "Unknown";
// /**
// * 是否允许覆盖
// */
// private boolean cover = true;
// /**
// * 允许用户为客户端添加自定义Tag信息
// */
// private Object tag;
//
// private WTFSocketServer context;
//
// public void setAddress(String address) {
// this.address = address;
// }
//
// public String getAddress() {
// return address;
// }
//
// public String getAccept() {
// return accept;
// }
//
// public void setAccept(String accept) {
// this.accept = accept;
// }
//
// public String getDeviceType() {
// return deviceType;
// }
//
// public void setDeviceType(String deviceType) {
// this.deviceType = deviceType == null ? "Unknown" : deviceType;
// }
//
// public WTFSocketIOTerm getTerm() {
// return term;
// }
//
// public void setTerm(WTFSocketIOTerm term) {
// this.term = term;
// }
//
// public boolean isCover() {
// return cover;
// }
//
// public void setCover(boolean cover) {
// this.cover = cover;
// }
//
// public WTFSocketServer getContext() {
// return context;
// }
//
// public void setContext(WTFSocketServer context) {
// this.context = context;
// }
//
// public Object getTag() {
// return tag;
// }
//
// public void setTag(Object tag) {
// this.tag = tag;
// }
//
// public void close() throws WTFSocketException {
// getContext().getEventsGroup().publishEvent(this, null, WTFSocketEventsType.Disconnect);
// getTerm().close();
// }
// }
// Path: src/wtf/socket/event/WTFSocketEventListenersGroup.java
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import wtf.socket.exception.WTFSocketException;
import wtf.socket.routing.item.WTFSocketRoutingItem;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
package wtf.socket.event;
/**
* 监听事件组
* <p>
* Created by ZFly on 2017/4/25.
*/
@Component
@Scope("prototype")
public class WTFSocketEventListenersGroup {
private final Map<WTFSocketEventsType, Set<WTFSocketEventListener>> group = new HashMap<WTFSocketEventsType, Set<WTFSocketEventListener>>(WTFSocketEventsType.values().length) {{
for (WTFSocketEventsType eventsType : WTFSocketEventsType.values()) {
put(eventsType, new HashSet<>(1));
}
}};
/**
* 添加事件监听者
*
* @param eventListener 监听者
* @param eventsType 事件类型
*/
public void addEventListener(WTFSocketEventListener eventListener, WTFSocketEventsType eventsType) {
group.get(eventsType).add(eventListener);
}
/**
* 移除事件监听者
*
* @param eventListener 监听者
* @param eventsType 事件类型
*/
public void removeEventListener(WTFSocketEventListener eventListener, WTFSocketEventsType eventsType) {
group.get(eventsType).remove(eventListener);
}
/**
* 发生某类型事件
*
* @param item 发送源客户端
* @param info 附加消息
* @param eventsType 事件类型
*
* @throws WTFSocketException 异常信息
*/ | public void publishEvent(WTFSocketRoutingItem item, Object info, WTFSocketEventsType eventsType) throws WTFSocketException { |
ZhangFly/WTFSocket_Server_JAVA | src/wtf/socket/secure/delegate/WTFSocketSecureDelegatesGroup.java | // Path: src/wtf/socket/event/WTFSocketEventsType.java
// public enum WTFSocketEventsType {
// /**
// * 客户端断开连接时触发
// */
// Disconnect,
// /**
// * 有新客户端连接时触发
// */
// Connect,
// /**
// * 收到新消息时触发
// * 在安全检查之前
// */
// OnReceiveData,
// /**
// * 发送消息前触发
// * 在安全检查之前
// */
// BeforeSendData,
// /**
// * 服务器启动时触发
// */
// ServerStarted
// }
| import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import wtf.socket.event.WTFSocketEventsType;
import java.util.HashMap;
import java.util.Map; | package wtf.socket.secure.delegate;
/**
* 安全组件
* <p>
* Created by ZFly on 2017/4/24.
*/
@Component
@Scope("prototype")
public class WTFSocketSecureDelegatesGroup {
| // Path: src/wtf/socket/event/WTFSocketEventsType.java
// public enum WTFSocketEventsType {
// /**
// * 客户端断开连接时触发
// */
// Disconnect,
// /**
// * 有新客户端连接时触发
// */
// Connect,
// /**
// * 收到新消息时触发
// * 在安全检查之前
// */
// OnReceiveData,
// /**
// * 发送消息前触发
// * 在安全检查之前
// */
// BeforeSendData,
// /**
// * 服务器启动时触发
// */
// ServerStarted
// }
// Path: src/wtf/socket/secure/delegate/WTFSocketSecureDelegatesGroup.java
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import wtf.socket.event.WTFSocketEventsType;
import java.util.HashMap;
import java.util.Map;
package wtf.socket.secure.delegate;
/**
* 安全组件
* <p>
* Created by ZFly on 2017/4/24.
*/
@Component
@Scope("prototype")
public class WTFSocketSecureDelegatesGroup {
| private final Map<WTFSocketSecureDelegateType, WTFSocketSecureDelegate> group = new HashMap<>(WTFSocketEventsType.values().length); |
ZhangFly/WTFSocket_Server_JAVA | src/wtf/socket/event/WTFSocketEventListener.java | // Path: src/wtf/socket/exception/WTFSocketException.java
// public abstract class WTFSocketException extends Exception {
//
//
// public WTFSocketException(String msg) {
// super(msg);
// }
//
// public abstract int getErrCode();
//
// }
//
// Path: src/wtf/socket/routing/item/WTFSocketRoutingItem.java
// @Component
// @Scope("prototype")
// public abstract class WTFSocketRoutingItem {
//
// /**
// * 自身通讯地址
// */
// private String address;
// /**
// * 终端对象
// */
// private WTFSocketIOTerm term;
// /**
// * 接受的协议类型
// */
// private String accept;
// /**
// * 终端类型(iOS, Android, Hardware)
// */
// private String deviceType = "Unknown";
// /**
// * 是否允许覆盖
// */
// private boolean cover = true;
// /**
// * 允许用户为客户端添加自定义Tag信息
// */
// private Object tag;
//
// private WTFSocketServer context;
//
// public void setAddress(String address) {
// this.address = address;
// }
//
// public String getAddress() {
// return address;
// }
//
// public String getAccept() {
// return accept;
// }
//
// public void setAccept(String accept) {
// this.accept = accept;
// }
//
// public String getDeviceType() {
// return deviceType;
// }
//
// public void setDeviceType(String deviceType) {
// this.deviceType = deviceType == null ? "Unknown" : deviceType;
// }
//
// public WTFSocketIOTerm getTerm() {
// return term;
// }
//
// public void setTerm(WTFSocketIOTerm term) {
// this.term = term;
// }
//
// public boolean isCover() {
// return cover;
// }
//
// public void setCover(boolean cover) {
// this.cover = cover;
// }
//
// public WTFSocketServer getContext() {
// return context;
// }
//
// public void setContext(WTFSocketServer context) {
// this.context = context;
// }
//
// public Object getTag() {
// return tag;
// }
//
// public void setTag(Object tag) {
// this.tag = tag;
// }
//
// public void close() throws WTFSocketException {
// getContext().getEventsGroup().publishEvent(this, null, WTFSocketEventsType.Disconnect);
// getTerm().close();
// }
// }
| import wtf.socket.exception.WTFSocketException;
import wtf.socket.routing.item.WTFSocketRoutingItem; | package wtf.socket.event;
/**
* 事件监听者接口
* <p>
* Created by ZFly on 2017/4/25.
*/
@FunctionalInterface
public interface WTFSocketEventListener { | // Path: src/wtf/socket/exception/WTFSocketException.java
// public abstract class WTFSocketException extends Exception {
//
//
// public WTFSocketException(String msg) {
// super(msg);
// }
//
// public abstract int getErrCode();
//
// }
//
// Path: src/wtf/socket/routing/item/WTFSocketRoutingItem.java
// @Component
// @Scope("prototype")
// public abstract class WTFSocketRoutingItem {
//
// /**
// * 自身通讯地址
// */
// private String address;
// /**
// * 终端对象
// */
// private WTFSocketIOTerm term;
// /**
// * 接受的协议类型
// */
// private String accept;
// /**
// * 终端类型(iOS, Android, Hardware)
// */
// private String deviceType = "Unknown";
// /**
// * 是否允许覆盖
// */
// private boolean cover = true;
// /**
// * 允许用户为客户端添加自定义Tag信息
// */
// private Object tag;
//
// private WTFSocketServer context;
//
// public void setAddress(String address) {
// this.address = address;
// }
//
// public String getAddress() {
// return address;
// }
//
// public String getAccept() {
// return accept;
// }
//
// public void setAccept(String accept) {
// this.accept = accept;
// }
//
// public String getDeviceType() {
// return deviceType;
// }
//
// public void setDeviceType(String deviceType) {
// this.deviceType = deviceType == null ? "Unknown" : deviceType;
// }
//
// public WTFSocketIOTerm getTerm() {
// return term;
// }
//
// public void setTerm(WTFSocketIOTerm term) {
// this.term = term;
// }
//
// public boolean isCover() {
// return cover;
// }
//
// public void setCover(boolean cover) {
// this.cover = cover;
// }
//
// public WTFSocketServer getContext() {
// return context;
// }
//
// public void setContext(WTFSocketServer context) {
// this.context = context;
// }
//
// public Object getTag() {
// return tag;
// }
//
// public void setTag(Object tag) {
// this.tag = tag;
// }
//
// public void close() throws WTFSocketException {
// getContext().getEventsGroup().publishEvent(this, null, WTFSocketEventsType.Disconnect);
// getTerm().close();
// }
// }
// Path: src/wtf/socket/event/WTFSocketEventListener.java
import wtf.socket.exception.WTFSocketException;
import wtf.socket.routing.item.WTFSocketRoutingItem;
package wtf.socket.event;
/**
* 事件监听者接口
* <p>
* Created by ZFly on 2017/4/25.
*/
@FunctionalInterface
public interface WTFSocketEventListener { | void eventOccurred(WTFSocketRoutingItem item, Object info) throws WTFSocketException; |
ZhangFly/WTFSocket_Server_JAVA | src/wtf/socket/event/WTFSocketEventListener.java | // Path: src/wtf/socket/exception/WTFSocketException.java
// public abstract class WTFSocketException extends Exception {
//
//
// public WTFSocketException(String msg) {
// super(msg);
// }
//
// public abstract int getErrCode();
//
// }
//
// Path: src/wtf/socket/routing/item/WTFSocketRoutingItem.java
// @Component
// @Scope("prototype")
// public abstract class WTFSocketRoutingItem {
//
// /**
// * 自身通讯地址
// */
// private String address;
// /**
// * 终端对象
// */
// private WTFSocketIOTerm term;
// /**
// * 接受的协议类型
// */
// private String accept;
// /**
// * 终端类型(iOS, Android, Hardware)
// */
// private String deviceType = "Unknown";
// /**
// * 是否允许覆盖
// */
// private boolean cover = true;
// /**
// * 允许用户为客户端添加自定义Tag信息
// */
// private Object tag;
//
// private WTFSocketServer context;
//
// public void setAddress(String address) {
// this.address = address;
// }
//
// public String getAddress() {
// return address;
// }
//
// public String getAccept() {
// return accept;
// }
//
// public void setAccept(String accept) {
// this.accept = accept;
// }
//
// public String getDeviceType() {
// return deviceType;
// }
//
// public void setDeviceType(String deviceType) {
// this.deviceType = deviceType == null ? "Unknown" : deviceType;
// }
//
// public WTFSocketIOTerm getTerm() {
// return term;
// }
//
// public void setTerm(WTFSocketIOTerm term) {
// this.term = term;
// }
//
// public boolean isCover() {
// return cover;
// }
//
// public void setCover(boolean cover) {
// this.cover = cover;
// }
//
// public WTFSocketServer getContext() {
// return context;
// }
//
// public void setContext(WTFSocketServer context) {
// this.context = context;
// }
//
// public Object getTag() {
// return tag;
// }
//
// public void setTag(Object tag) {
// this.tag = tag;
// }
//
// public void close() throws WTFSocketException {
// getContext().getEventsGroup().publishEvent(this, null, WTFSocketEventsType.Disconnect);
// getTerm().close();
// }
// }
| import wtf.socket.exception.WTFSocketException;
import wtf.socket.routing.item.WTFSocketRoutingItem; | package wtf.socket.event;
/**
* 事件监听者接口
* <p>
* Created by ZFly on 2017/4/25.
*/
@FunctionalInterface
public interface WTFSocketEventListener { | // Path: src/wtf/socket/exception/WTFSocketException.java
// public abstract class WTFSocketException extends Exception {
//
//
// public WTFSocketException(String msg) {
// super(msg);
// }
//
// public abstract int getErrCode();
//
// }
//
// Path: src/wtf/socket/routing/item/WTFSocketRoutingItem.java
// @Component
// @Scope("prototype")
// public abstract class WTFSocketRoutingItem {
//
// /**
// * 自身通讯地址
// */
// private String address;
// /**
// * 终端对象
// */
// private WTFSocketIOTerm term;
// /**
// * 接受的协议类型
// */
// private String accept;
// /**
// * 终端类型(iOS, Android, Hardware)
// */
// private String deviceType = "Unknown";
// /**
// * 是否允许覆盖
// */
// private boolean cover = true;
// /**
// * 允许用户为客户端添加自定义Tag信息
// */
// private Object tag;
//
// private WTFSocketServer context;
//
// public void setAddress(String address) {
// this.address = address;
// }
//
// public String getAddress() {
// return address;
// }
//
// public String getAccept() {
// return accept;
// }
//
// public void setAccept(String accept) {
// this.accept = accept;
// }
//
// public String getDeviceType() {
// return deviceType;
// }
//
// public void setDeviceType(String deviceType) {
// this.deviceType = deviceType == null ? "Unknown" : deviceType;
// }
//
// public WTFSocketIOTerm getTerm() {
// return term;
// }
//
// public void setTerm(WTFSocketIOTerm term) {
// this.term = term;
// }
//
// public boolean isCover() {
// return cover;
// }
//
// public void setCover(boolean cover) {
// this.cover = cover;
// }
//
// public WTFSocketServer getContext() {
// return context;
// }
//
// public void setContext(WTFSocketServer context) {
// this.context = context;
// }
//
// public Object getTag() {
// return tag;
// }
//
// public void setTag(Object tag) {
// this.tag = tag;
// }
//
// public void close() throws WTFSocketException {
// getContext().getEventsGroup().publishEvent(this, null, WTFSocketEventsType.Disconnect);
// getTerm().close();
// }
// }
// Path: src/wtf/socket/event/WTFSocketEventListener.java
import wtf.socket.exception.WTFSocketException;
import wtf.socket.routing.item.WTFSocketRoutingItem;
package wtf.socket.event;
/**
* 事件监听者接口
* <p>
* Created by ZFly on 2017/4/25.
*/
@FunctionalInterface
public interface WTFSocketEventListener { | void eventOccurred(WTFSocketRoutingItem item, Object info) throws WTFSocketException; |
ZhangFly/WTFSocket_Server_JAVA | src/wtf/socket/controller/impl/WTFSocketEchoControllerImpl.java | // Path: src/wtf/socket/controller/WTFSocketController.java
// public interface WTFSocketController {
//
// /**
// * 控制器优先级
// * 数值越低优先级越高,默认的优先级为 WTFSocketPriority.MEDIUM
// *
// * @return 优先级数值
// */
// default int priority() {
// return WTFSocketPriority.MEDIUM;
// }
//
// /**
// * 是否响应该消息
// *
// * @param msg 消息对象
// *
// * @return 是否响应
// */
// boolean isResponse(WTFSocketMsg msg);
//
// /**
// * 控制器工作函数
// * 当控制器的isResponse()方法为true时调用
// * 当控制器工作完成后如果返回true表示该请求被消费,请求传递终止
// * 否则请求继续向下传递
// *
// * @param source 消息发送源
// * @param request 请求消息
// * @param responses 回复消息列表
// *
// * @return 请求是否被消费
// *
// * @throws WTFSocketException 异常消息
// */
// boolean work(WTFSocketRoutingItem source, WTFSocketMsg request, List<WTFSocketMsg> responses) throws WTFSocketException;
//
// }
//
// Path: src/wtf/socket/exception/WTFSocketException.java
// public abstract class WTFSocketException extends Exception {
//
//
// public WTFSocketException(String msg) {
// super(msg);
// }
//
// public abstract int getErrCode();
//
// }
//
// Path: src/wtf/socket/protocol/WTFSocketMsg.java
// public interface WTFSocketMsg {
//
// String getIoTag();
//
// void setIoTag(String ioTag);
//
// String getFrom();
//
// void setFrom(String from);
//
// String getTo();
//
// void setTo(String to);
//
// int getMsgId();
//
// void setMsgId(int msgId);
//
// int getMsgType();
//
// void setMsgType(int msgType);
//
// int getState();
//
// void setState(int state);
//
// void setConnectType(String connectType);
//
// String getConnectType();
//
// String getVersion();
//
// void setVersion(String version);
//
// Object getBody();
//
// <T> T getBody(Class<T> tClass);
//
// void setBody(Object body);
//
// WTFSocketMsg makeResponse();
// }
//
// Path: src/wtf/socket/routing/item/WTFSocketRoutingItem.java
// @Component
// @Scope("prototype")
// public abstract class WTFSocketRoutingItem {
//
// /**
// * 自身通讯地址
// */
// private String address;
// /**
// * 终端对象
// */
// private WTFSocketIOTerm term;
// /**
// * 接受的协议类型
// */
// private String accept;
// /**
// * 终端类型(iOS, Android, Hardware)
// */
// private String deviceType = "Unknown";
// /**
// * 是否允许覆盖
// */
// private boolean cover = true;
// /**
// * 允许用户为客户端添加自定义Tag信息
// */
// private Object tag;
//
// private WTFSocketServer context;
//
// public void setAddress(String address) {
// this.address = address;
// }
//
// public String getAddress() {
// return address;
// }
//
// public String getAccept() {
// return accept;
// }
//
// public void setAccept(String accept) {
// this.accept = accept;
// }
//
// public String getDeviceType() {
// return deviceType;
// }
//
// public void setDeviceType(String deviceType) {
// this.deviceType = deviceType == null ? "Unknown" : deviceType;
// }
//
// public WTFSocketIOTerm getTerm() {
// return term;
// }
//
// public void setTerm(WTFSocketIOTerm term) {
// this.term = term;
// }
//
// public boolean isCover() {
// return cover;
// }
//
// public void setCover(boolean cover) {
// this.cover = cover;
// }
//
// public WTFSocketServer getContext() {
// return context;
// }
//
// public void setContext(WTFSocketServer context) {
// this.context = context;
// }
//
// public Object getTag() {
// return tag;
// }
//
// public void setTag(Object tag) {
// this.tag = tag;
// }
//
// public void close() throws WTFSocketException {
// getContext().getEventsGroup().publishEvent(this, null, WTFSocketEventsType.Disconnect);
// getTerm().close();
// }
// }
| import wtf.socket.controller.WTFSocketController;
import wtf.socket.exception.WTFSocketException;
import wtf.socket.protocol.WTFSocketMsg;
import wtf.socket.routing.item.WTFSocketRoutingItem;
import java.util.List; | package wtf.socket.controller.impl;
/**
* 回声控制器
* <p>
* Created by ZFly on 2017/4/29.
*/
public enum WTFSocketEchoControllerImpl implements WTFSocketController {
INSTANCE;
@Override | // Path: src/wtf/socket/controller/WTFSocketController.java
// public interface WTFSocketController {
//
// /**
// * 控制器优先级
// * 数值越低优先级越高,默认的优先级为 WTFSocketPriority.MEDIUM
// *
// * @return 优先级数值
// */
// default int priority() {
// return WTFSocketPriority.MEDIUM;
// }
//
// /**
// * 是否响应该消息
// *
// * @param msg 消息对象
// *
// * @return 是否响应
// */
// boolean isResponse(WTFSocketMsg msg);
//
// /**
// * 控制器工作函数
// * 当控制器的isResponse()方法为true时调用
// * 当控制器工作完成后如果返回true表示该请求被消费,请求传递终止
// * 否则请求继续向下传递
// *
// * @param source 消息发送源
// * @param request 请求消息
// * @param responses 回复消息列表
// *
// * @return 请求是否被消费
// *
// * @throws WTFSocketException 异常消息
// */
// boolean work(WTFSocketRoutingItem source, WTFSocketMsg request, List<WTFSocketMsg> responses) throws WTFSocketException;
//
// }
//
// Path: src/wtf/socket/exception/WTFSocketException.java
// public abstract class WTFSocketException extends Exception {
//
//
// public WTFSocketException(String msg) {
// super(msg);
// }
//
// public abstract int getErrCode();
//
// }
//
// Path: src/wtf/socket/protocol/WTFSocketMsg.java
// public interface WTFSocketMsg {
//
// String getIoTag();
//
// void setIoTag(String ioTag);
//
// String getFrom();
//
// void setFrom(String from);
//
// String getTo();
//
// void setTo(String to);
//
// int getMsgId();
//
// void setMsgId(int msgId);
//
// int getMsgType();
//
// void setMsgType(int msgType);
//
// int getState();
//
// void setState(int state);
//
// void setConnectType(String connectType);
//
// String getConnectType();
//
// String getVersion();
//
// void setVersion(String version);
//
// Object getBody();
//
// <T> T getBody(Class<T> tClass);
//
// void setBody(Object body);
//
// WTFSocketMsg makeResponse();
// }
//
// Path: src/wtf/socket/routing/item/WTFSocketRoutingItem.java
// @Component
// @Scope("prototype")
// public abstract class WTFSocketRoutingItem {
//
// /**
// * 自身通讯地址
// */
// private String address;
// /**
// * 终端对象
// */
// private WTFSocketIOTerm term;
// /**
// * 接受的协议类型
// */
// private String accept;
// /**
// * 终端类型(iOS, Android, Hardware)
// */
// private String deviceType = "Unknown";
// /**
// * 是否允许覆盖
// */
// private boolean cover = true;
// /**
// * 允许用户为客户端添加自定义Tag信息
// */
// private Object tag;
//
// private WTFSocketServer context;
//
// public void setAddress(String address) {
// this.address = address;
// }
//
// public String getAddress() {
// return address;
// }
//
// public String getAccept() {
// return accept;
// }
//
// public void setAccept(String accept) {
// this.accept = accept;
// }
//
// public String getDeviceType() {
// return deviceType;
// }
//
// public void setDeviceType(String deviceType) {
// this.deviceType = deviceType == null ? "Unknown" : deviceType;
// }
//
// public WTFSocketIOTerm getTerm() {
// return term;
// }
//
// public void setTerm(WTFSocketIOTerm term) {
// this.term = term;
// }
//
// public boolean isCover() {
// return cover;
// }
//
// public void setCover(boolean cover) {
// this.cover = cover;
// }
//
// public WTFSocketServer getContext() {
// return context;
// }
//
// public void setContext(WTFSocketServer context) {
// this.context = context;
// }
//
// public Object getTag() {
// return tag;
// }
//
// public void setTag(Object tag) {
// this.tag = tag;
// }
//
// public void close() throws WTFSocketException {
// getContext().getEventsGroup().publishEvent(this, null, WTFSocketEventsType.Disconnect);
// getTerm().close();
// }
// }
// Path: src/wtf/socket/controller/impl/WTFSocketEchoControllerImpl.java
import wtf.socket.controller.WTFSocketController;
import wtf.socket.exception.WTFSocketException;
import wtf.socket.protocol.WTFSocketMsg;
import wtf.socket.routing.item.WTFSocketRoutingItem;
import java.util.List;
package wtf.socket.controller.impl;
/**
* 回声控制器
* <p>
* Created by ZFly on 2017/4/29.
*/
public enum WTFSocketEchoControllerImpl implements WTFSocketController {
INSTANCE;
@Override | public boolean isResponse(WTFSocketMsg msg) { |
ZhangFly/WTFSocket_Server_JAVA | src/wtf/socket/controller/impl/WTFSocketEchoControllerImpl.java | // Path: src/wtf/socket/controller/WTFSocketController.java
// public interface WTFSocketController {
//
// /**
// * 控制器优先级
// * 数值越低优先级越高,默认的优先级为 WTFSocketPriority.MEDIUM
// *
// * @return 优先级数值
// */
// default int priority() {
// return WTFSocketPriority.MEDIUM;
// }
//
// /**
// * 是否响应该消息
// *
// * @param msg 消息对象
// *
// * @return 是否响应
// */
// boolean isResponse(WTFSocketMsg msg);
//
// /**
// * 控制器工作函数
// * 当控制器的isResponse()方法为true时调用
// * 当控制器工作完成后如果返回true表示该请求被消费,请求传递终止
// * 否则请求继续向下传递
// *
// * @param source 消息发送源
// * @param request 请求消息
// * @param responses 回复消息列表
// *
// * @return 请求是否被消费
// *
// * @throws WTFSocketException 异常消息
// */
// boolean work(WTFSocketRoutingItem source, WTFSocketMsg request, List<WTFSocketMsg> responses) throws WTFSocketException;
//
// }
//
// Path: src/wtf/socket/exception/WTFSocketException.java
// public abstract class WTFSocketException extends Exception {
//
//
// public WTFSocketException(String msg) {
// super(msg);
// }
//
// public abstract int getErrCode();
//
// }
//
// Path: src/wtf/socket/protocol/WTFSocketMsg.java
// public interface WTFSocketMsg {
//
// String getIoTag();
//
// void setIoTag(String ioTag);
//
// String getFrom();
//
// void setFrom(String from);
//
// String getTo();
//
// void setTo(String to);
//
// int getMsgId();
//
// void setMsgId(int msgId);
//
// int getMsgType();
//
// void setMsgType(int msgType);
//
// int getState();
//
// void setState(int state);
//
// void setConnectType(String connectType);
//
// String getConnectType();
//
// String getVersion();
//
// void setVersion(String version);
//
// Object getBody();
//
// <T> T getBody(Class<T> tClass);
//
// void setBody(Object body);
//
// WTFSocketMsg makeResponse();
// }
//
// Path: src/wtf/socket/routing/item/WTFSocketRoutingItem.java
// @Component
// @Scope("prototype")
// public abstract class WTFSocketRoutingItem {
//
// /**
// * 自身通讯地址
// */
// private String address;
// /**
// * 终端对象
// */
// private WTFSocketIOTerm term;
// /**
// * 接受的协议类型
// */
// private String accept;
// /**
// * 终端类型(iOS, Android, Hardware)
// */
// private String deviceType = "Unknown";
// /**
// * 是否允许覆盖
// */
// private boolean cover = true;
// /**
// * 允许用户为客户端添加自定义Tag信息
// */
// private Object tag;
//
// private WTFSocketServer context;
//
// public void setAddress(String address) {
// this.address = address;
// }
//
// public String getAddress() {
// return address;
// }
//
// public String getAccept() {
// return accept;
// }
//
// public void setAccept(String accept) {
// this.accept = accept;
// }
//
// public String getDeviceType() {
// return deviceType;
// }
//
// public void setDeviceType(String deviceType) {
// this.deviceType = deviceType == null ? "Unknown" : deviceType;
// }
//
// public WTFSocketIOTerm getTerm() {
// return term;
// }
//
// public void setTerm(WTFSocketIOTerm term) {
// this.term = term;
// }
//
// public boolean isCover() {
// return cover;
// }
//
// public void setCover(boolean cover) {
// this.cover = cover;
// }
//
// public WTFSocketServer getContext() {
// return context;
// }
//
// public void setContext(WTFSocketServer context) {
// this.context = context;
// }
//
// public Object getTag() {
// return tag;
// }
//
// public void setTag(Object tag) {
// this.tag = tag;
// }
//
// public void close() throws WTFSocketException {
// getContext().getEventsGroup().publishEvent(this, null, WTFSocketEventsType.Disconnect);
// getTerm().close();
// }
// }
| import wtf.socket.controller.WTFSocketController;
import wtf.socket.exception.WTFSocketException;
import wtf.socket.protocol.WTFSocketMsg;
import wtf.socket.routing.item.WTFSocketRoutingItem;
import java.util.List; | package wtf.socket.controller.impl;
/**
* 回声控制器
* <p>
* Created by ZFly on 2017/4/29.
*/
public enum WTFSocketEchoControllerImpl implements WTFSocketController {
INSTANCE;
@Override
public boolean isResponse(WTFSocketMsg msg) {
return true;
}
@Override | // Path: src/wtf/socket/controller/WTFSocketController.java
// public interface WTFSocketController {
//
// /**
// * 控制器优先级
// * 数值越低优先级越高,默认的优先级为 WTFSocketPriority.MEDIUM
// *
// * @return 优先级数值
// */
// default int priority() {
// return WTFSocketPriority.MEDIUM;
// }
//
// /**
// * 是否响应该消息
// *
// * @param msg 消息对象
// *
// * @return 是否响应
// */
// boolean isResponse(WTFSocketMsg msg);
//
// /**
// * 控制器工作函数
// * 当控制器的isResponse()方法为true时调用
// * 当控制器工作完成后如果返回true表示该请求被消费,请求传递终止
// * 否则请求继续向下传递
// *
// * @param source 消息发送源
// * @param request 请求消息
// * @param responses 回复消息列表
// *
// * @return 请求是否被消费
// *
// * @throws WTFSocketException 异常消息
// */
// boolean work(WTFSocketRoutingItem source, WTFSocketMsg request, List<WTFSocketMsg> responses) throws WTFSocketException;
//
// }
//
// Path: src/wtf/socket/exception/WTFSocketException.java
// public abstract class WTFSocketException extends Exception {
//
//
// public WTFSocketException(String msg) {
// super(msg);
// }
//
// public abstract int getErrCode();
//
// }
//
// Path: src/wtf/socket/protocol/WTFSocketMsg.java
// public interface WTFSocketMsg {
//
// String getIoTag();
//
// void setIoTag(String ioTag);
//
// String getFrom();
//
// void setFrom(String from);
//
// String getTo();
//
// void setTo(String to);
//
// int getMsgId();
//
// void setMsgId(int msgId);
//
// int getMsgType();
//
// void setMsgType(int msgType);
//
// int getState();
//
// void setState(int state);
//
// void setConnectType(String connectType);
//
// String getConnectType();
//
// String getVersion();
//
// void setVersion(String version);
//
// Object getBody();
//
// <T> T getBody(Class<T> tClass);
//
// void setBody(Object body);
//
// WTFSocketMsg makeResponse();
// }
//
// Path: src/wtf/socket/routing/item/WTFSocketRoutingItem.java
// @Component
// @Scope("prototype")
// public abstract class WTFSocketRoutingItem {
//
// /**
// * 自身通讯地址
// */
// private String address;
// /**
// * 终端对象
// */
// private WTFSocketIOTerm term;
// /**
// * 接受的协议类型
// */
// private String accept;
// /**
// * 终端类型(iOS, Android, Hardware)
// */
// private String deviceType = "Unknown";
// /**
// * 是否允许覆盖
// */
// private boolean cover = true;
// /**
// * 允许用户为客户端添加自定义Tag信息
// */
// private Object tag;
//
// private WTFSocketServer context;
//
// public void setAddress(String address) {
// this.address = address;
// }
//
// public String getAddress() {
// return address;
// }
//
// public String getAccept() {
// return accept;
// }
//
// public void setAccept(String accept) {
// this.accept = accept;
// }
//
// public String getDeviceType() {
// return deviceType;
// }
//
// public void setDeviceType(String deviceType) {
// this.deviceType = deviceType == null ? "Unknown" : deviceType;
// }
//
// public WTFSocketIOTerm getTerm() {
// return term;
// }
//
// public void setTerm(WTFSocketIOTerm term) {
// this.term = term;
// }
//
// public boolean isCover() {
// return cover;
// }
//
// public void setCover(boolean cover) {
// this.cover = cover;
// }
//
// public WTFSocketServer getContext() {
// return context;
// }
//
// public void setContext(WTFSocketServer context) {
// this.context = context;
// }
//
// public Object getTag() {
// return tag;
// }
//
// public void setTag(Object tag) {
// this.tag = tag;
// }
//
// public void close() throws WTFSocketException {
// getContext().getEventsGroup().publishEvent(this, null, WTFSocketEventsType.Disconnect);
// getTerm().close();
// }
// }
// Path: src/wtf/socket/controller/impl/WTFSocketEchoControllerImpl.java
import wtf.socket.controller.WTFSocketController;
import wtf.socket.exception.WTFSocketException;
import wtf.socket.protocol.WTFSocketMsg;
import wtf.socket.routing.item.WTFSocketRoutingItem;
import java.util.List;
package wtf.socket.controller.impl;
/**
* 回声控制器
* <p>
* Created by ZFly on 2017/4/29.
*/
public enum WTFSocketEchoControllerImpl implements WTFSocketController {
INSTANCE;
@Override
public boolean isResponse(WTFSocketMsg msg) {
return true;
}
@Override | public boolean work(WTFSocketRoutingItem source, WTFSocketMsg request, List<WTFSocketMsg> responses) throws WTFSocketException { |
ZhangFly/WTFSocket_Server_JAVA | src/wtf/socket/controller/impl/WTFSocketEchoControllerImpl.java | // Path: src/wtf/socket/controller/WTFSocketController.java
// public interface WTFSocketController {
//
// /**
// * 控制器优先级
// * 数值越低优先级越高,默认的优先级为 WTFSocketPriority.MEDIUM
// *
// * @return 优先级数值
// */
// default int priority() {
// return WTFSocketPriority.MEDIUM;
// }
//
// /**
// * 是否响应该消息
// *
// * @param msg 消息对象
// *
// * @return 是否响应
// */
// boolean isResponse(WTFSocketMsg msg);
//
// /**
// * 控制器工作函数
// * 当控制器的isResponse()方法为true时调用
// * 当控制器工作完成后如果返回true表示该请求被消费,请求传递终止
// * 否则请求继续向下传递
// *
// * @param source 消息发送源
// * @param request 请求消息
// * @param responses 回复消息列表
// *
// * @return 请求是否被消费
// *
// * @throws WTFSocketException 异常消息
// */
// boolean work(WTFSocketRoutingItem source, WTFSocketMsg request, List<WTFSocketMsg> responses) throws WTFSocketException;
//
// }
//
// Path: src/wtf/socket/exception/WTFSocketException.java
// public abstract class WTFSocketException extends Exception {
//
//
// public WTFSocketException(String msg) {
// super(msg);
// }
//
// public abstract int getErrCode();
//
// }
//
// Path: src/wtf/socket/protocol/WTFSocketMsg.java
// public interface WTFSocketMsg {
//
// String getIoTag();
//
// void setIoTag(String ioTag);
//
// String getFrom();
//
// void setFrom(String from);
//
// String getTo();
//
// void setTo(String to);
//
// int getMsgId();
//
// void setMsgId(int msgId);
//
// int getMsgType();
//
// void setMsgType(int msgType);
//
// int getState();
//
// void setState(int state);
//
// void setConnectType(String connectType);
//
// String getConnectType();
//
// String getVersion();
//
// void setVersion(String version);
//
// Object getBody();
//
// <T> T getBody(Class<T> tClass);
//
// void setBody(Object body);
//
// WTFSocketMsg makeResponse();
// }
//
// Path: src/wtf/socket/routing/item/WTFSocketRoutingItem.java
// @Component
// @Scope("prototype")
// public abstract class WTFSocketRoutingItem {
//
// /**
// * 自身通讯地址
// */
// private String address;
// /**
// * 终端对象
// */
// private WTFSocketIOTerm term;
// /**
// * 接受的协议类型
// */
// private String accept;
// /**
// * 终端类型(iOS, Android, Hardware)
// */
// private String deviceType = "Unknown";
// /**
// * 是否允许覆盖
// */
// private boolean cover = true;
// /**
// * 允许用户为客户端添加自定义Tag信息
// */
// private Object tag;
//
// private WTFSocketServer context;
//
// public void setAddress(String address) {
// this.address = address;
// }
//
// public String getAddress() {
// return address;
// }
//
// public String getAccept() {
// return accept;
// }
//
// public void setAccept(String accept) {
// this.accept = accept;
// }
//
// public String getDeviceType() {
// return deviceType;
// }
//
// public void setDeviceType(String deviceType) {
// this.deviceType = deviceType == null ? "Unknown" : deviceType;
// }
//
// public WTFSocketIOTerm getTerm() {
// return term;
// }
//
// public void setTerm(WTFSocketIOTerm term) {
// this.term = term;
// }
//
// public boolean isCover() {
// return cover;
// }
//
// public void setCover(boolean cover) {
// this.cover = cover;
// }
//
// public WTFSocketServer getContext() {
// return context;
// }
//
// public void setContext(WTFSocketServer context) {
// this.context = context;
// }
//
// public Object getTag() {
// return tag;
// }
//
// public void setTag(Object tag) {
// this.tag = tag;
// }
//
// public void close() throws WTFSocketException {
// getContext().getEventsGroup().publishEvent(this, null, WTFSocketEventsType.Disconnect);
// getTerm().close();
// }
// }
| import wtf.socket.controller.WTFSocketController;
import wtf.socket.exception.WTFSocketException;
import wtf.socket.protocol.WTFSocketMsg;
import wtf.socket.routing.item.WTFSocketRoutingItem;
import java.util.List; | package wtf.socket.controller.impl;
/**
* 回声控制器
* <p>
* Created by ZFly on 2017/4/29.
*/
public enum WTFSocketEchoControllerImpl implements WTFSocketController {
INSTANCE;
@Override
public boolean isResponse(WTFSocketMsg msg) {
return true;
}
@Override | // Path: src/wtf/socket/controller/WTFSocketController.java
// public interface WTFSocketController {
//
// /**
// * 控制器优先级
// * 数值越低优先级越高,默认的优先级为 WTFSocketPriority.MEDIUM
// *
// * @return 优先级数值
// */
// default int priority() {
// return WTFSocketPriority.MEDIUM;
// }
//
// /**
// * 是否响应该消息
// *
// * @param msg 消息对象
// *
// * @return 是否响应
// */
// boolean isResponse(WTFSocketMsg msg);
//
// /**
// * 控制器工作函数
// * 当控制器的isResponse()方法为true时调用
// * 当控制器工作完成后如果返回true表示该请求被消费,请求传递终止
// * 否则请求继续向下传递
// *
// * @param source 消息发送源
// * @param request 请求消息
// * @param responses 回复消息列表
// *
// * @return 请求是否被消费
// *
// * @throws WTFSocketException 异常消息
// */
// boolean work(WTFSocketRoutingItem source, WTFSocketMsg request, List<WTFSocketMsg> responses) throws WTFSocketException;
//
// }
//
// Path: src/wtf/socket/exception/WTFSocketException.java
// public abstract class WTFSocketException extends Exception {
//
//
// public WTFSocketException(String msg) {
// super(msg);
// }
//
// public abstract int getErrCode();
//
// }
//
// Path: src/wtf/socket/protocol/WTFSocketMsg.java
// public interface WTFSocketMsg {
//
// String getIoTag();
//
// void setIoTag(String ioTag);
//
// String getFrom();
//
// void setFrom(String from);
//
// String getTo();
//
// void setTo(String to);
//
// int getMsgId();
//
// void setMsgId(int msgId);
//
// int getMsgType();
//
// void setMsgType(int msgType);
//
// int getState();
//
// void setState(int state);
//
// void setConnectType(String connectType);
//
// String getConnectType();
//
// String getVersion();
//
// void setVersion(String version);
//
// Object getBody();
//
// <T> T getBody(Class<T> tClass);
//
// void setBody(Object body);
//
// WTFSocketMsg makeResponse();
// }
//
// Path: src/wtf/socket/routing/item/WTFSocketRoutingItem.java
// @Component
// @Scope("prototype")
// public abstract class WTFSocketRoutingItem {
//
// /**
// * 自身通讯地址
// */
// private String address;
// /**
// * 终端对象
// */
// private WTFSocketIOTerm term;
// /**
// * 接受的协议类型
// */
// private String accept;
// /**
// * 终端类型(iOS, Android, Hardware)
// */
// private String deviceType = "Unknown";
// /**
// * 是否允许覆盖
// */
// private boolean cover = true;
// /**
// * 允许用户为客户端添加自定义Tag信息
// */
// private Object tag;
//
// private WTFSocketServer context;
//
// public void setAddress(String address) {
// this.address = address;
// }
//
// public String getAddress() {
// return address;
// }
//
// public String getAccept() {
// return accept;
// }
//
// public void setAccept(String accept) {
// this.accept = accept;
// }
//
// public String getDeviceType() {
// return deviceType;
// }
//
// public void setDeviceType(String deviceType) {
// this.deviceType = deviceType == null ? "Unknown" : deviceType;
// }
//
// public WTFSocketIOTerm getTerm() {
// return term;
// }
//
// public void setTerm(WTFSocketIOTerm term) {
// this.term = term;
// }
//
// public boolean isCover() {
// return cover;
// }
//
// public void setCover(boolean cover) {
// this.cover = cover;
// }
//
// public WTFSocketServer getContext() {
// return context;
// }
//
// public void setContext(WTFSocketServer context) {
// this.context = context;
// }
//
// public Object getTag() {
// return tag;
// }
//
// public void setTag(Object tag) {
// this.tag = tag;
// }
//
// public void close() throws WTFSocketException {
// getContext().getEventsGroup().publishEvent(this, null, WTFSocketEventsType.Disconnect);
// getTerm().close();
// }
// }
// Path: src/wtf/socket/controller/impl/WTFSocketEchoControllerImpl.java
import wtf.socket.controller.WTFSocketController;
import wtf.socket.exception.WTFSocketException;
import wtf.socket.protocol.WTFSocketMsg;
import wtf.socket.routing.item.WTFSocketRoutingItem;
import java.util.List;
package wtf.socket.controller.impl;
/**
* 回声控制器
* <p>
* Created by ZFly on 2017/4/29.
*/
public enum WTFSocketEchoControllerImpl implements WTFSocketController {
INSTANCE;
@Override
public boolean isResponse(WTFSocketMsg msg) {
return true;
}
@Override | public boolean work(WTFSocketRoutingItem source, WTFSocketMsg request, List<WTFSocketMsg> responses) throws WTFSocketException { |
ZhangFly/WTFSocket_Server_JAVA | src/wtf/socket/protocol/WTFSocketProtocolFamily.java | // Path: src/wtf/socket/exception/fatal/WTFSocketProtocolBrokenException.java
// public class WTFSocketProtocolBrokenException extends WTFSocketFatalException {
//
// public WTFSocketProtocolBrokenException(String msg) {
// super(msg);
// }
//
// public int getErrCode() {
// return 64;
// }
// }
//
// Path: src/wtf/socket/exception/fatal/WTFSocketProtocolUnsupportedException.java
// public class WTFSocketProtocolUnsupportedException extends WTFSocketFatalException {
//
// public WTFSocketProtocolUnsupportedException(String msg) {
// super(msg);
// }
//
// public int getErrCode() {
// return 65;
// }
// }
//
// Path: src/wtf/socket/protocol/msg/WTFSocketDefaultProtocolParser.java
// public class WTFSocketDefaultProtocolParser implements WTFSocketProtocolParser {
//
//
// @Override
// public int getPriority() {
// return WTFSocketPriority.LOWEST;
// }
//
// @Override
// public boolean isResponse(String data) {
// return StringUtils.startsWith(data, "{") && StringUtils.endsWith(data, "}");
// }
//
// @Override
// public boolean isResponse(WTFSocketMsg msg) {
// return StringUtils.equals(msg.getVersion(), "2.0");
// }
//
// @Override
// public WTFSocketMsg parse(String data) throws WTFSocketProtocolBrokenException {
// try {
// return JSON.parseObject(data, WTFSocketDefaultMsg.class);
// } catch (Exception e) {
// throw new WTFSocketProtocolBrokenException("Protocol broken [" + e.getMessage() + "]");
// }
// }
//
// @Override
// public String parse(WTFSocketMsg msg) {
// return JSON.toJSONString(msg);
// }
// }
| import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import wtf.socket.exception.fatal.WTFSocketProtocolBrokenException;
import wtf.socket.exception.fatal.WTFSocketProtocolUnsupportedException;
import wtf.socket.protocol.msg.WTFSocketDefaultProtocolParser;
import java.util.*; | package wtf.socket.protocol;
/**
* 协议簇,通过向协议簇注册解析器
* 将不同协议的数据包统一转化到 WTFSocketMsg
* <p>
* Created by ZFly on 2017/4/21.
*/
@Component
@Scope("prototype")
public class WTFSocketProtocolFamily {
/**
* 解析器列表
*/
private Queue<WTFSocketProtocolParser> parsers = new PriorityQueue<WTFSocketProtocolParser>(Comparator.comparingInt(WTFSocketProtocolParser::getPriority)) {{ | // Path: src/wtf/socket/exception/fatal/WTFSocketProtocolBrokenException.java
// public class WTFSocketProtocolBrokenException extends WTFSocketFatalException {
//
// public WTFSocketProtocolBrokenException(String msg) {
// super(msg);
// }
//
// public int getErrCode() {
// return 64;
// }
// }
//
// Path: src/wtf/socket/exception/fatal/WTFSocketProtocolUnsupportedException.java
// public class WTFSocketProtocolUnsupportedException extends WTFSocketFatalException {
//
// public WTFSocketProtocolUnsupportedException(String msg) {
// super(msg);
// }
//
// public int getErrCode() {
// return 65;
// }
// }
//
// Path: src/wtf/socket/protocol/msg/WTFSocketDefaultProtocolParser.java
// public class WTFSocketDefaultProtocolParser implements WTFSocketProtocolParser {
//
//
// @Override
// public int getPriority() {
// return WTFSocketPriority.LOWEST;
// }
//
// @Override
// public boolean isResponse(String data) {
// return StringUtils.startsWith(data, "{") && StringUtils.endsWith(data, "}");
// }
//
// @Override
// public boolean isResponse(WTFSocketMsg msg) {
// return StringUtils.equals(msg.getVersion(), "2.0");
// }
//
// @Override
// public WTFSocketMsg parse(String data) throws WTFSocketProtocolBrokenException {
// try {
// return JSON.parseObject(data, WTFSocketDefaultMsg.class);
// } catch (Exception e) {
// throw new WTFSocketProtocolBrokenException("Protocol broken [" + e.getMessage() + "]");
// }
// }
//
// @Override
// public String parse(WTFSocketMsg msg) {
// return JSON.toJSONString(msg);
// }
// }
// Path: src/wtf/socket/protocol/WTFSocketProtocolFamily.java
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import wtf.socket.exception.fatal.WTFSocketProtocolBrokenException;
import wtf.socket.exception.fatal.WTFSocketProtocolUnsupportedException;
import wtf.socket.protocol.msg.WTFSocketDefaultProtocolParser;
import java.util.*;
package wtf.socket.protocol;
/**
* 协议簇,通过向协议簇注册解析器
* 将不同协议的数据包统一转化到 WTFSocketMsg
* <p>
* Created by ZFly on 2017/4/21.
*/
@Component
@Scope("prototype")
public class WTFSocketProtocolFamily {
/**
* 解析器列表
*/
private Queue<WTFSocketProtocolParser> parsers = new PriorityQueue<WTFSocketProtocolParser>(Comparator.comparingInt(WTFSocketProtocolParser::getPriority)) {{ | add(new WTFSocketDefaultProtocolParser()); |
ZhangFly/WTFSocket_Server_JAVA | src/wtf/socket/protocol/WTFSocketProtocolFamily.java | // Path: src/wtf/socket/exception/fatal/WTFSocketProtocolBrokenException.java
// public class WTFSocketProtocolBrokenException extends WTFSocketFatalException {
//
// public WTFSocketProtocolBrokenException(String msg) {
// super(msg);
// }
//
// public int getErrCode() {
// return 64;
// }
// }
//
// Path: src/wtf/socket/exception/fatal/WTFSocketProtocolUnsupportedException.java
// public class WTFSocketProtocolUnsupportedException extends WTFSocketFatalException {
//
// public WTFSocketProtocolUnsupportedException(String msg) {
// super(msg);
// }
//
// public int getErrCode() {
// return 65;
// }
// }
//
// Path: src/wtf/socket/protocol/msg/WTFSocketDefaultProtocolParser.java
// public class WTFSocketDefaultProtocolParser implements WTFSocketProtocolParser {
//
//
// @Override
// public int getPriority() {
// return WTFSocketPriority.LOWEST;
// }
//
// @Override
// public boolean isResponse(String data) {
// return StringUtils.startsWith(data, "{") && StringUtils.endsWith(data, "}");
// }
//
// @Override
// public boolean isResponse(WTFSocketMsg msg) {
// return StringUtils.equals(msg.getVersion(), "2.0");
// }
//
// @Override
// public WTFSocketMsg parse(String data) throws WTFSocketProtocolBrokenException {
// try {
// return JSON.parseObject(data, WTFSocketDefaultMsg.class);
// } catch (Exception e) {
// throw new WTFSocketProtocolBrokenException("Protocol broken [" + e.getMessage() + "]");
// }
// }
//
// @Override
// public String parse(WTFSocketMsg msg) {
// return JSON.toJSONString(msg);
// }
// }
| import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import wtf.socket.exception.fatal.WTFSocketProtocolBrokenException;
import wtf.socket.exception.fatal.WTFSocketProtocolUnsupportedException;
import wtf.socket.protocol.msg.WTFSocketDefaultProtocolParser;
import java.util.*; | package wtf.socket.protocol;
/**
* 协议簇,通过向协议簇注册解析器
* 将不同协议的数据包统一转化到 WTFSocketMsg
* <p>
* Created by ZFly on 2017/4/21.
*/
@Component
@Scope("prototype")
public class WTFSocketProtocolFamily {
/**
* 解析器列表
*/
private Queue<WTFSocketProtocolParser> parsers = new PriorityQueue<WTFSocketProtocolParser>(Comparator.comparingInt(WTFSocketProtocolParser::getPriority)) {{
add(new WTFSocketDefaultProtocolParser());
}};
/**
* 选择解析器从字符串数据中解析出消息对象
*
* @param data 字符串数据
*
* @return 消息对象
*
* @throws WTFSocketProtocolBrokenException 消息格式错误
* @throws WTFSocketProtocolUnsupportedException 没有适合的解析器
*/ | // Path: src/wtf/socket/exception/fatal/WTFSocketProtocolBrokenException.java
// public class WTFSocketProtocolBrokenException extends WTFSocketFatalException {
//
// public WTFSocketProtocolBrokenException(String msg) {
// super(msg);
// }
//
// public int getErrCode() {
// return 64;
// }
// }
//
// Path: src/wtf/socket/exception/fatal/WTFSocketProtocolUnsupportedException.java
// public class WTFSocketProtocolUnsupportedException extends WTFSocketFatalException {
//
// public WTFSocketProtocolUnsupportedException(String msg) {
// super(msg);
// }
//
// public int getErrCode() {
// return 65;
// }
// }
//
// Path: src/wtf/socket/protocol/msg/WTFSocketDefaultProtocolParser.java
// public class WTFSocketDefaultProtocolParser implements WTFSocketProtocolParser {
//
//
// @Override
// public int getPriority() {
// return WTFSocketPriority.LOWEST;
// }
//
// @Override
// public boolean isResponse(String data) {
// return StringUtils.startsWith(data, "{") && StringUtils.endsWith(data, "}");
// }
//
// @Override
// public boolean isResponse(WTFSocketMsg msg) {
// return StringUtils.equals(msg.getVersion(), "2.0");
// }
//
// @Override
// public WTFSocketMsg parse(String data) throws WTFSocketProtocolBrokenException {
// try {
// return JSON.parseObject(data, WTFSocketDefaultMsg.class);
// } catch (Exception e) {
// throw new WTFSocketProtocolBrokenException("Protocol broken [" + e.getMessage() + "]");
// }
// }
//
// @Override
// public String parse(WTFSocketMsg msg) {
// return JSON.toJSONString(msg);
// }
// }
// Path: src/wtf/socket/protocol/WTFSocketProtocolFamily.java
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import wtf.socket.exception.fatal.WTFSocketProtocolBrokenException;
import wtf.socket.exception.fatal.WTFSocketProtocolUnsupportedException;
import wtf.socket.protocol.msg.WTFSocketDefaultProtocolParser;
import java.util.*;
package wtf.socket.protocol;
/**
* 协议簇,通过向协议簇注册解析器
* 将不同协议的数据包统一转化到 WTFSocketMsg
* <p>
* Created by ZFly on 2017/4/21.
*/
@Component
@Scope("prototype")
public class WTFSocketProtocolFamily {
/**
* 解析器列表
*/
private Queue<WTFSocketProtocolParser> parsers = new PriorityQueue<WTFSocketProtocolParser>(Comparator.comparingInt(WTFSocketProtocolParser::getPriority)) {{
add(new WTFSocketDefaultProtocolParser());
}};
/**
* 选择解析器从字符串数据中解析出消息对象
*
* @param data 字符串数据
*
* @return 消息对象
*
* @throws WTFSocketProtocolBrokenException 消息格式错误
* @throws WTFSocketProtocolUnsupportedException 没有适合的解析器
*/ | public WTFSocketMsg parse(String data) throws WTFSocketProtocolBrokenException, WTFSocketProtocolUnsupportedException { |
ZhangFly/WTFSocket_Server_JAVA | src/wtf/socket/protocol/WTFSocketProtocolFamily.java | // Path: src/wtf/socket/exception/fatal/WTFSocketProtocolBrokenException.java
// public class WTFSocketProtocolBrokenException extends WTFSocketFatalException {
//
// public WTFSocketProtocolBrokenException(String msg) {
// super(msg);
// }
//
// public int getErrCode() {
// return 64;
// }
// }
//
// Path: src/wtf/socket/exception/fatal/WTFSocketProtocolUnsupportedException.java
// public class WTFSocketProtocolUnsupportedException extends WTFSocketFatalException {
//
// public WTFSocketProtocolUnsupportedException(String msg) {
// super(msg);
// }
//
// public int getErrCode() {
// return 65;
// }
// }
//
// Path: src/wtf/socket/protocol/msg/WTFSocketDefaultProtocolParser.java
// public class WTFSocketDefaultProtocolParser implements WTFSocketProtocolParser {
//
//
// @Override
// public int getPriority() {
// return WTFSocketPriority.LOWEST;
// }
//
// @Override
// public boolean isResponse(String data) {
// return StringUtils.startsWith(data, "{") && StringUtils.endsWith(data, "}");
// }
//
// @Override
// public boolean isResponse(WTFSocketMsg msg) {
// return StringUtils.equals(msg.getVersion(), "2.0");
// }
//
// @Override
// public WTFSocketMsg parse(String data) throws WTFSocketProtocolBrokenException {
// try {
// return JSON.parseObject(data, WTFSocketDefaultMsg.class);
// } catch (Exception e) {
// throw new WTFSocketProtocolBrokenException("Protocol broken [" + e.getMessage() + "]");
// }
// }
//
// @Override
// public String parse(WTFSocketMsg msg) {
// return JSON.toJSONString(msg);
// }
// }
| import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import wtf.socket.exception.fatal.WTFSocketProtocolBrokenException;
import wtf.socket.exception.fatal.WTFSocketProtocolUnsupportedException;
import wtf.socket.protocol.msg.WTFSocketDefaultProtocolParser;
import java.util.*; | package wtf.socket.protocol;
/**
* 协议簇,通过向协议簇注册解析器
* 将不同协议的数据包统一转化到 WTFSocketMsg
* <p>
* Created by ZFly on 2017/4/21.
*/
@Component
@Scope("prototype")
public class WTFSocketProtocolFamily {
/**
* 解析器列表
*/
private Queue<WTFSocketProtocolParser> parsers = new PriorityQueue<WTFSocketProtocolParser>(Comparator.comparingInt(WTFSocketProtocolParser::getPriority)) {{
add(new WTFSocketDefaultProtocolParser());
}};
/**
* 选择解析器从字符串数据中解析出消息对象
*
* @param data 字符串数据
*
* @return 消息对象
*
* @throws WTFSocketProtocolBrokenException 消息格式错误
* @throws WTFSocketProtocolUnsupportedException 没有适合的解析器
*/ | // Path: src/wtf/socket/exception/fatal/WTFSocketProtocolBrokenException.java
// public class WTFSocketProtocolBrokenException extends WTFSocketFatalException {
//
// public WTFSocketProtocolBrokenException(String msg) {
// super(msg);
// }
//
// public int getErrCode() {
// return 64;
// }
// }
//
// Path: src/wtf/socket/exception/fatal/WTFSocketProtocolUnsupportedException.java
// public class WTFSocketProtocolUnsupportedException extends WTFSocketFatalException {
//
// public WTFSocketProtocolUnsupportedException(String msg) {
// super(msg);
// }
//
// public int getErrCode() {
// return 65;
// }
// }
//
// Path: src/wtf/socket/protocol/msg/WTFSocketDefaultProtocolParser.java
// public class WTFSocketDefaultProtocolParser implements WTFSocketProtocolParser {
//
//
// @Override
// public int getPriority() {
// return WTFSocketPriority.LOWEST;
// }
//
// @Override
// public boolean isResponse(String data) {
// return StringUtils.startsWith(data, "{") && StringUtils.endsWith(data, "}");
// }
//
// @Override
// public boolean isResponse(WTFSocketMsg msg) {
// return StringUtils.equals(msg.getVersion(), "2.0");
// }
//
// @Override
// public WTFSocketMsg parse(String data) throws WTFSocketProtocolBrokenException {
// try {
// return JSON.parseObject(data, WTFSocketDefaultMsg.class);
// } catch (Exception e) {
// throw new WTFSocketProtocolBrokenException("Protocol broken [" + e.getMessage() + "]");
// }
// }
//
// @Override
// public String parse(WTFSocketMsg msg) {
// return JSON.toJSONString(msg);
// }
// }
// Path: src/wtf/socket/protocol/WTFSocketProtocolFamily.java
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import wtf.socket.exception.fatal.WTFSocketProtocolBrokenException;
import wtf.socket.exception.fatal.WTFSocketProtocolUnsupportedException;
import wtf.socket.protocol.msg.WTFSocketDefaultProtocolParser;
import java.util.*;
package wtf.socket.protocol;
/**
* 协议簇,通过向协议簇注册解析器
* 将不同协议的数据包统一转化到 WTFSocketMsg
* <p>
* Created by ZFly on 2017/4/21.
*/
@Component
@Scope("prototype")
public class WTFSocketProtocolFamily {
/**
* 解析器列表
*/
private Queue<WTFSocketProtocolParser> parsers = new PriorityQueue<WTFSocketProtocolParser>(Comparator.comparingInt(WTFSocketProtocolParser::getPriority)) {{
add(new WTFSocketDefaultProtocolParser());
}};
/**
* 选择解析器从字符串数据中解析出消息对象
*
* @param data 字符串数据
*
* @return 消息对象
*
* @throws WTFSocketProtocolBrokenException 消息格式错误
* @throws WTFSocketProtocolUnsupportedException 没有适合的解析器
*/ | public WTFSocketMsg parse(String data) throws WTFSocketProtocolBrokenException, WTFSocketProtocolUnsupportedException { |
DeanLee77/Nadia | src/nodePackage/ComparisonLine.java | // Path: src/ruleParser/Tokens.java
// public class Tokens
// {
// public List<String> tokensList;
// public List<String> tokensStringList;
// public String tokensString;
//
// public Tokens(List<String> tl, List<String> tsl, String ts) {
// tokensList = tl;
// tokensStringList = tsl;
// tokensString = ts;
// }
//
// }
| import java.time.LocalDate;
import java.util.HashMap;
import javax.script.ScriptEngine;
import javax.script.ScriptException;
import factValuePackage.*;
import ruleParser.Tokens; | package nodePackage;
public class ComparisonLine extends Node{
private String operator;
private String lhs;
private FactValue rhs;
| // Path: src/ruleParser/Tokens.java
// public class Tokens
// {
// public List<String> tokensList;
// public List<String> tokensStringList;
// public String tokensString;
//
// public Tokens(List<String> tl, List<String> tsl, String ts) {
// tokensList = tl;
// tokensStringList = tsl;
// tokensString = ts;
// }
//
// }
// Path: src/nodePackage/ComparisonLine.java
import java.time.LocalDate;
import java.util.HashMap;
import javax.script.ScriptEngine;
import javax.script.ScriptException;
import factValuePackage.*;
import ruleParser.Tokens;
package nodePackage;
public class ComparisonLine extends Node{
private String operator;
private String lhs;
private FactValue rhs;
| public ComparisonLine(String childText, Tokens tokens) |
DeanLee77/Nadia | src/testingPackage/testing1/TokenizerTesting_1.java | // Path: src/ruleParser/Tokenizer.java
// public class Tokenizer {
//
// public static Tokens getTokens(String text)
// {
//
// List<String> tokenStringList = new ArrayList<>();
// List<String> tokenList = new ArrayList<>();
// String tokenString="";
//
// Pattern spaceMatch = Pattern.compile("^\\s+");
// Pattern iteratePattern = Pattern.compile("^(ITERATE:([\\s]*)LIST OF)(.)");
// Pattern upperMatch = Pattern.compile("^([:'’,\\.\\p{Upper}_\\s]+(?!\\p{Lower}))");
// Pattern lowerMatch = Pattern.compile("^([\\p{Lower}-'’,\\.\\s]+(?!\\d))");
// Pattern mixedMatch = Pattern.compile("^(\\p{Upper}[\\p{Lower}-'’,\\.\\s]+)+");
// Pattern operatorPattern = Pattern.compile("^([<>=]+)");
// Pattern calculationPattern = Pattern.compile("^(\\()([\\s|([\\d]+)(?!/.)|\\w|\\W]*)(\\))");
// Pattern numberPattern = Pattern.compile("^(\\d+)(?!/|\\.|\\d)+");
// Pattern decimalNumberPattern = Pattern.compile("^([\\d]+\\.\\d+)(?!\\d)");
// Pattern datePattern = Pattern.compile("^([0-2]?[0-9]|3[0-1])/(0?[0-9]|1[0-2])/([0-9][0-9])?[0-9][0-9]|^([0-9][0-9])?[0-9][0-9]/(0?[0-9]|1[0-2])/([0-2]?[0-9]|3[0-1])");
// Pattern urlPattern = Pattern.compile( "^(ht|f)tps?\\:(\\p{Graph}|\\p{XDigit}|\\p{Space})*$");
// Pattern uuidPattern = Pattern.compile("^[0-9a-f]{8}-([0-9a-f]{4}-){3}[0-9a-f]{12}");
// Pattern hashPattern = Pattern.compile("^([-]?)([0-9a-f]{10,}$)(?!\\-)*");
// Pattern quotedPattern = Pattern.compile("^([\"\\“])(.*)([\"\\”])(\\.)*");
// /*
// * the order of Pattern in the array of 'matchPatterns' is extremely important because some patterns won't work if other patterns are invoked earlier than them
// * especially 'I' pattern. 'I' pattern must come before 'U' pattern, 'Url' pattern must come before 'L' pattern with current patterns.
// */
// Pattern matchPatterns[] = {spaceMatch, quotedPattern, iteratePattern, mixedMatch, upperMatch, urlPattern, operatorPattern, calculationPattern, hashPattern, numberPattern, decimalNumberPattern, datePattern, uuidPattern, lowerMatch};
// String tokenType[] = {"S", "Q", "I", "M", "U", "Url", "O", "C", "Ha", "No", "De", "Da", "Id", "L"};
// int textLength = text.length();
//
// while(textLength!=0) {
//
// for(int i = 0; i < matchPatterns.length; i++) {
//
// Pattern p = matchPatterns[i];
// Matcher matcher = p.matcher(text);
//
// if(matcher.find() == true)
// {
// String group = matcher.group();
//
// // ignore space tokens
// if(!tokenType[i].equals("S"))
// {
// tokenStringList.add(tokenType[i]);
// tokenList.add(group.trim());
// tokenString += tokenType[i];
// }
//
// text = text.substring(matcher.end()).trim();
// textLength = text.length();
// break;
// }
// if(i >= matchPatterns.length-1)
// {
// textLength =0;
// tokenString = "WARNING";
// }
// }
//
// }
//
// Tokens tokens = new Tokens(tokenList, tokenStringList, tokenString);
//
// return tokens;
//
// }
//
//
// }
//
// Path: src/ruleParser/Tokens.java
// public class Tokens
// {
// public List<String> tokensList;
// public List<String> tokensStringList;
// public String tokensString;
//
// public Tokens(List<String> tl, List<String> tsl, String ts) {
// tokensList = tl;
// tokensStringList = tsl;
// tokensString = ts;
// }
//
// }
| import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import ruleParser.Tokenizer;
import ruleParser.Tokens; | package testingPackage.testing1;
public class TokenizerTesting_1 {
public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub
String fileName = "Tokenizer_Testing.txt";
BufferedReader br = new BufferedReader(new InputStreamReader(TokenizerTesting_1.class.getResourceAsStream(fileName)));
String line;
String textString = "";
int lineTracking = 0; | // Path: src/ruleParser/Tokenizer.java
// public class Tokenizer {
//
// public static Tokens getTokens(String text)
// {
//
// List<String> tokenStringList = new ArrayList<>();
// List<String> tokenList = new ArrayList<>();
// String tokenString="";
//
// Pattern spaceMatch = Pattern.compile("^\\s+");
// Pattern iteratePattern = Pattern.compile("^(ITERATE:([\\s]*)LIST OF)(.)");
// Pattern upperMatch = Pattern.compile("^([:'’,\\.\\p{Upper}_\\s]+(?!\\p{Lower}))");
// Pattern lowerMatch = Pattern.compile("^([\\p{Lower}-'’,\\.\\s]+(?!\\d))");
// Pattern mixedMatch = Pattern.compile("^(\\p{Upper}[\\p{Lower}-'’,\\.\\s]+)+");
// Pattern operatorPattern = Pattern.compile("^([<>=]+)");
// Pattern calculationPattern = Pattern.compile("^(\\()([\\s|([\\d]+)(?!/.)|\\w|\\W]*)(\\))");
// Pattern numberPattern = Pattern.compile("^(\\d+)(?!/|\\.|\\d)+");
// Pattern decimalNumberPattern = Pattern.compile("^([\\d]+\\.\\d+)(?!\\d)");
// Pattern datePattern = Pattern.compile("^([0-2]?[0-9]|3[0-1])/(0?[0-9]|1[0-2])/([0-9][0-9])?[0-9][0-9]|^([0-9][0-9])?[0-9][0-9]/(0?[0-9]|1[0-2])/([0-2]?[0-9]|3[0-1])");
// Pattern urlPattern = Pattern.compile( "^(ht|f)tps?\\:(\\p{Graph}|\\p{XDigit}|\\p{Space})*$");
// Pattern uuidPattern = Pattern.compile("^[0-9a-f]{8}-([0-9a-f]{4}-){3}[0-9a-f]{12}");
// Pattern hashPattern = Pattern.compile("^([-]?)([0-9a-f]{10,}$)(?!\\-)*");
// Pattern quotedPattern = Pattern.compile("^([\"\\“])(.*)([\"\\”])(\\.)*");
// /*
// * the order of Pattern in the array of 'matchPatterns' is extremely important because some patterns won't work if other patterns are invoked earlier than them
// * especially 'I' pattern. 'I' pattern must come before 'U' pattern, 'Url' pattern must come before 'L' pattern with current patterns.
// */
// Pattern matchPatterns[] = {spaceMatch, quotedPattern, iteratePattern, mixedMatch, upperMatch, urlPattern, operatorPattern, calculationPattern, hashPattern, numberPattern, decimalNumberPattern, datePattern, uuidPattern, lowerMatch};
// String tokenType[] = {"S", "Q", "I", "M", "U", "Url", "O", "C", "Ha", "No", "De", "Da", "Id", "L"};
// int textLength = text.length();
//
// while(textLength!=0) {
//
// for(int i = 0; i < matchPatterns.length; i++) {
//
// Pattern p = matchPatterns[i];
// Matcher matcher = p.matcher(text);
//
// if(matcher.find() == true)
// {
// String group = matcher.group();
//
// // ignore space tokens
// if(!tokenType[i].equals("S"))
// {
// tokenStringList.add(tokenType[i]);
// tokenList.add(group.trim());
// tokenString += tokenType[i];
// }
//
// text = text.substring(matcher.end()).trim();
// textLength = text.length();
// break;
// }
// if(i >= matchPatterns.length-1)
// {
// textLength =0;
// tokenString = "WARNING";
// }
// }
//
// }
//
// Tokens tokens = new Tokens(tokenList, tokenStringList, tokenString);
//
// return tokens;
//
// }
//
//
// }
//
// Path: src/ruleParser/Tokens.java
// public class Tokens
// {
// public List<String> tokensList;
// public List<String> tokensStringList;
// public String tokensString;
//
// public Tokens(List<String> tl, List<String> tsl, String ts) {
// tokensList = tl;
// tokensStringList = tsl;
// tokensString = ts;
// }
//
// }
// Path: src/testingPackage/testing1/TokenizerTesting_1.java
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import ruleParser.Tokenizer;
import ruleParser.Tokens;
package testingPackage.testing1;
public class TokenizerTesting_1 {
public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub
String fileName = "Tokenizer_Testing.txt";
BufferedReader br = new BufferedReader(new InputStreamReader(TokenizerTesting_1.class.getResourceAsStream(fileName)));
String line;
String textString = "";
int lineTracking = 0; | Tokens tk = null; |
DeanLee77/Nadia | src/testingPackage/testing1/TokenizerTesting_1.java | // Path: src/ruleParser/Tokenizer.java
// public class Tokenizer {
//
// public static Tokens getTokens(String text)
// {
//
// List<String> tokenStringList = new ArrayList<>();
// List<String> tokenList = new ArrayList<>();
// String tokenString="";
//
// Pattern spaceMatch = Pattern.compile("^\\s+");
// Pattern iteratePattern = Pattern.compile("^(ITERATE:([\\s]*)LIST OF)(.)");
// Pattern upperMatch = Pattern.compile("^([:'’,\\.\\p{Upper}_\\s]+(?!\\p{Lower}))");
// Pattern lowerMatch = Pattern.compile("^([\\p{Lower}-'’,\\.\\s]+(?!\\d))");
// Pattern mixedMatch = Pattern.compile("^(\\p{Upper}[\\p{Lower}-'’,\\.\\s]+)+");
// Pattern operatorPattern = Pattern.compile("^([<>=]+)");
// Pattern calculationPattern = Pattern.compile("^(\\()([\\s|([\\d]+)(?!/.)|\\w|\\W]*)(\\))");
// Pattern numberPattern = Pattern.compile("^(\\d+)(?!/|\\.|\\d)+");
// Pattern decimalNumberPattern = Pattern.compile("^([\\d]+\\.\\d+)(?!\\d)");
// Pattern datePattern = Pattern.compile("^([0-2]?[0-9]|3[0-1])/(0?[0-9]|1[0-2])/([0-9][0-9])?[0-9][0-9]|^([0-9][0-9])?[0-9][0-9]/(0?[0-9]|1[0-2])/([0-2]?[0-9]|3[0-1])");
// Pattern urlPattern = Pattern.compile( "^(ht|f)tps?\\:(\\p{Graph}|\\p{XDigit}|\\p{Space})*$");
// Pattern uuidPattern = Pattern.compile("^[0-9a-f]{8}-([0-9a-f]{4}-){3}[0-9a-f]{12}");
// Pattern hashPattern = Pattern.compile("^([-]?)([0-9a-f]{10,}$)(?!\\-)*");
// Pattern quotedPattern = Pattern.compile("^([\"\\“])(.*)([\"\\”])(\\.)*");
// /*
// * the order of Pattern in the array of 'matchPatterns' is extremely important because some patterns won't work if other patterns are invoked earlier than them
// * especially 'I' pattern. 'I' pattern must come before 'U' pattern, 'Url' pattern must come before 'L' pattern with current patterns.
// */
// Pattern matchPatterns[] = {spaceMatch, quotedPattern, iteratePattern, mixedMatch, upperMatch, urlPattern, operatorPattern, calculationPattern, hashPattern, numberPattern, decimalNumberPattern, datePattern, uuidPattern, lowerMatch};
// String tokenType[] = {"S", "Q", "I", "M", "U", "Url", "O", "C", "Ha", "No", "De", "Da", "Id", "L"};
// int textLength = text.length();
//
// while(textLength!=0) {
//
// for(int i = 0; i < matchPatterns.length; i++) {
//
// Pattern p = matchPatterns[i];
// Matcher matcher = p.matcher(text);
//
// if(matcher.find() == true)
// {
// String group = matcher.group();
//
// // ignore space tokens
// if(!tokenType[i].equals("S"))
// {
// tokenStringList.add(tokenType[i]);
// tokenList.add(group.trim());
// tokenString += tokenType[i];
// }
//
// text = text.substring(matcher.end()).trim();
// textLength = text.length();
// break;
// }
// if(i >= matchPatterns.length-1)
// {
// textLength =0;
// tokenString = "WARNING";
// }
// }
//
// }
//
// Tokens tokens = new Tokens(tokenList, tokenStringList, tokenString);
//
// return tokens;
//
// }
//
//
// }
//
// Path: src/ruleParser/Tokens.java
// public class Tokens
// {
// public List<String> tokensList;
// public List<String> tokensStringList;
// public String tokensString;
//
// public Tokens(List<String> tl, List<String> tsl, String ts) {
// tokensList = tl;
// tokensStringList = tsl;
// tokensString = ts;
// }
//
// }
| import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import ruleParser.Tokenizer;
import ruleParser.Tokens; | package testingPackage.testing1;
public class TokenizerTesting_1 {
public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub
String fileName = "Tokenizer_Testing.txt";
BufferedReader br = new BufferedReader(new InputStreamReader(TokenizerTesting_1.class.getResourceAsStream(fileName)));
String line;
String textString = "";
int lineTracking = 0;
Tokens tk = null;
while ((line = br.readLine()) != null)
{
line = line.trim();
if(!line.equals("") && !line.matches("^\\/.*"))
{
if(lineTracking == 0)
{
textString = line; | // Path: src/ruleParser/Tokenizer.java
// public class Tokenizer {
//
// public static Tokens getTokens(String text)
// {
//
// List<String> tokenStringList = new ArrayList<>();
// List<String> tokenList = new ArrayList<>();
// String tokenString="";
//
// Pattern spaceMatch = Pattern.compile("^\\s+");
// Pattern iteratePattern = Pattern.compile("^(ITERATE:([\\s]*)LIST OF)(.)");
// Pattern upperMatch = Pattern.compile("^([:'’,\\.\\p{Upper}_\\s]+(?!\\p{Lower}))");
// Pattern lowerMatch = Pattern.compile("^([\\p{Lower}-'’,\\.\\s]+(?!\\d))");
// Pattern mixedMatch = Pattern.compile("^(\\p{Upper}[\\p{Lower}-'’,\\.\\s]+)+");
// Pattern operatorPattern = Pattern.compile("^([<>=]+)");
// Pattern calculationPattern = Pattern.compile("^(\\()([\\s|([\\d]+)(?!/.)|\\w|\\W]*)(\\))");
// Pattern numberPattern = Pattern.compile("^(\\d+)(?!/|\\.|\\d)+");
// Pattern decimalNumberPattern = Pattern.compile("^([\\d]+\\.\\d+)(?!\\d)");
// Pattern datePattern = Pattern.compile("^([0-2]?[0-9]|3[0-1])/(0?[0-9]|1[0-2])/([0-9][0-9])?[0-9][0-9]|^([0-9][0-9])?[0-9][0-9]/(0?[0-9]|1[0-2])/([0-2]?[0-9]|3[0-1])");
// Pattern urlPattern = Pattern.compile( "^(ht|f)tps?\\:(\\p{Graph}|\\p{XDigit}|\\p{Space})*$");
// Pattern uuidPattern = Pattern.compile("^[0-9a-f]{8}-([0-9a-f]{4}-){3}[0-9a-f]{12}");
// Pattern hashPattern = Pattern.compile("^([-]?)([0-9a-f]{10,}$)(?!\\-)*");
// Pattern quotedPattern = Pattern.compile("^([\"\\“])(.*)([\"\\”])(\\.)*");
// /*
// * the order of Pattern in the array of 'matchPatterns' is extremely important because some patterns won't work if other patterns are invoked earlier than them
// * especially 'I' pattern. 'I' pattern must come before 'U' pattern, 'Url' pattern must come before 'L' pattern with current patterns.
// */
// Pattern matchPatterns[] = {spaceMatch, quotedPattern, iteratePattern, mixedMatch, upperMatch, urlPattern, operatorPattern, calculationPattern, hashPattern, numberPattern, decimalNumberPattern, datePattern, uuidPattern, lowerMatch};
// String tokenType[] = {"S", "Q", "I", "M", "U", "Url", "O", "C", "Ha", "No", "De", "Da", "Id", "L"};
// int textLength = text.length();
//
// while(textLength!=0) {
//
// for(int i = 0; i < matchPatterns.length; i++) {
//
// Pattern p = matchPatterns[i];
// Matcher matcher = p.matcher(text);
//
// if(matcher.find() == true)
// {
// String group = matcher.group();
//
// // ignore space tokens
// if(!tokenType[i].equals("S"))
// {
// tokenStringList.add(tokenType[i]);
// tokenList.add(group.trim());
// tokenString += tokenType[i];
// }
//
// text = text.substring(matcher.end()).trim();
// textLength = text.length();
// break;
// }
// if(i >= matchPatterns.length-1)
// {
// textLength =0;
// tokenString = "WARNING";
// }
// }
//
// }
//
// Tokens tokens = new Tokens(tokenList, tokenStringList, tokenString);
//
// return tokens;
//
// }
//
//
// }
//
// Path: src/ruleParser/Tokens.java
// public class Tokens
// {
// public List<String> tokensList;
// public List<String> tokensStringList;
// public String tokensString;
//
// public Tokens(List<String> tl, List<String> tsl, String ts) {
// tokensList = tl;
// tokensStringList = tsl;
// tokensString = ts;
// }
//
// }
// Path: src/testingPackage/testing1/TokenizerTesting_1.java
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import ruleParser.Tokenizer;
import ruleParser.Tokens;
package testingPackage.testing1;
public class TokenizerTesting_1 {
public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub
String fileName = "Tokenizer_Testing.txt";
BufferedReader br = new BufferedReader(new InputStreamReader(TokenizerTesting_1.class.getResourceAsStream(fileName)));
String line;
String textString = "";
int lineTracking = 0;
Tokens tk = null;
while ((line = br.readLine()) != null)
{
line = line.trim();
if(!line.equals("") && !line.matches("^\\/.*"))
{
if(lineTracking == 0)
{
textString = line; | tk = Tokenizer.getTokens(line); |
DeanLee77/Nadia | src/inferencePackage/AssessmentState.java | // Path: src/factValuePackage/FactListValue.java
// public class FactListValue<T> extends FactValue{
//
// private List<FactValue> listValue;
// private FactValue defaultValue;
//
// public FactListValue(List<FactValue> i) {
// setListValue(i);
// }
//
// public void setListValue(List<FactValue> listValue) {
// this.listValue = listValue;
// }
//
// public void addFactValueToListValue(FactValue fv)
// {
// this.listValue.add(fv);
// }
//
//
// @Override
// public FactValueType getType() {
// return FactValueType.LIST;
// }
//
//
// @SuppressWarnings("hiding")
// @Override
// public <T> void setDefaultValue(T defaultValue) {
//
// this.defaultValue = (FactValue)defaultValue;
//
// }
//
// @SuppressWarnings("unchecked")
// @Override
// public List<FactValue> getValue() {
//
// return listValue;
// }
//
// @SuppressWarnings("unchecked")
// @Override
// public FactValue getDefaultValue() {
//
// return defaultValue;
// }
//
// //
// // public boolean compare(FactValue factValue2) {
// // boolean equal = false;
// // FactValueType factValue2Type = factValue2.getType();
// // if(factValue2Type.equals(FactValueType.LIST))
// // {
// // int factValue2ListSize = ((FactListValue)factValue2).getListValue().size();
// // int trueCount = 0;
// // for(int i = 0; i < factValue2ListSize; i++)
// // {
// // if(this.listValue.get(i).getType().equals(((FactValue) ((FactListValue)factValue2).getListValue().get(i)).getType())
// // &&this.listValue.get(i).equals(factValue2))
// // {
// // trueCount++;
// // }
// // }
// // if(factValue2ListSize == this.listValue.size() && trueCount == factValue2ListSize)
// // {
// // equal = true;
// // }
// //
// // }
// // else
// // {
// // System.out.println("FactListValue comparison is failed");
// // }
// //
// // return equal;
// // }
//
//
//
//
//
// }
//
// Path: src/factValuePackage/FactValue.java
// public abstract class FactValue {
//
//
// public static FactDefiStringValue parseDefiString(String s) {
// return new FactDefiStringValue(s);
// }
//
// public static FactStringValue parse(String s) {
// return new FactStringValue(s);
// }
//
// public static FactIntegerValue parse(int i) {
// return new FactIntegerValue(i);
// }
//
// public static FactDateValue parse(LocalDate cal) {
// return new FactDateValue(cal);
// }
//
// public static FactDoubleValue parse(double d) {
// return new FactDoubleValue(d);
// }
//
// @SuppressWarnings("rawtypes")
// public static FactBooleanValue<?> parse(boolean b)
// {
// return new FactBooleanValue(b);
// }
//
// @SuppressWarnings({ "unchecked", "rawtypes" })
// public static FactListValue<?> parse(List<FactValue> l)
// {
// return new FactListValue(l);
// }
//
// public static FactURLValue parseURL(String url)
// {
// return new FactURLValue(url);
// }
//
// public static FactHashValue parseHash(String hash)
// {
// return new FactHashValue(hash);
// }
//
// public static FactUUIDValue parseUUID(String uuid)
// {
// return new FactUUIDValue(uuid);
// }
//
//
// public abstract FactValueType getType() ;
// public abstract <T> void setDefaultValue(T str);
// public abstract <T> T getValue();
// public abstract <T> T getDefaultValue();
//
// }
//
// Path: src/factValuePackage/FactValueType.java
// public enum FactValueType {
// DEFI_STRING, TEXT, STRING, INTEGER, DOUBLE, NUMBER, DATE, DECIMAL, BOOLEAN, LIST, RULE, RULE_SET, OBJECT, UNKNOWN, URL, HASH, UUID, NULL;
//
// }
| import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import factValuePackage.FactListValue;
import factValuePackage.FactValue;
import factValuePackage.FactValueType;
import nodePackage.*; | {
this.mandatoryList = mandatoryList;
}
public void addItemToMandatoryList(String nodeName)
{
if(!this.mandatoryList.contains(nodeName))
{
this.mandatoryList.add(nodeName);
}
}
public boolean isInMandatoryList(String nodeName)
{
return this.mandatoryList.contains(nodeName);
}
public boolean allMandatoryNodeDetermined()
{
return this.mandatoryList.parallelStream().allMatch(nodeName -> this.workingMemory.containsKey(nodeName));
}
/*
* this method is to set a rule as a fact in the workingMemory
* before this method is called, nodeName should be given and look up nodeMap in NodeSet to find variableName of the node
* then the variableName of the node should be passed to this method.
*/
public void setFact(String nodeVariableName, FactValue value)
{
if(workingMemory.containsKey(nodeVariableName))
{
FactValue tempFv = workingMemory.get(nodeVariableName);
| // Path: src/factValuePackage/FactListValue.java
// public class FactListValue<T> extends FactValue{
//
// private List<FactValue> listValue;
// private FactValue defaultValue;
//
// public FactListValue(List<FactValue> i) {
// setListValue(i);
// }
//
// public void setListValue(List<FactValue> listValue) {
// this.listValue = listValue;
// }
//
// public void addFactValueToListValue(FactValue fv)
// {
// this.listValue.add(fv);
// }
//
//
// @Override
// public FactValueType getType() {
// return FactValueType.LIST;
// }
//
//
// @SuppressWarnings("hiding")
// @Override
// public <T> void setDefaultValue(T defaultValue) {
//
// this.defaultValue = (FactValue)defaultValue;
//
// }
//
// @SuppressWarnings("unchecked")
// @Override
// public List<FactValue> getValue() {
//
// return listValue;
// }
//
// @SuppressWarnings("unchecked")
// @Override
// public FactValue getDefaultValue() {
//
// return defaultValue;
// }
//
// //
// // public boolean compare(FactValue factValue2) {
// // boolean equal = false;
// // FactValueType factValue2Type = factValue2.getType();
// // if(factValue2Type.equals(FactValueType.LIST))
// // {
// // int factValue2ListSize = ((FactListValue)factValue2).getListValue().size();
// // int trueCount = 0;
// // for(int i = 0; i < factValue2ListSize; i++)
// // {
// // if(this.listValue.get(i).getType().equals(((FactValue) ((FactListValue)factValue2).getListValue().get(i)).getType())
// // &&this.listValue.get(i).equals(factValue2))
// // {
// // trueCount++;
// // }
// // }
// // if(factValue2ListSize == this.listValue.size() && trueCount == factValue2ListSize)
// // {
// // equal = true;
// // }
// //
// // }
// // else
// // {
// // System.out.println("FactListValue comparison is failed");
// // }
// //
// // return equal;
// // }
//
//
//
//
//
// }
//
// Path: src/factValuePackage/FactValue.java
// public abstract class FactValue {
//
//
// public static FactDefiStringValue parseDefiString(String s) {
// return new FactDefiStringValue(s);
// }
//
// public static FactStringValue parse(String s) {
// return new FactStringValue(s);
// }
//
// public static FactIntegerValue parse(int i) {
// return new FactIntegerValue(i);
// }
//
// public static FactDateValue parse(LocalDate cal) {
// return new FactDateValue(cal);
// }
//
// public static FactDoubleValue parse(double d) {
// return new FactDoubleValue(d);
// }
//
// @SuppressWarnings("rawtypes")
// public static FactBooleanValue<?> parse(boolean b)
// {
// return new FactBooleanValue(b);
// }
//
// @SuppressWarnings({ "unchecked", "rawtypes" })
// public static FactListValue<?> parse(List<FactValue> l)
// {
// return new FactListValue(l);
// }
//
// public static FactURLValue parseURL(String url)
// {
// return new FactURLValue(url);
// }
//
// public static FactHashValue parseHash(String hash)
// {
// return new FactHashValue(hash);
// }
//
// public static FactUUIDValue parseUUID(String uuid)
// {
// return new FactUUIDValue(uuid);
// }
//
//
// public abstract FactValueType getType() ;
// public abstract <T> void setDefaultValue(T str);
// public abstract <T> T getValue();
// public abstract <T> T getDefaultValue();
//
// }
//
// Path: src/factValuePackage/FactValueType.java
// public enum FactValueType {
// DEFI_STRING, TEXT, STRING, INTEGER, DOUBLE, NUMBER, DATE, DECIMAL, BOOLEAN, LIST, RULE, RULE_SET, OBJECT, UNKNOWN, URL, HASH, UUID, NULL;
//
// }
// Path: src/inferencePackage/AssessmentState.java
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import factValuePackage.FactListValue;
import factValuePackage.FactValue;
import factValuePackage.FactValueType;
import nodePackage.*;
{
this.mandatoryList = mandatoryList;
}
public void addItemToMandatoryList(String nodeName)
{
if(!this.mandatoryList.contains(nodeName))
{
this.mandatoryList.add(nodeName);
}
}
public boolean isInMandatoryList(String nodeName)
{
return this.mandatoryList.contains(nodeName);
}
public boolean allMandatoryNodeDetermined()
{
return this.mandatoryList.parallelStream().allMatch(nodeName -> this.workingMemory.containsKey(nodeName));
}
/*
* this method is to set a rule as a fact in the workingMemory
* before this method is called, nodeName should be given and look up nodeMap in NodeSet to find variableName of the node
* then the variableName of the node should be passed to this method.
*/
public void setFact(String nodeVariableName, FactValue value)
{
if(workingMemory.containsKey(nodeVariableName))
{
FactValue tempFv = workingMemory.get(nodeVariableName);
| if(tempFv.getType().equals(FactValueType.LIST)) |
DeanLee77/Nadia | src/inferencePackage/AssessmentState.java | // Path: src/factValuePackage/FactListValue.java
// public class FactListValue<T> extends FactValue{
//
// private List<FactValue> listValue;
// private FactValue defaultValue;
//
// public FactListValue(List<FactValue> i) {
// setListValue(i);
// }
//
// public void setListValue(List<FactValue> listValue) {
// this.listValue = listValue;
// }
//
// public void addFactValueToListValue(FactValue fv)
// {
// this.listValue.add(fv);
// }
//
//
// @Override
// public FactValueType getType() {
// return FactValueType.LIST;
// }
//
//
// @SuppressWarnings("hiding")
// @Override
// public <T> void setDefaultValue(T defaultValue) {
//
// this.defaultValue = (FactValue)defaultValue;
//
// }
//
// @SuppressWarnings("unchecked")
// @Override
// public List<FactValue> getValue() {
//
// return listValue;
// }
//
// @SuppressWarnings("unchecked")
// @Override
// public FactValue getDefaultValue() {
//
// return defaultValue;
// }
//
// //
// // public boolean compare(FactValue factValue2) {
// // boolean equal = false;
// // FactValueType factValue2Type = factValue2.getType();
// // if(factValue2Type.equals(FactValueType.LIST))
// // {
// // int factValue2ListSize = ((FactListValue)factValue2).getListValue().size();
// // int trueCount = 0;
// // for(int i = 0; i < factValue2ListSize; i++)
// // {
// // if(this.listValue.get(i).getType().equals(((FactValue) ((FactListValue)factValue2).getListValue().get(i)).getType())
// // &&this.listValue.get(i).equals(factValue2))
// // {
// // trueCount++;
// // }
// // }
// // if(factValue2ListSize == this.listValue.size() && trueCount == factValue2ListSize)
// // {
// // equal = true;
// // }
// //
// // }
// // else
// // {
// // System.out.println("FactListValue comparison is failed");
// // }
// //
// // return equal;
// // }
//
//
//
//
//
// }
//
// Path: src/factValuePackage/FactValue.java
// public abstract class FactValue {
//
//
// public static FactDefiStringValue parseDefiString(String s) {
// return new FactDefiStringValue(s);
// }
//
// public static FactStringValue parse(String s) {
// return new FactStringValue(s);
// }
//
// public static FactIntegerValue parse(int i) {
// return new FactIntegerValue(i);
// }
//
// public static FactDateValue parse(LocalDate cal) {
// return new FactDateValue(cal);
// }
//
// public static FactDoubleValue parse(double d) {
// return new FactDoubleValue(d);
// }
//
// @SuppressWarnings("rawtypes")
// public static FactBooleanValue<?> parse(boolean b)
// {
// return new FactBooleanValue(b);
// }
//
// @SuppressWarnings({ "unchecked", "rawtypes" })
// public static FactListValue<?> parse(List<FactValue> l)
// {
// return new FactListValue(l);
// }
//
// public static FactURLValue parseURL(String url)
// {
// return new FactURLValue(url);
// }
//
// public static FactHashValue parseHash(String hash)
// {
// return new FactHashValue(hash);
// }
//
// public static FactUUIDValue parseUUID(String uuid)
// {
// return new FactUUIDValue(uuid);
// }
//
//
// public abstract FactValueType getType() ;
// public abstract <T> void setDefaultValue(T str);
// public abstract <T> T getValue();
// public abstract <T> T getDefaultValue();
//
// }
//
// Path: src/factValuePackage/FactValueType.java
// public enum FactValueType {
// DEFI_STRING, TEXT, STRING, INTEGER, DOUBLE, NUMBER, DATE, DECIMAL, BOOLEAN, LIST, RULE, RULE_SET, OBJECT, UNKNOWN, URL, HASH, UUID, NULL;
//
// }
| import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import factValuePackage.FactListValue;
import factValuePackage.FactValue;
import factValuePackage.FactValueType;
import nodePackage.*; | }
public void addItemToMandatoryList(String nodeName)
{
if(!this.mandatoryList.contains(nodeName))
{
this.mandatoryList.add(nodeName);
}
}
public boolean isInMandatoryList(String nodeName)
{
return this.mandatoryList.contains(nodeName);
}
public boolean allMandatoryNodeDetermined()
{
return this.mandatoryList.parallelStream().allMatch(nodeName -> this.workingMemory.containsKey(nodeName));
}
/*
* this method is to set a rule as a fact in the workingMemory
* before this method is called, nodeName should be given and look up nodeMap in NodeSet to find variableName of the node
* then the variableName of the node should be passed to this method.
*/
public void setFact(String nodeVariableName, FactValue value)
{
if(workingMemory.containsKey(nodeVariableName))
{
FactValue tempFv = workingMemory.get(nodeVariableName);
if(tempFv.getType().equals(FactValueType.LIST))
{ | // Path: src/factValuePackage/FactListValue.java
// public class FactListValue<T> extends FactValue{
//
// private List<FactValue> listValue;
// private FactValue defaultValue;
//
// public FactListValue(List<FactValue> i) {
// setListValue(i);
// }
//
// public void setListValue(List<FactValue> listValue) {
// this.listValue = listValue;
// }
//
// public void addFactValueToListValue(FactValue fv)
// {
// this.listValue.add(fv);
// }
//
//
// @Override
// public FactValueType getType() {
// return FactValueType.LIST;
// }
//
//
// @SuppressWarnings("hiding")
// @Override
// public <T> void setDefaultValue(T defaultValue) {
//
// this.defaultValue = (FactValue)defaultValue;
//
// }
//
// @SuppressWarnings("unchecked")
// @Override
// public List<FactValue> getValue() {
//
// return listValue;
// }
//
// @SuppressWarnings("unchecked")
// @Override
// public FactValue getDefaultValue() {
//
// return defaultValue;
// }
//
// //
// // public boolean compare(FactValue factValue2) {
// // boolean equal = false;
// // FactValueType factValue2Type = factValue2.getType();
// // if(factValue2Type.equals(FactValueType.LIST))
// // {
// // int factValue2ListSize = ((FactListValue)factValue2).getListValue().size();
// // int trueCount = 0;
// // for(int i = 0; i < factValue2ListSize; i++)
// // {
// // if(this.listValue.get(i).getType().equals(((FactValue) ((FactListValue)factValue2).getListValue().get(i)).getType())
// // &&this.listValue.get(i).equals(factValue2))
// // {
// // trueCount++;
// // }
// // }
// // if(factValue2ListSize == this.listValue.size() && trueCount == factValue2ListSize)
// // {
// // equal = true;
// // }
// //
// // }
// // else
// // {
// // System.out.println("FactListValue comparison is failed");
// // }
// //
// // return equal;
// // }
//
//
//
//
//
// }
//
// Path: src/factValuePackage/FactValue.java
// public abstract class FactValue {
//
//
// public static FactDefiStringValue parseDefiString(String s) {
// return new FactDefiStringValue(s);
// }
//
// public static FactStringValue parse(String s) {
// return new FactStringValue(s);
// }
//
// public static FactIntegerValue parse(int i) {
// return new FactIntegerValue(i);
// }
//
// public static FactDateValue parse(LocalDate cal) {
// return new FactDateValue(cal);
// }
//
// public static FactDoubleValue parse(double d) {
// return new FactDoubleValue(d);
// }
//
// @SuppressWarnings("rawtypes")
// public static FactBooleanValue<?> parse(boolean b)
// {
// return new FactBooleanValue(b);
// }
//
// @SuppressWarnings({ "unchecked", "rawtypes" })
// public static FactListValue<?> parse(List<FactValue> l)
// {
// return new FactListValue(l);
// }
//
// public static FactURLValue parseURL(String url)
// {
// return new FactURLValue(url);
// }
//
// public static FactHashValue parseHash(String hash)
// {
// return new FactHashValue(hash);
// }
//
// public static FactUUIDValue parseUUID(String uuid)
// {
// return new FactUUIDValue(uuid);
// }
//
//
// public abstract FactValueType getType() ;
// public abstract <T> void setDefaultValue(T str);
// public abstract <T> T getValue();
// public abstract <T> T getDefaultValue();
//
// }
//
// Path: src/factValuePackage/FactValueType.java
// public enum FactValueType {
// DEFI_STRING, TEXT, STRING, INTEGER, DOUBLE, NUMBER, DATE, DECIMAL, BOOLEAN, LIST, RULE, RULE_SET, OBJECT, UNKNOWN, URL, HASH, UUID, NULL;
//
// }
// Path: src/inferencePackage/AssessmentState.java
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import factValuePackage.FactListValue;
import factValuePackage.FactValue;
import factValuePackage.FactValueType;
import nodePackage.*;
}
public void addItemToMandatoryList(String nodeName)
{
if(!this.mandatoryList.contains(nodeName))
{
this.mandatoryList.add(nodeName);
}
}
public boolean isInMandatoryList(String nodeName)
{
return this.mandatoryList.contains(nodeName);
}
public boolean allMandatoryNodeDetermined()
{
return this.mandatoryList.parallelStream().allMatch(nodeName -> this.workingMemory.containsKey(nodeName));
}
/*
* this method is to set a rule as a fact in the workingMemory
* before this method is called, nodeName should be given and look up nodeMap in NodeSet to find variableName of the node
* then the variableName of the node should be passed to this method.
*/
public void setFact(String nodeVariableName, FactValue value)
{
if(workingMemory.containsKey(nodeVariableName))
{
FactValue tempFv = workingMemory.get(nodeVariableName);
if(tempFv.getType().equals(FactValueType.LIST))
{ | ((FactListValue<?>)tempFv).getValue().add(tempFv); |
DeanLee77/Nadia | src/ruleParser/IScanFeeder.java | // Path: src/nodePackage/MetaType.java
// public enum MetaType {
// LINE, FIXED, INPUT, ITEM, GOAL, CLICK_LINK, SOP_DOC
//
// }
//
// Path: src/nodePackage/NodeSet.java
// public class NodeSet {
// private String nodeSetName;
// private HashMap<String, Node> nodeMap ;
// private HashMap<Integer, String> nodeIdMap;
// private List<Node> sortedNodeList;
// private HashMap<String, FactValue> inputMap;
// private HashMap<String, FactValue> factMap;
// private Node defaultGoalNode;
// private DependencyMatrix dependencyMatrix;
//
// public NodeSet()
// {
// this.nodeSetName = "";
// this.inputMap = new HashMap<>();
// this.factMap = new HashMap<>();
// this.nodeMap = new HashMap<>();
// this.nodeIdMap = new HashMap<>();
// this.sortedNodeList = new ArrayList<>();
//
// }
//
// public DependencyMatrix getDependencyMatrix()
// {
// return this.dependencyMatrix;
// }
// public void setDependencyMatrix(DependencyMatrix dm)
// {
// this.dependencyMatrix = dm;
// }
// public void setDependencyMatrix(int[][] dependencyMatrix)
// {
// this.dependencyMatrix = new DependencyMatrix(dependencyMatrix);
// }
//
// public String getNodeSetName()
// {
// return this.nodeSetName;
// }
// public void setNodeSetName(String nodeSetName)
// {
// this.nodeSetName = nodeSetName;
// }
//
// public void setNodeIdMap(HashMap<Integer, String> nodeIdMap)
// {
// this.nodeIdMap = nodeIdMap;
// }
// public HashMap<Integer, String> getNodeIdMap()
// {
// return this.nodeIdMap;
// }
// public void setNodeMap(HashMap<String, Node> nodeMap)
// {
// this.nodeMap = nodeMap;
// }
// public HashMap<String, Node> getNodeMap()
// {
// return this.nodeMap;
// }
//
// public void setNodeSortedList(List<Node> sortedNodeList)
// {
// this.sortedNodeList = sortedNodeList;
// }
// public List<Node> getNodeSortedList()
// {
// return this.sortedNodeList;
// }
//
// public HashMap<String, FactValue> getInputMap()
// {
// return this.inputMap;
// }
//
// public void setFactMap(HashMap<String, FactValue> factMap)
// {
// this.factMap = factMap;
// }
// public HashMap<String, FactValue> getFactMap()
// {
// return this.factMap;
// }
//
// public Node getNode(int nodeIndex)
// {
// return sortedNodeList.get(nodeIndex);
// }
//
// public Node getNode(String nodeName)
// {
// return nodeMap.get(nodeName);
// }
//
// public Node getNodeByNodeId(int nodeId)
// {
// return getNode(getNodeIdMap().get(nodeId));
// }
//
// public int findNodeIndex(String nodeName)
// {
// int nodeIndex = IntStream.range(0, getNodeSortedList().size()).filter(i -> getNodeSortedList().get(i).getNodeName().equals(nodeName)).toArray()[0];
//
// return nodeIndex;
// }
//
// public void setDefaultGoalNode(String name)
// {
// this.defaultGoalNode = this.nodeMap.get(name);
// }
// public Node getDefaultGoalNode()
// {
// return this.defaultGoalNode;
// }
// public HashMap<String, FactValue> transferFactMapToWorkingMemory(HashMap<String, FactValue> workingMemory)
// {
// inputMap.forEach((k,v)->workingMemory.put(k, v));
//
// return workingMemory;
// }
//
//
//
// }
| import nodePackage.MetaType;
import nodePackage.NodeSet; | package ruleParser;
public interface IScanFeeder {
public void handleParent(String parentText, int lineNumber);
public void handleChild(String parentText, String childText, String firstKeywordsGroup, int lineNumber);
// public void handleNeedWant(String parentText, String childText, int lineNumber); | // Path: src/nodePackage/MetaType.java
// public enum MetaType {
// LINE, FIXED, INPUT, ITEM, GOAL, CLICK_LINK, SOP_DOC
//
// }
//
// Path: src/nodePackage/NodeSet.java
// public class NodeSet {
// private String nodeSetName;
// private HashMap<String, Node> nodeMap ;
// private HashMap<Integer, String> nodeIdMap;
// private List<Node> sortedNodeList;
// private HashMap<String, FactValue> inputMap;
// private HashMap<String, FactValue> factMap;
// private Node defaultGoalNode;
// private DependencyMatrix dependencyMatrix;
//
// public NodeSet()
// {
// this.nodeSetName = "";
// this.inputMap = new HashMap<>();
// this.factMap = new HashMap<>();
// this.nodeMap = new HashMap<>();
// this.nodeIdMap = new HashMap<>();
// this.sortedNodeList = new ArrayList<>();
//
// }
//
// public DependencyMatrix getDependencyMatrix()
// {
// return this.dependencyMatrix;
// }
// public void setDependencyMatrix(DependencyMatrix dm)
// {
// this.dependencyMatrix = dm;
// }
// public void setDependencyMatrix(int[][] dependencyMatrix)
// {
// this.dependencyMatrix = new DependencyMatrix(dependencyMatrix);
// }
//
// public String getNodeSetName()
// {
// return this.nodeSetName;
// }
// public void setNodeSetName(String nodeSetName)
// {
// this.nodeSetName = nodeSetName;
// }
//
// public void setNodeIdMap(HashMap<Integer, String> nodeIdMap)
// {
// this.nodeIdMap = nodeIdMap;
// }
// public HashMap<Integer, String> getNodeIdMap()
// {
// return this.nodeIdMap;
// }
// public void setNodeMap(HashMap<String, Node> nodeMap)
// {
// this.nodeMap = nodeMap;
// }
// public HashMap<String, Node> getNodeMap()
// {
// return this.nodeMap;
// }
//
// public void setNodeSortedList(List<Node> sortedNodeList)
// {
// this.sortedNodeList = sortedNodeList;
// }
// public List<Node> getNodeSortedList()
// {
// return this.sortedNodeList;
// }
//
// public HashMap<String, FactValue> getInputMap()
// {
// return this.inputMap;
// }
//
// public void setFactMap(HashMap<String, FactValue> factMap)
// {
// this.factMap = factMap;
// }
// public HashMap<String, FactValue> getFactMap()
// {
// return this.factMap;
// }
//
// public Node getNode(int nodeIndex)
// {
// return sortedNodeList.get(nodeIndex);
// }
//
// public Node getNode(String nodeName)
// {
// return nodeMap.get(nodeName);
// }
//
// public Node getNodeByNodeId(int nodeId)
// {
// return getNode(getNodeIdMap().get(nodeId));
// }
//
// public int findNodeIndex(String nodeName)
// {
// int nodeIndex = IntStream.range(0, getNodeSortedList().size()).filter(i -> getNodeSortedList().get(i).getNodeName().equals(nodeName)).toArray()[0];
//
// return nodeIndex;
// }
//
// public void setDefaultGoalNode(String name)
// {
// this.defaultGoalNode = this.nodeMap.get(name);
// }
// public Node getDefaultGoalNode()
// {
// return this.defaultGoalNode;
// }
// public HashMap<String, FactValue> transferFactMapToWorkingMemory(HashMap<String, FactValue> workingMemory)
// {
// inputMap.forEach((k,v)->workingMemory.put(k, v));
//
// return workingMemory;
// }
//
//
//
// }
// Path: src/ruleParser/IScanFeeder.java
import nodePackage.MetaType;
import nodePackage.NodeSet;
package ruleParser;
public interface IScanFeeder {
public void handleParent(String parentText, int lineNumber);
public void handleChild(String parentText, String childText, String firstKeywordsGroup, int lineNumber);
// public void handleNeedWant(String parentText, String childText, int lineNumber); | public void handleListItem(String parentText, String itemText, MetaType metaTyp); |
DeanLee77/Nadia | src/ruleParser/IScanFeeder.java | // Path: src/nodePackage/MetaType.java
// public enum MetaType {
// LINE, FIXED, INPUT, ITEM, GOAL, CLICK_LINK, SOP_DOC
//
// }
//
// Path: src/nodePackage/NodeSet.java
// public class NodeSet {
// private String nodeSetName;
// private HashMap<String, Node> nodeMap ;
// private HashMap<Integer, String> nodeIdMap;
// private List<Node> sortedNodeList;
// private HashMap<String, FactValue> inputMap;
// private HashMap<String, FactValue> factMap;
// private Node defaultGoalNode;
// private DependencyMatrix dependencyMatrix;
//
// public NodeSet()
// {
// this.nodeSetName = "";
// this.inputMap = new HashMap<>();
// this.factMap = new HashMap<>();
// this.nodeMap = new HashMap<>();
// this.nodeIdMap = new HashMap<>();
// this.sortedNodeList = new ArrayList<>();
//
// }
//
// public DependencyMatrix getDependencyMatrix()
// {
// return this.dependencyMatrix;
// }
// public void setDependencyMatrix(DependencyMatrix dm)
// {
// this.dependencyMatrix = dm;
// }
// public void setDependencyMatrix(int[][] dependencyMatrix)
// {
// this.dependencyMatrix = new DependencyMatrix(dependencyMatrix);
// }
//
// public String getNodeSetName()
// {
// return this.nodeSetName;
// }
// public void setNodeSetName(String nodeSetName)
// {
// this.nodeSetName = nodeSetName;
// }
//
// public void setNodeIdMap(HashMap<Integer, String> nodeIdMap)
// {
// this.nodeIdMap = nodeIdMap;
// }
// public HashMap<Integer, String> getNodeIdMap()
// {
// return this.nodeIdMap;
// }
// public void setNodeMap(HashMap<String, Node> nodeMap)
// {
// this.nodeMap = nodeMap;
// }
// public HashMap<String, Node> getNodeMap()
// {
// return this.nodeMap;
// }
//
// public void setNodeSortedList(List<Node> sortedNodeList)
// {
// this.sortedNodeList = sortedNodeList;
// }
// public List<Node> getNodeSortedList()
// {
// return this.sortedNodeList;
// }
//
// public HashMap<String, FactValue> getInputMap()
// {
// return this.inputMap;
// }
//
// public void setFactMap(HashMap<String, FactValue> factMap)
// {
// this.factMap = factMap;
// }
// public HashMap<String, FactValue> getFactMap()
// {
// return this.factMap;
// }
//
// public Node getNode(int nodeIndex)
// {
// return sortedNodeList.get(nodeIndex);
// }
//
// public Node getNode(String nodeName)
// {
// return nodeMap.get(nodeName);
// }
//
// public Node getNodeByNodeId(int nodeId)
// {
// return getNode(getNodeIdMap().get(nodeId));
// }
//
// public int findNodeIndex(String nodeName)
// {
// int nodeIndex = IntStream.range(0, getNodeSortedList().size()).filter(i -> getNodeSortedList().get(i).getNodeName().equals(nodeName)).toArray()[0];
//
// return nodeIndex;
// }
//
// public void setDefaultGoalNode(String name)
// {
// this.defaultGoalNode = this.nodeMap.get(name);
// }
// public Node getDefaultGoalNode()
// {
// return this.defaultGoalNode;
// }
// public HashMap<String, FactValue> transferFactMapToWorkingMemory(HashMap<String, FactValue> workingMemory)
// {
// inputMap.forEach((k,v)->workingMemory.put(k, v));
//
// return workingMemory;
// }
//
//
//
// }
| import nodePackage.MetaType;
import nodePackage.NodeSet; | package ruleParser;
public interface IScanFeeder {
public void handleParent(String parentText, int lineNumber);
public void handleChild(String parentText, String childText, String firstKeywordsGroup, int lineNumber);
// public void handleNeedWant(String parentText, String childText, int lineNumber);
public void handleListItem(String parentText, String itemText, MetaType metaTyp);
// public void handleIterateCheck(String iterateParent, String parentText, String checkText, int lineNumber);
public String handleWarning(String parentText); | // Path: src/nodePackage/MetaType.java
// public enum MetaType {
// LINE, FIXED, INPUT, ITEM, GOAL, CLICK_LINK, SOP_DOC
//
// }
//
// Path: src/nodePackage/NodeSet.java
// public class NodeSet {
// private String nodeSetName;
// private HashMap<String, Node> nodeMap ;
// private HashMap<Integer, String> nodeIdMap;
// private List<Node> sortedNodeList;
// private HashMap<String, FactValue> inputMap;
// private HashMap<String, FactValue> factMap;
// private Node defaultGoalNode;
// private DependencyMatrix dependencyMatrix;
//
// public NodeSet()
// {
// this.nodeSetName = "";
// this.inputMap = new HashMap<>();
// this.factMap = new HashMap<>();
// this.nodeMap = new HashMap<>();
// this.nodeIdMap = new HashMap<>();
// this.sortedNodeList = new ArrayList<>();
//
// }
//
// public DependencyMatrix getDependencyMatrix()
// {
// return this.dependencyMatrix;
// }
// public void setDependencyMatrix(DependencyMatrix dm)
// {
// this.dependencyMatrix = dm;
// }
// public void setDependencyMatrix(int[][] dependencyMatrix)
// {
// this.dependencyMatrix = new DependencyMatrix(dependencyMatrix);
// }
//
// public String getNodeSetName()
// {
// return this.nodeSetName;
// }
// public void setNodeSetName(String nodeSetName)
// {
// this.nodeSetName = nodeSetName;
// }
//
// public void setNodeIdMap(HashMap<Integer, String> nodeIdMap)
// {
// this.nodeIdMap = nodeIdMap;
// }
// public HashMap<Integer, String> getNodeIdMap()
// {
// return this.nodeIdMap;
// }
// public void setNodeMap(HashMap<String, Node> nodeMap)
// {
// this.nodeMap = nodeMap;
// }
// public HashMap<String, Node> getNodeMap()
// {
// return this.nodeMap;
// }
//
// public void setNodeSortedList(List<Node> sortedNodeList)
// {
// this.sortedNodeList = sortedNodeList;
// }
// public List<Node> getNodeSortedList()
// {
// return this.sortedNodeList;
// }
//
// public HashMap<String, FactValue> getInputMap()
// {
// return this.inputMap;
// }
//
// public void setFactMap(HashMap<String, FactValue> factMap)
// {
// this.factMap = factMap;
// }
// public HashMap<String, FactValue> getFactMap()
// {
// return this.factMap;
// }
//
// public Node getNode(int nodeIndex)
// {
// return sortedNodeList.get(nodeIndex);
// }
//
// public Node getNode(String nodeName)
// {
// return nodeMap.get(nodeName);
// }
//
// public Node getNodeByNodeId(int nodeId)
// {
// return getNode(getNodeIdMap().get(nodeId));
// }
//
// public int findNodeIndex(String nodeName)
// {
// int nodeIndex = IntStream.range(0, getNodeSortedList().size()).filter(i -> getNodeSortedList().get(i).getNodeName().equals(nodeName)).toArray()[0];
//
// return nodeIndex;
// }
//
// public void setDefaultGoalNode(String name)
// {
// this.defaultGoalNode = this.nodeMap.get(name);
// }
// public Node getDefaultGoalNode()
// {
// return this.defaultGoalNode;
// }
// public HashMap<String, FactValue> transferFactMapToWorkingMemory(HashMap<String, FactValue> workingMemory)
// {
// inputMap.forEach((k,v)->workingMemory.put(k, v));
//
// return workingMemory;
// }
//
//
//
// }
// Path: src/ruleParser/IScanFeeder.java
import nodePackage.MetaType;
import nodePackage.NodeSet;
package ruleParser;
public interface IScanFeeder {
public void handleParent(String parentText, int lineNumber);
public void handleChild(String parentText, String childText, String firstKeywordsGroup, int lineNumber);
// public void handleNeedWant(String parentText, String childText, int lineNumber);
public void handleListItem(String parentText, String itemText, MetaType metaTyp);
// public void handleIterateCheck(String iterateParent, String parentText, String checkText, int lineNumber);
public String handleWarning(String parentText); | public NodeSet getNodeSet(); |
DeanLee77/Nadia | src/nodePackage/Node.java | // Path: src/factValuePackage/FactValue.java
// public abstract class FactValue {
//
//
// public static FactDefiStringValue parseDefiString(String s) {
// return new FactDefiStringValue(s);
// }
//
// public static FactStringValue parse(String s) {
// return new FactStringValue(s);
// }
//
// public static FactIntegerValue parse(int i) {
// return new FactIntegerValue(i);
// }
//
// public static FactDateValue parse(LocalDate cal) {
// return new FactDateValue(cal);
// }
//
// public static FactDoubleValue parse(double d) {
// return new FactDoubleValue(d);
// }
//
// @SuppressWarnings("rawtypes")
// public static FactBooleanValue<?> parse(boolean b)
// {
// return new FactBooleanValue(b);
// }
//
// @SuppressWarnings({ "unchecked", "rawtypes" })
// public static FactListValue<?> parse(List<FactValue> l)
// {
// return new FactListValue(l);
// }
//
// public static FactURLValue parseURL(String url)
// {
// return new FactURLValue(url);
// }
//
// public static FactHashValue parseHash(String hash)
// {
// return new FactHashValue(hash);
// }
//
// public static FactUUIDValue parseUUID(String uuid)
// {
// return new FactUUIDValue(uuid);
// }
//
//
// public abstract FactValueType getType() ;
// public abstract <T> void setDefaultValue(T str);
// public abstract <T> T getValue();
// public abstract <T> T getDefaultValue();
//
// }
//
// Path: src/ruleParser/Tokens.java
// public class Tokens
// {
// public List<String> tokensList;
// public List<String> tokensStringList;
// public String tokensString;
//
// public Tokens(List<String> tl, List<String> tsl, String ts) {
// tokensList = tl;
// tokensStringList = tsl;
// tokensString = ts;
// }
//
// }
| import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.HashMap;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.script.ScriptEngine;
import factValuePackage.FactValue;
import ruleParser.Tokens; | package nodePackage;
public abstract class Node {
protected static int staticNodeId = 0;
protected int nodeId;
protected String nodeName;
protected int nodeLine;
protected String variableName; | // Path: src/factValuePackage/FactValue.java
// public abstract class FactValue {
//
//
// public static FactDefiStringValue parseDefiString(String s) {
// return new FactDefiStringValue(s);
// }
//
// public static FactStringValue parse(String s) {
// return new FactStringValue(s);
// }
//
// public static FactIntegerValue parse(int i) {
// return new FactIntegerValue(i);
// }
//
// public static FactDateValue parse(LocalDate cal) {
// return new FactDateValue(cal);
// }
//
// public static FactDoubleValue parse(double d) {
// return new FactDoubleValue(d);
// }
//
// @SuppressWarnings("rawtypes")
// public static FactBooleanValue<?> parse(boolean b)
// {
// return new FactBooleanValue(b);
// }
//
// @SuppressWarnings({ "unchecked", "rawtypes" })
// public static FactListValue<?> parse(List<FactValue> l)
// {
// return new FactListValue(l);
// }
//
// public static FactURLValue parseURL(String url)
// {
// return new FactURLValue(url);
// }
//
// public static FactHashValue parseHash(String hash)
// {
// return new FactHashValue(hash);
// }
//
// public static FactUUIDValue parseUUID(String uuid)
// {
// return new FactUUIDValue(uuid);
// }
//
//
// public abstract FactValueType getType() ;
// public abstract <T> void setDefaultValue(T str);
// public abstract <T> T getValue();
// public abstract <T> T getDefaultValue();
//
// }
//
// Path: src/ruleParser/Tokens.java
// public class Tokens
// {
// public List<String> tokensList;
// public List<String> tokensStringList;
// public String tokensString;
//
// public Tokens(List<String> tl, List<String> tsl, String ts) {
// tokensList = tl;
// tokensStringList = tsl;
// tokensString = ts;
// }
//
// }
// Path: src/nodePackage/Node.java
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.HashMap;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.script.ScriptEngine;
import factValuePackage.FactValue;
import ruleParser.Tokens;
package nodePackage;
public abstract class Node {
protected static int staticNodeId = 0;
protected int nodeId;
protected String nodeName;
protected int nodeLine;
protected String variableName; | protected FactValue value; |
DeanLee77/Nadia | src/nodePackage/Node.java | // Path: src/factValuePackage/FactValue.java
// public abstract class FactValue {
//
//
// public static FactDefiStringValue parseDefiString(String s) {
// return new FactDefiStringValue(s);
// }
//
// public static FactStringValue parse(String s) {
// return new FactStringValue(s);
// }
//
// public static FactIntegerValue parse(int i) {
// return new FactIntegerValue(i);
// }
//
// public static FactDateValue parse(LocalDate cal) {
// return new FactDateValue(cal);
// }
//
// public static FactDoubleValue parse(double d) {
// return new FactDoubleValue(d);
// }
//
// @SuppressWarnings("rawtypes")
// public static FactBooleanValue<?> parse(boolean b)
// {
// return new FactBooleanValue(b);
// }
//
// @SuppressWarnings({ "unchecked", "rawtypes" })
// public static FactListValue<?> parse(List<FactValue> l)
// {
// return new FactListValue(l);
// }
//
// public static FactURLValue parseURL(String url)
// {
// return new FactURLValue(url);
// }
//
// public static FactHashValue parseHash(String hash)
// {
// return new FactHashValue(hash);
// }
//
// public static FactUUIDValue parseUUID(String uuid)
// {
// return new FactUUIDValue(uuid);
// }
//
//
// public abstract FactValueType getType() ;
// public abstract <T> void setDefaultValue(T str);
// public abstract <T> T getValue();
// public abstract <T> T getDefaultValue();
//
// }
//
// Path: src/ruleParser/Tokens.java
// public class Tokens
// {
// public List<String> tokensList;
// public List<String> tokensStringList;
// public String tokensString;
//
// public Tokens(List<String> tl, List<String> tsl, String ts) {
// tokensList = tl;
// tokensStringList = tsl;
// tokensString = ts;
// }
//
// }
| import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.HashMap;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.script.ScriptEngine;
import factValuePackage.FactValue;
import ruleParser.Tokens; | package nodePackage;
public abstract class Node {
protected static int staticNodeId = 0;
protected int nodeId;
protected String nodeName;
protected int nodeLine;
protected String variableName;
protected FactValue value; | // Path: src/factValuePackage/FactValue.java
// public abstract class FactValue {
//
//
// public static FactDefiStringValue parseDefiString(String s) {
// return new FactDefiStringValue(s);
// }
//
// public static FactStringValue parse(String s) {
// return new FactStringValue(s);
// }
//
// public static FactIntegerValue parse(int i) {
// return new FactIntegerValue(i);
// }
//
// public static FactDateValue parse(LocalDate cal) {
// return new FactDateValue(cal);
// }
//
// public static FactDoubleValue parse(double d) {
// return new FactDoubleValue(d);
// }
//
// @SuppressWarnings("rawtypes")
// public static FactBooleanValue<?> parse(boolean b)
// {
// return new FactBooleanValue(b);
// }
//
// @SuppressWarnings({ "unchecked", "rawtypes" })
// public static FactListValue<?> parse(List<FactValue> l)
// {
// return new FactListValue(l);
// }
//
// public static FactURLValue parseURL(String url)
// {
// return new FactURLValue(url);
// }
//
// public static FactHashValue parseHash(String hash)
// {
// return new FactHashValue(hash);
// }
//
// public static FactUUIDValue parseUUID(String uuid)
// {
// return new FactUUIDValue(uuid);
// }
//
//
// public abstract FactValueType getType() ;
// public abstract <T> void setDefaultValue(T str);
// public abstract <T> T getValue();
// public abstract <T> T getDefaultValue();
//
// }
//
// Path: src/ruleParser/Tokens.java
// public class Tokens
// {
// public List<String> tokensList;
// public List<String> tokensStringList;
// public String tokensString;
//
// public Tokens(List<String> tl, List<String> tsl, String ts) {
// tokensList = tl;
// tokensStringList = tsl;
// tokensString = ts;
// }
//
// }
// Path: src/nodePackage/Node.java
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.HashMap;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.script.ScriptEngine;
import factValuePackage.FactValue;
import ruleParser.Tokens;
package nodePackage;
public abstract class Node {
protected static int staticNodeId = 0;
protected int nodeId;
protected String nodeName;
protected int nodeLine;
protected String variableName;
protected FactValue value; | protected Tokens tokens; |
DeanLee77/Nadia | src/testingPackage/inferenceEngineTest/Fact.java | // Path: src/factValuePackage/FactValue.java
// public abstract class FactValue {
//
//
// public static FactDefiStringValue parseDefiString(String s) {
// return new FactDefiStringValue(s);
// }
//
// public static FactStringValue parse(String s) {
// return new FactStringValue(s);
// }
//
// public static FactIntegerValue parse(int i) {
// return new FactIntegerValue(i);
// }
//
// public static FactDateValue parse(LocalDate cal) {
// return new FactDateValue(cal);
// }
//
// public static FactDoubleValue parse(double d) {
// return new FactDoubleValue(d);
// }
//
// @SuppressWarnings("rawtypes")
// public static FactBooleanValue<?> parse(boolean b)
// {
// return new FactBooleanValue(b);
// }
//
// @SuppressWarnings({ "unchecked", "rawtypes" })
// public static FactListValue<?> parse(List<FactValue> l)
// {
// return new FactListValue(l);
// }
//
// public static FactURLValue parseURL(String url)
// {
// return new FactURLValue(url);
// }
//
// public static FactHashValue parseHash(String hash)
// {
// return new FactHashValue(hash);
// }
//
// public static FactUUIDValue parseUUID(String uuid)
// {
// return new FactUUIDValue(uuid);
// }
//
//
// public abstract FactValueType getType() ;
// public abstract <T> void setDefaultValue(T str);
// public abstract <T> T getValue();
// public abstract <T> T getDefaultValue();
//
// }
| import factValuePackage.FactValue; | package testingPackage.inferenceEngineTest;
public class Fact {
String variableName; | // Path: src/factValuePackage/FactValue.java
// public abstract class FactValue {
//
//
// public static FactDefiStringValue parseDefiString(String s) {
// return new FactDefiStringValue(s);
// }
//
// public static FactStringValue parse(String s) {
// return new FactStringValue(s);
// }
//
// public static FactIntegerValue parse(int i) {
// return new FactIntegerValue(i);
// }
//
// public static FactDateValue parse(LocalDate cal) {
// return new FactDateValue(cal);
// }
//
// public static FactDoubleValue parse(double d) {
// return new FactDoubleValue(d);
// }
//
// @SuppressWarnings("rawtypes")
// public static FactBooleanValue<?> parse(boolean b)
// {
// return new FactBooleanValue(b);
// }
//
// @SuppressWarnings({ "unchecked", "rawtypes" })
// public static FactListValue<?> parse(List<FactValue> l)
// {
// return new FactListValue(l);
// }
//
// public static FactURLValue parseURL(String url)
// {
// return new FactURLValue(url);
// }
//
// public static FactHashValue parseHash(String hash)
// {
// return new FactHashValue(hash);
// }
//
// public static FactUUIDValue parseUUID(String uuid)
// {
// return new FactUUIDValue(uuid);
// }
//
//
// public abstract FactValueType getType() ;
// public abstract <T> void setDefaultValue(T str);
// public abstract <T> T getValue();
// public abstract <T> T getDefaultValue();
//
// }
// Path: src/testingPackage/inferenceEngineTest/Fact.java
import factValuePackage.FactValue;
package testingPackage.inferenceEngineTest;
public class Fact {
String variableName; | FactValue fv; |
DeanLee77/Nadia | src/nodePackage/ValueConclusionLine.java | // Path: src/ruleParser/Tokens.java
// public class Tokens
// {
// public List<String> tokensList;
// public List<String> tokensStringList;
// public String tokensString;
//
// public Tokens(List<String> tl, List<String> tsl, String ts) {
// tokensList = tl;
// tokensStringList = tsl;
// tokensString = ts;
// }
//
// }
| import java.util.HashMap;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import javax.script.ScriptEngine;
import factValuePackage.*;
import ruleParser.Tokens; | package nodePackage;
public class ValueConclusionLine extends Node{
private boolean isPlainStatementFormat;
/*
* ValueConclusionLine format is as follows;
* 1. 'A-statement IS B-statement';
* 2. 'A-item name IS IN LIST: B-list name'; or
* 3. 'A-statement'(plain statement line) including statement of 'A' type from a child node of ExprConclusionLine type which are 'NEEDS' and 'WANTS'.
* When the inference engine reaches at a ValueConclusionLine and needs to ask a question to a user,
* this rule must be either 'A (plain statement)' or 'A IS B' format due to the reason that other than the two format cannot be a parent rule.
* Hence, the question can be from either variableName or ruleName, and a result of the question will be inserted into the workingMemory.
* However, when the engine reaches at the line during forward-chaining then the key for the workingMemory will be a ruleName,
* and value for the workingMemory will be set as a result of propagation.
*
* If the rule statement is in a format of 'A-statement' then a default value of variable 'value' will be set as 'false'
*
*/ | // Path: src/ruleParser/Tokens.java
// public class Tokens
// {
// public List<String> tokensList;
// public List<String> tokensStringList;
// public String tokensString;
//
// public Tokens(List<String> tl, List<String> tsl, String ts) {
// tokensList = tl;
// tokensStringList = tsl;
// tokensString = ts;
// }
//
// }
// Path: src/nodePackage/ValueConclusionLine.java
import java.util.HashMap;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import javax.script.ScriptEngine;
import factValuePackage.*;
import ruleParser.Tokens;
package nodePackage;
public class ValueConclusionLine extends Node{
private boolean isPlainStatementFormat;
/*
* ValueConclusionLine format is as follows;
* 1. 'A-statement IS B-statement';
* 2. 'A-item name IS IN LIST: B-list name'; or
* 3. 'A-statement'(plain statement line) including statement of 'A' type from a child node of ExprConclusionLine type which are 'NEEDS' and 'WANTS'.
* When the inference engine reaches at a ValueConclusionLine and needs to ask a question to a user,
* this rule must be either 'A (plain statement)' or 'A IS B' format due to the reason that other than the two format cannot be a parent rule.
* Hence, the question can be from either variableName or ruleName, and a result of the question will be inserted into the workingMemory.
* However, when the engine reaches at the line during forward-chaining then the key for the workingMemory will be a ruleName,
* and value for the workingMemory will be set as a result of propagation.
*
* If the rule statement is in a format of 'A-statement' then a default value of variable 'value' will be set as 'false'
*
*/ | public ValueConclusionLine(String nodeText, Tokens tokens) |
DeanLee77/Nadia | src/nodePackage/NodeSet.java | // Path: src/factValuePackage/FactValue.java
// public abstract class FactValue {
//
//
// public static FactDefiStringValue parseDefiString(String s) {
// return new FactDefiStringValue(s);
// }
//
// public static FactStringValue parse(String s) {
// return new FactStringValue(s);
// }
//
// public static FactIntegerValue parse(int i) {
// return new FactIntegerValue(i);
// }
//
// public static FactDateValue parse(LocalDate cal) {
// return new FactDateValue(cal);
// }
//
// public static FactDoubleValue parse(double d) {
// return new FactDoubleValue(d);
// }
//
// @SuppressWarnings("rawtypes")
// public static FactBooleanValue<?> parse(boolean b)
// {
// return new FactBooleanValue(b);
// }
//
// @SuppressWarnings({ "unchecked", "rawtypes" })
// public static FactListValue<?> parse(List<FactValue> l)
// {
// return new FactListValue(l);
// }
//
// public static FactURLValue parseURL(String url)
// {
// return new FactURLValue(url);
// }
//
// public static FactHashValue parseHash(String hash)
// {
// return new FactHashValue(hash);
// }
//
// public static FactUUIDValue parseUUID(String uuid)
// {
// return new FactUUIDValue(uuid);
// }
//
//
// public abstract FactValueType getType() ;
// public abstract <T> void setDefaultValue(T str);
// public abstract <T> T getValue();
// public abstract <T> T getDefaultValue();
//
// }
| import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.stream.IntStream;
import factValuePackage.FactValue; | package nodePackage;
public class NodeSet {
private String nodeSetName;
private HashMap<String, Node> nodeMap ;
private HashMap<Integer, String> nodeIdMap;
private List<Node> sortedNodeList; | // Path: src/factValuePackage/FactValue.java
// public abstract class FactValue {
//
//
// public static FactDefiStringValue parseDefiString(String s) {
// return new FactDefiStringValue(s);
// }
//
// public static FactStringValue parse(String s) {
// return new FactStringValue(s);
// }
//
// public static FactIntegerValue parse(int i) {
// return new FactIntegerValue(i);
// }
//
// public static FactDateValue parse(LocalDate cal) {
// return new FactDateValue(cal);
// }
//
// public static FactDoubleValue parse(double d) {
// return new FactDoubleValue(d);
// }
//
// @SuppressWarnings("rawtypes")
// public static FactBooleanValue<?> parse(boolean b)
// {
// return new FactBooleanValue(b);
// }
//
// @SuppressWarnings({ "unchecked", "rawtypes" })
// public static FactListValue<?> parse(List<FactValue> l)
// {
// return new FactListValue(l);
// }
//
// public static FactURLValue parseURL(String url)
// {
// return new FactURLValue(url);
// }
//
// public static FactHashValue parseHash(String hash)
// {
// return new FactHashValue(hash);
// }
//
// public static FactUUIDValue parseUUID(String uuid)
// {
// return new FactUUIDValue(uuid);
// }
//
//
// public abstract FactValueType getType() ;
// public abstract <T> void setDefaultValue(T str);
// public abstract <T> T getValue();
// public abstract <T> T getDefaultValue();
//
// }
// Path: src/nodePackage/NodeSet.java
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.stream.IntStream;
import factValuePackage.FactValue;
package nodePackage;
public class NodeSet {
private String nodeSetName;
private HashMap<String, Node> nodeMap ;
private HashMap<Integer, String> nodeIdMap;
private List<Node> sortedNodeList; | private HashMap<String, FactValue> inputMap; |
dataArtisans/flink-benchmarks | src/main/java/org/apache/flink/benchmark/TwoInputBenchmark.java | // Path: src/main/java/org/apache/flink/benchmark/functions/LongSource.java
// public class LongSource extends RichParallelSourceFunction<Long> {
//
// private volatile boolean running = true;
// private long maxValue;
//
// public LongSource(long maxValue) {
// this.maxValue = maxValue;
// }
//
// @Override
// public void run(SourceContext<Long> ctx) throws Exception {
// long counter = 0;
//
// while (running) {
// synchronized (ctx.getCheckpointLock()) {
// ctx.collect(counter);
// counter++;
// if (counter >= maxValue) {
// cancel();
// }
// }
// }
// }
//
// @Override
// public void cancel() {
// running = false;
// }
// }
//
// Path: src/main/java/org/apache/flink/benchmark/functions/QueuingLongSource.java
// public class QueuingLongSource extends LongSource {
//
// private static Object lock = new Object();
//
// private static int currentRank = 1;
//
// private final int rank;
//
// public QueuingLongSource(int rank, long maxValue) {
// super(maxValue);
// this.rank = rank;
// }
//
// @Override
// public void run(SourceContext<Long> ctx) throws Exception {
// synchronized (lock) {
// while (currentRank != rank) {
// lock.wait();
// }
// }
//
// super.run(ctx);
//
// synchronized (lock) {
// currentRank++;
// lock.notifyAll();
// }
// }
//
// public static void reset() {
// currentRank = 1;
// }
// }
//
// Path: src/main/java/org/apache/flink/benchmark/operators/MultiplyByTwoCoStreamMap.java
// public class MultiplyByTwoCoStreamMap
// extends AbstractStreamOperator<Long>
// implements TwoInputStreamOperator<Long, Long, Long> {
//
// @Override
// public void processElement1(StreamRecord<Long> element) {
// output.collect(element.replace(element.getValue() * 2));
// }
//
// @Override
// public void processElement2(StreamRecord<Long> element) {
// output.collect(element.replace(element.getValue() * 2));
// }
// }
| import org.openjdk.jmh.runner.options.Options;
import org.openjdk.jmh.runner.options.OptionsBuilder;
import org.openjdk.jmh.runner.options.VerboseMode;
import org.apache.flink.api.common.typeinfo.TypeInformation;
import org.apache.flink.benchmark.functions.LongSource;
import org.apache.flink.benchmark.functions.QueuingLongSource;
import org.apache.flink.benchmark.operators.MultiplyByTwoCoStreamMap;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.apache.flink.streaming.api.functions.sink.DiscardingSink;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.OperationsPerInvocation;
import org.openjdk.jmh.runner.Runner;
import org.openjdk.jmh.runner.RunnerException; | /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.flink.benchmark;
public class TwoInputBenchmark extends BenchmarkBase {
public static final int RECORDS_PER_INVOCATION = 25_000_000;
public static final int ONE_IDLE_RECORDS_PER_INVOCATION = 15_000_000;
private static final long CHECKPOINT_INTERVAL_MS = 100;
public static void main(String[] args)
throws RunnerException {
Options options = new OptionsBuilder()
.verbosity(VerboseMode.NORMAL)
.include(".*" + TwoInputBenchmark.class.getCanonicalName() + ".*")
.build();
new Runner(options).run();
}
@Benchmark
@OperationsPerInvocation(value = TwoInputBenchmark.RECORDS_PER_INVOCATION)
public void twoInputMapSink(FlinkEnvironmentContext context) throws Exception {
StreamExecutionEnvironment env = context.env;
env.enableCheckpointing(CHECKPOINT_INTERVAL_MS);
env.setParallelism(1);
// Setting buffer timeout to 1 is an attempt to improve twoInputMapSink benchmark stability.
// Without 1ms buffer timeout, some JVM forks are much slower then others, making results
// unstable and unreliable.
env.setBufferTimeout(1);
long numRecordsPerInput = RECORDS_PER_INVOCATION / 2; | // Path: src/main/java/org/apache/flink/benchmark/functions/LongSource.java
// public class LongSource extends RichParallelSourceFunction<Long> {
//
// private volatile boolean running = true;
// private long maxValue;
//
// public LongSource(long maxValue) {
// this.maxValue = maxValue;
// }
//
// @Override
// public void run(SourceContext<Long> ctx) throws Exception {
// long counter = 0;
//
// while (running) {
// synchronized (ctx.getCheckpointLock()) {
// ctx.collect(counter);
// counter++;
// if (counter >= maxValue) {
// cancel();
// }
// }
// }
// }
//
// @Override
// public void cancel() {
// running = false;
// }
// }
//
// Path: src/main/java/org/apache/flink/benchmark/functions/QueuingLongSource.java
// public class QueuingLongSource extends LongSource {
//
// private static Object lock = new Object();
//
// private static int currentRank = 1;
//
// private final int rank;
//
// public QueuingLongSource(int rank, long maxValue) {
// super(maxValue);
// this.rank = rank;
// }
//
// @Override
// public void run(SourceContext<Long> ctx) throws Exception {
// synchronized (lock) {
// while (currentRank != rank) {
// lock.wait();
// }
// }
//
// super.run(ctx);
//
// synchronized (lock) {
// currentRank++;
// lock.notifyAll();
// }
// }
//
// public static void reset() {
// currentRank = 1;
// }
// }
//
// Path: src/main/java/org/apache/flink/benchmark/operators/MultiplyByTwoCoStreamMap.java
// public class MultiplyByTwoCoStreamMap
// extends AbstractStreamOperator<Long>
// implements TwoInputStreamOperator<Long, Long, Long> {
//
// @Override
// public void processElement1(StreamRecord<Long> element) {
// output.collect(element.replace(element.getValue() * 2));
// }
//
// @Override
// public void processElement2(StreamRecord<Long> element) {
// output.collect(element.replace(element.getValue() * 2));
// }
// }
// Path: src/main/java/org/apache/flink/benchmark/TwoInputBenchmark.java
import org.openjdk.jmh.runner.options.Options;
import org.openjdk.jmh.runner.options.OptionsBuilder;
import org.openjdk.jmh.runner.options.VerboseMode;
import org.apache.flink.api.common.typeinfo.TypeInformation;
import org.apache.flink.benchmark.functions.LongSource;
import org.apache.flink.benchmark.functions.QueuingLongSource;
import org.apache.flink.benchmark.operators.MultiplyByTwoCoStreamMap;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.apache.flink.streaming.api.functions.sink.DiscardingSink;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.OperationsPerInvocation;
import org.openjdk.jmh.runner.Runner;
import org.openjdk.jmh.runner.RunnerException;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.flink.benchmark;
public class TwoInputBenchmark extends BenchmarkBase {
public static final int RECORDS_PER_INVOCATION = 25_000_000;
public static final int ONE_IDLE_RECORDS_PER_INVOCATION = 15_000_000;
private static final long CHECKPOINT_INTERVAL_MS = 100;
public static void main(String[] args)
throws RunnerException {
Options options = new OptionsBuilder()
.verbosity(VerboseMode.NORMAL)
.include(".*" + TwoInputBenchmark.class.getCanonicalName() + ".*")
.build();
new Runner(options).run();
}
@Benchmark
@OperationsPerInvocation(value = TwoInputBenchmark.RECORDS_PER_INVOCATION)
public void twoInputMapSink(FlinkEnvironmentContext context) throws Exception {
StreamExecutionEnvironment env = context.env;
env.enableCheckpointing(CHECKPOINT_INTERVAL_MS);
env.setParallelism(1);
// Setting buffer timeout to 1 is an attempt to improve twoInputMapSink benchmark stability.
// Without 1ms buffer timeout, some JVM forks are much slower then others, making results
// unstable and unreliable.
env.setBufferTimeout(1);
long numRecordsPerInput = RECORDS_PER_INVOCATION / 2; | DataStreamSource<Long> source1 = env.addSource(new LongSource(numRecordsPerInput)); |
dataArtisans/flink-benchmarks | src/main/java/org/apache/flink/benchmark/TwoInputBenchmark.java | // Path: src/main/java/org/apache/flink/benchmark/functions/LongSource.java
// public class LongSource extends RichParallelSourceFunction<Long> {
//
// private volatile boolean running = true;
// private long maxValue;
//
// public LongSource(long maxValue) {
// this.maxValue = maxValue;
// }
//
// @Override
// public void run(SourceContext<Long> ctx) throws Exception {
// long counter = 0;
//
// while (running) {
// synchronized (ctx.getCheckpointLock()) {
// ctx.collect(counter);
// counter++;
// if (counter >= maxValue) {
// cancel();
// }
// }
// }
// }
//
// @Override
// public void cancel() {
// running = false;
// }
// }
//
// Path: src/main/java/org/apache/flink/benchmark/functions/QueuingLongSource.java
// public class QueuingLongSource extends LongSource {
//
// private static Object lock = new Object();
//
// private static int currentRank = 1;
//
// private final int rank;
//
// public QueuingLongSource(int rank, long maxValue) {
// super(maxValue);
// this.rank = rank;
// }
//
// @Override
// public void run(SourceContext<Long> ctx) throws Exception {
// synchronized (lock) {
// while (currentRank != rank) {
// lock.wait();
// }
// }
//
// super.run(ctx);
//
// synchronized (lock) {
// currentRank++;
// lock.notifyAll();
// }
// }
//
// public static void reset() {
// currentRank = 1;
// }
// }
//
// Path: src/main/java/org/apache/flink/benchmark/operators/MultiplyByTwoCoStreamMap.java
// public class MultiplyByTwoCoStreamMap
// extends AbstractStreamOperator<Long>
// implements TwoInputStreamOperator<Long, Long, Long> {
//
// @Override
// public void processElement1(StreamRecord<Long> element) {
// output.collect(element.replace(element.getValue() * 2));
// }
//
// @Override
// public void processElement2(StreamRecord<Long> element) {
// output.collect(element.replace(element.getValue() * 2));
// }
// }
| import org.openjdk.jmh.runner.options.Options;
import org.openjdk.jmh.runner.options.OptionsBuilder;
import org.openjdk.jmh.runner.options.VerboseMode;
import org.apache.flink.api.common.typeinfo.TypeInformation;
import org.apache.flink.benchmark.functions.LongSource;
import org.apache.flink.benchmark.functions.QueuingLongSource;
import org.apache.flink.benchmark.operators.MultiplyByTwoCoStreamMap;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.apache.flink.streaming.api.functions.sink.DiscardingSink;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.OperationsPerInvocation;
import org.openjdk.jmh.runner.Runner;
import org.openjdk.jmh.runner.RunnerException; | /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.flink.benchmark;
public class TwoInputBenchmark extends BenchmarkBase {
public static final int RECORDS_PER_INVOCATION = 25_000_000;
public static final int ONE_IDLE_RECORDS_PER_INVOCATION = 15_000_000;
private static final long CHECKPOINT_INTERVAL_MS = 100;
public static void main(String[] args)
throws RunnerException {
Options options = new OptionsBuilder()
.verbosity(VerboseMode.NORMAL)
.include(".*" + TwoInputBenchmark.class.getCanonicalName() + ".*")
.build();
new Runner(options).run();
}
@Benchmark
@OperationsPerInvocation(value = TwoInputBenchmark.RECORDS_PER_INVOCATION)
public void twoInputMapSink(FlinkEnvironmentContext context) throws Exception {
StreamExecutionEnvironment env = context.env;
env.enableCheckpointing(CHECKPOINT_INTERVAL_MS);
env.setParallelism(1);
// Setting buffer timeout to 1 is an attempt to improve twoInputMapSink benchmark stability.
// Without 1ms buffer timeout, some JVM forks are much slower then others, making results
// unstable and unreliable.
env.setBufferTimeout(1);
long numRecordsPerInput = RECORDS_PER_INVOCATION / 2;
DataStreamSource<Long> source1 = env.addSource(new LongSource(numRecordsPerInput));
DataStreamSource<Long> source2 = env.addSource(new LongSource(numRecordsPerInput));
source1
.connect(source2) | // Path: src/main/java/org/apache/flink/benchmark/functions/LongSource.java
// public class LongSource extends RichParallelSourceFunction<Long> {
//
// private volatile boolean running = true;
// private long maxValue;
//
// public LongSource(long maxValue) {
// this.maxValue = maxValue;
// }
//
// @Override
// public void run(SourceContext<Long> ctx) throws Exception {
// long counter = 0;
//
// while (running) {
// synchronized (ctx.getCheckpointLock()) {
// ctx.collect(counter);
// counter++;
// if (counter >= maxValue) {
// cancel();
// }
// }
// }
// }
//
// @Override
// public void cancel() {
// running = false;
// }
// }
//
// Path: src/main/java/org/apache/flink/benchmark/functions/QueuingLongSource.java
// public class QueuingLongSource extends LongSource {
//
// private static Object lock = new Object();
//
// private static int currentRank = 1;
//
// private final int rank;
//
// public QueuingLongSource(int rank, long maxValue) {
// super(maxValue);
// this.rank = rank;
// }
//
// @Override
// public void run(SourceContext<Long> ctx) throws Exception {
// synchronized (lock) {
// while (currentRank != rank) {
// lock.wait();
// }
// }
//
// super.run(ctx);
//
// synchronized (lock) {
// currentRank++;
// lock.notifyAll();
// }
// }
//
// public static void reset() {
// currentRank = 1;
// }
// }
//
// Path: src/main/java/org/apache/flink/benchmark/operators/MultiplyByTwoCoStreamMap.java
// public class MultiplyByTwoCoStreamMap
// extends AbstractStreamOperator<Long>
// implements TwoInputStreamOperator<Long, Long, Long> {
//
// @Override
// public void processElement1(StreamRecord<Long> element) {
// output.collect(element.replace(element.getValue() * 2));
// }
//
// @Override
// public void processElement2(StreamRecord<Long> element) {
// output.collect(element.replace(element.getValue() * 2));
// }
// }
// Path: src/main/java/org/apache/flink/benchmark/TwoInputBenchmark.java
import org.openjdk.jmh.runner.options.Options;
import org.openjdk.jmh.runner.options.OptionsBuilder;
import org.openjdk.jmh.runner.options.VerboseMode;
import org.apache.flink.api.common.typeinfo.TypeInformation;
import org.apache.flink.benchmark.functions.LongSource;
import org.apache.flink.benchmark.functions.QueuingLongSource;
import org.apache.flink.benchmark.operators.MultiplyByTwoCoStreamMap;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.apache.flink.streaming.api.functions.sink.DiscardingSink;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.OperationsPerInvocation;
import org.openjdk.jmh.runner.Runner;
import org.openjdk.jmh.runner.RunnerException;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.flink.benchmark;
public class TwoInputBenchmark extends BenchmarkBase {
public static final int RECORDS_PER_INVOCATION = 25_000_000;
public static final int ONE_IDLE_RECORDS_PER_INVOCATION = 15_000_000;
private static final long CHECKPOINT_INTERVAL_MS = 100;
public static void main(String[] args)
throws RunnerException {
Options options = new OptionsBuilder()
.verbosity(VerboseMode.NORMAL)
.include(".*" + TwoInputBenchmark.class.getCanonicalName() + ".*")
.build();
new Runner(options).run();
}
@Benchmark
@OperationsPerInvocation(value = TwoInputBenchmark.RECORDS_PER_INVOCATION)
public void twoInputMapSink(FlinkEnvironmentContext context) throws Exception {
StreamExecutionEnvironment env = context.env;
env.enableCheckpointing(CHECKPOINT_INTERVAL_MS);
env.setParallelism(1);
// Setting buffer timeout to 1 is an attempt to improve twoInputMapSink benchmark stability.
// Without 1ms buffer timeout, some JVM forks are much slower then others, making results
// unstable and unreliable.
env.setBufferTimeout(1);
long numRecordsPerInput = RECORDS_PER_INVOCATION / 2;
DataStreamSource<Long> source1 = env.addSource(new LongSource(numRecordsPerInput));
DataStreamSource<Long> source2 = env.addSource(new LongSource(numRecordsPerInput));
source1
.connect(source2) | .transform("custom operator", TypeInformation.of(Long.class), new MultiplyByTwoCoStreamMap()) |
dataArtisans/flink-benchmarks | src/main/java/org/apache/flink/benchmark/TwoInputBenchmark.java | // Path: src/main/java/org/apache/flink/benchmark/functions/LongSource.java
// public class LongSource extends RichParallelSourceFunction<Long> {
//
// private volatile boolean running = true;
// private long maxValue;
//
// public LongSource(long maxValue) {
// this.maxValue = maxValue;
// }
//
// @Override
// public void run(SourceContext<Long> ctx) throws Exception {
// long counter = 0;
//
// while (running) {
// synchronized (ctx.getCheckpointLock()) {
// ctx.collect(counter);
// counter++;
// if (counter >= maxValue) {
// cancel();
// }
// }
// }
// }
//
// @Override
// public void cancel() {
// running = false;
// }
// }
//
// Path: src/main/java/org/apache/flink/benchmark/functions/QueuingLongSource.java
// public class QueuingLongSource extends LongSource {
//
// private static Object lock = new Object();
//
// private static int currentRank = 1;
//
// private final int rank;
//
// public QueuingLongSource(int rank, long maxValue) {
// super(maxValue);
// this.rank = rank;
// }
//
// @Override
// public void run(SourceContext<Long> ctx) throws Exception {
// synchronized (lock) {
// while (currentRank != rank) {
// lock.wait();
// }
// }
//
// super.run(ctx);
//
// synchronized (lock) {
// currentRank++;
// lock.notifyAll();
// }
// }
//
// public static void reset() {
// currentRank = 1;
// }
// }
//
// Path: src/main/java/org/apache/flink/benchmark/operators/MultiplyByTwoCoStreamMap.java
// public class MultiplyByTwoCoStreamMap
// extends AbstractStreamOperator<Long>
// implements TwoInputStreamOperator<Long, Long, Long> {
//
// @Override
// public void processElement1(StreamRecord<Long> element) {
// output.collect(element.replace(element.getValue() * 2));
// }
//
// @Override
// public void processElement2(StreamRecord<Long> element) {
// output.collect(element.replace(element.getValue() * 2));
// }
// }
| import org.openjdk.jmh.runner.options.Options;
import org.openjdk.jmh.runner.options.OptionsBuilder;
import org.openjdk.jmh.runner.options.VerboseMode;
import org.apache.flink.api.common.typeinfo.TypeInformation;
import org.apache.flink.benchmark.functions.LongSource;
import org.apache.flink.benchmark.functions.QueuingLongSource;
import org.apache.flink.benchmark.operators.MultiplyByTwoCoStreamMap;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.apache.flink.streaming.api.functions.sink.DiscardingSink;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.OperationsPerInvocation;
import org.openjdk.jmh.runner.Runner;
import org.openjdk.jmh.runner.RunnerException; | StreamExecutionEnvironment env = context.env;
env.enableCheckpointing(CHECKPOINT_INTERVAL_MS);
env.setParallelism(1);
// Setting buffer timeout to 1 is an attempt to improve twoInputMapSink benchmark stability.
// Without 1ms buffer timeout, some JVM forks are much slower then others, making results
// unstable and unreliable.
env.setBufferTimeout(1);
long numRecordsPerInput = RECORDS_PER_INVOCATION / 2;
DataStreamSource<Long> source1 = env.addSource(new LongSource(numRecordsPerInput));
DataStreamSource<Long> source2 = env.addSource(new LongSource(numRecordsPerInput));
source1
.connect(source2)
.transform("custom operator", TypeInformation.of(Long.class), new MultiplyByTwoCoStreamMap())
.addSink(new DiscardingSink<>());
env.execute();
}
@Benchmark
@OperationsPerInvocation(value = TwoInputBenchmark.ONE_IDLE_RECORDS_PER_INVOCATION)
public void twoInputOneIdleMapSink(FlinkEnvironmentContext context) throws Exception {
StreamExecutionEnvironment env = context.env;
env.enableCheckpointing(CHECKPOINT_INTERVAL_MS);
env.setParallelism(1);
| // Path: src/main/java/org/apache/flink/benchmark/functions/LongSource.java
// public class LongSource extends RichParallelSourceFunction<Long> {
//
// private volatile boolean running = true;
// private long maxValue;
//
// public LongSource(long maxValue) {
// this.maxValue = maxValue;
// }
//
// @Override
// public void run(SourceContext<Long> ctx) throws Exception {
// long counter = 0;
//
// while (running) {
// synchronized (ctx.getCheckpointLock()) {
// ctx.collect(counter);
// counter++;
// if (counter >= maxValue) {
// cancel();
// }
// }
// }
// }
//
// @Override
// public void cancel() {
// running = false;
// }
// }
//
// Path: src/main/java/org/apache/flink/benchmark/functions/QueuingLongSource.java
// public class QueuingLongSource extends LongSource {
//
// private static Object lock = new Object();
//
// private static int currentRank = 1;
//
// private final int rank;
//
// public QueuingLongSource(int rank, long maxValue) {
// super(maxValue);
// this.rank = rank;
// }
//
// @Override
// public void run(SourceContext<Long> ctx) throws Exception {
// synchronized (lock) {
// while (currentRank != rank) {
// lock.wait();
// }
// }
//
// super.run(ctx);
//
// synchronized (lock) {
// currentRank++;
// lock.notifyAll();
// }
// }
//
// public static void reset() {
// currentRank = 1;
// }
// }
//
// Path: src/main/java/org/apache/flink/benchmark/operators/MultiplyByTwoCoStreamMap.java
// public class MultiplyByTwoCoStreamMap
// extends AbstractStreamOperator<Long>
// implements TwoInputStreamOperator<Long, Long, Long> {
//
// @Override
// public void processElement1(StreamRecord<Long> element) {
// output.collect(element.replace(element.getValue() * 2));
// }
//
// @Override
// public void processElement2(StreamRecord<Long> element) {
// output.collect(element.replace(element.getValue() * 2));
// }
// }
// Path: src/main/java/org/apache/flink/benchmark/TwoInputBenchmark.java
import org.openjdk.jmh.runner.options.Options;
import org.openjdk.jmh.runner.options.OptionsBuilder;
import org.openjdk.jmh.runner.options.VerboseMode;
import org.apache.flink.api.common.typeinfo.TypeInformation;
import org.apache.flink.benchmark.functions.LongSource;
import org.apache.flink.benchmark.functions.QueuingLongSource;
import org.apache.flink.benchmark.operators.MultiplyByTwoCoStreamMap;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.apache.flink.streaming.api.functions.sink.DiscardingSink;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.OperationsPerInvocation;
import org.openjdk.jmh.runner.Runner;
import org.openjdk.jmh.runner.RunnerException;
StreamExecutionEnvironment env = context.env;
env.enableCheckpointing(CHECKPOINT_INTERVAL_MS);
env.setParallelism(1);
// Setting buffer timeout to 1 is an attempt to improve twoInputMapSink benchmark stability.
// Without 1ms buffer timeout, some JVM forks are much slower then others, making results
// unstable and unreliable.
env.setBufferTimeout(1);
long numRecordsPerInput = RECORDS_PER_INVOCATION / 2;
DataStreamSource<Long> source1 = env.addSource(new LongSource(numRecordsPerInput));
DataStreamSource<Long> source2 = env.addSource(new LongSource(numRecordsPerInput));
source1
.connect(source2)
.transform("custom operator", TypeInformation.of(Long.class), new MultiplyByTwoCoStreamMap())
.addSink(new DiscardingSink<>());
env.execute();
}
@Benchmark
@OperationsPerInvocation(value = TwoInputBenchmark.ONE_IDLE_RECORDS_PER_INVOCATION)
public void twoInputOneIdleMapSink(FlinkEnvironmentContext context) throws Exception {
StreamExecutionEnvironment env = context.env;
env.enableCheckpointing(CHECKPOINT_INTERVAL_MS);
env.setParallelism(1);
| QueuingLongSource.reset(); |
dataArtisans/flink-benchmarks | src/main/java/org/apache/flink/benchmark/RocksStateBackendBenchmark.java | // Path: src/main/java/org/apache/flink/benchmark/functions/IntLongApplications.java
// public class IntLongApplications {
// public static <W extends Window> void reduceWithWindow(
// DataStreamSource<IntegerLongSource.Record> source,
// WindowAssigner<Object, W> windowAssigner) {
// source
// .map(new MultiplyIntLongByTwo())
// .keyBy(record -> record.key)
// .window(windowAssigner)
// .reduce(new SumReduceIntLong())
// .addSink(new CollectSink());
// }
// }
| import org.apache.flink.benchmark.functions.IntLongApplications;
import org.apache.flink.configuration.Configuration;
import org.apache.flink.configuration.MemorySize;
import org.apache.flink.contrib.streaming.state.RocksDBOptions;
import org.apache.flink.streaming.api.windowing.assigners.TumblingEventTimeWindows;
import org.apache.flink.streaming.api.windowing.time.Time;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.OperationsPerInvocation;
import org.openjdk.jmh.annotations.Param;
import org.openjdk.jmh.annotations.Setup;
import org.openjdk.jmh.annotations.State;
import org.openjdk.jmh.annotations.TearDown;
import org.openjdk.jmh.runner.Runner;
import org.openjdk.jmh.runner.RunnerException;
import org.openjdk.jmh.runner.options.Options;
import org.openjdk.jmh.runner.options.OptionsBuilder;
import org.openjdk.jmh.runner.options.VerboseMode;
import java.io.IOException;
import static org.openjdk.jmh.annotations.Scope.Thread; | /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.flink.benchmark;
@OperationsPerInvocation(value = RocksStateBackendBenchmark.RECORDS_PER_INVOCATION)
public class RocksStateBackendBenchmark extends StateBackendBenchmarkBase {
public static final int RECORDS_PER_INVOCATION = 2_000_000;
public static void main(String[] args)
throws RunnerException {
Options options = new OptionsBuilder()
.verbosity(VerboseMode.NORMAL)
.include(".*" + RocksStateBackendBenchmark.class.getCanonicalName() + ".*")
.build();
new Runner(options).run();
}
@Benchmark
public void stateBackends(RocksStateBackendContext context) throws Exception { | // Path: src/main/java/org/apache/flink/benchmark/functions/IntLongApplications.java
// public class IntLongApplications {
// public static <W extends Window> void reduceWithWindow(
// DataStreamSource<IntegerLongSource.Record> source,
// WindowAssigner<Object, W> windowAssigner) {
// source
// .map(new MultiplyIntLongByTwo())
// .keyBy(record -> record.key)
// .window(windowAssigner)
// .reduce(new SumReduceIntLong())
// .addSink(new CollectSink());
// }
// }
// Path: src/main/java/org/apache/flink/benchmark/RocksStateBackendBenchmark.java
import org.apache.flink.benchmark.functions.IntLongApplications;
import org.apache.flink.configuration.Configuration;
import org.apache.flink.configuration.MemorySize;
import org.apache.flink.contrib.streaming.state.RocksDBOptions;
import org.apache.flink.streaming.api.windowing.assigners.TumblingEventTimeWindows;
import org.apache.flink.streaming.api.windowing.time.Time;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.OperationsPerInvocation;
import org.openjdk.jmh.annotations.Param;
import org.openjdk.jmh.annotations.Setup;
import org.openjdk.jmh.annotations.State;
import org.openjdk.jmh.annotations.TearDown;
import org.openjdk.jmh.runner.Runner;
import org.openjdk.jmh.runner.RunnerException;
import org.openjdk.jmh.runner.options.Options;
import org.openjdk.jmh.runner.options.OptionsBuilder;
import org.openjdk.jmh.runner.options.VerboseMode;
import java.io.IOException;
import static org.openjdk.jmh.annotations.Scope.Thread;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.flink.benchmark;
@OperationsPerInvocation(value = RocksStateBackendBenchmark.RECORDS_PER_INVOCATION)
public class RocksStateBackendBenchmark extends StateBackendBenchmarkBase {
public static final int RECORDS_PER_INVOCATION = 2_000_000;
public static void main(String[] args)
throws RunnerException {
Options options = new OptionsBuilder()
.verbosity(VerboseMode.NORMAL)
.include(".*" + RocksStateBackendBenchmark.class.getCanonicalName() + ".*")
.build();
new Runner(options).run();
}
@Benchmark
public void stateBackends(RocksStateBackendContext context) throws Exception { | IntLongApplications.reduceWithWindow(context.source, TumblingEventTimeWindows.of(Time.seconds(10_000))); |
dataArtisans/flink-benchmarks | src/main/java/org/apache/flink/benchmark/InputBenchmark.java | // Path: src/main/java/org/apache/flink/benchmark/functions/LongSource.java
// public class LongSource extends RichParallelSourceFunction<Long> {
//
// private volatile boolean running = true;
// private long maxValue;
//
// public LongSource(long maxValue) {
// this.maxValue = maxValue;
// }
//
// @Override
// public void run(SourceContext<Long> ctx) throws Exception {
// long counter = 0;
//
// while (running) {
// synchronized (ctx.getCheckpointLock()) {
// ctx.collect(counter);
// counter++;
// if (counter >= maxValue) {
// cancel();
// }
// }
// }
// }
//
// @Override
// public void cancel() {
// running = false;
// }
// }
//
// Path: src/main/java/org/apache/flink/benchmark/functions/MultiplyByTwo.java
// public class MultiplyByTwo implements MapFunction<Long, Long> {
// @Override
// public Long map(Long value) throws Exception {
// return value * 2;
// }
// }
| import org.openjdk.jmh.runner.options.VerboseMode;
import org.apache.flink.benchmark.functions.LongSource;
import org.apache.flink.benchmark.functions.MultiplyByTwo;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.apache.flink.streaming.api.functions.sink.DiscardingSink;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.OperationsPerInvocation;
import org.openjdk.jmh.runner.Runner;
import org.openjdk.jmh.runner.RunnerException;
import org.openjdk.jmh.runner.options.Options;
import org.openjdk.jmh.runner.options.OptionsBuilder; | /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.flink.benchmark;
@OperationsPerInvocation(value = InputBenchmark.RECORDS_PER_INVOCATION)
public class InputBenchmark extends BenchmarkBase {
public static final int RECORDS_PER_INVOCATION = 15_000_000;
private static final long CHECKPOINT_INTERVAL_MS = 100;
public static void main(String[] args)
throws RunnerException {
Options options = new OptionsBuilder()
.verbosity(VerboseMode.NORMAL)
.include(".*" + InputBenchmark.class.getCanonicalName() + ".*")
.build();
new Runner(options).run();
}
@Benchmark
public void mapSink(FlinkEnvironmentContext context) throws Exception {
StreamExecutionEnvironment env = context.env;
env.enableCheckpointing(CHECKPOINT_INTERVAL_MS);
env.setParallelism(1);
| // Path: src/main/java/org/apache/flink/benchmark/functions/LongSource.java
// public class LongSource extends RichParallelSourceFunction<Long> {
//
// private volatile boolean running = true;
// private long maxValue;
//
// public LongSource(long maxValue) {
// this.maxValue = maxValue;
// }
//
// @Override
// public void run(SourceContext<Long> ctx) throws Exception {
// long counter = 0;
//
// while (running) {
// synchronized (ctx.getCheckpointLock()) {
// ctx.collect(counter);
// counter++;
// if (counter >= maxValue) {
// cancel();
// }
// }
// }
// }
//
// @Override
// public void cancel() {
// running = false;
// }
// }
//
// Path: src/main/java/org/apache/flink/benchmark/functions/MultiplyByTwo.java
// public class MultiplyByTwo implements MapFunction<Long, Long> {
// @Override
// public Long map(Long value) throws Exception {
// return value * 2;
// }
// }
// Path: src/main/java/org/apache/flink/benchmark/InputBenchmark.java
import org.openjdk.jmh.runner.options.VerboseMode;
import org.apache.flink.benchmark.functions.LongSource;
import org.apache.flink.benchmark.functions.MultiplyByTwo;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.apache.flink.streaming.api.functions.sink.DiscardingSink;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.OperationsPerInvocation;
import org.openjdk.jmh.runner.Runner;
import org.openjdk.jmh.runner.RunnerException;
import org.openjdk.jmh.runner.options.Options;
import org.openjdk.jmh.runner.options.OptionsBuilder;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.flink.benchmark;
@OperationsPerInvocation(value = InputBenchmark.RECORDS_PER_INVOCATION)
public class InputBenchmark extends BenchmarkBase {
public static final int RECORDS_PER_INVOCATION = 15_000_000;
private static final long CHECKPOINT_INTERVAL_MS = 100;
public static void main(String[] args)
throws RunnerException {
Options options = new OptionsBuilder()
.verbosity(VerboseMode.NORMAL)
.include(".*" + InputBenchmark.class.getCanonicalName() + ".*")
.build();
new Runner(options).run();
}
@Benchmark
public void mapSink(FlinkEnvironmentContext context) throws Exception {
StreamExecutionEnvironment env = context.env;
env.enableCheckpointing(CHECKPOINT_INTERVAL_MS);
env.setParallelism(1);
| DataStreamSource<Long> source = env.addSource(new LongSource(RECORDS_PER_INVOCATION)); |
dataArtisans/flink-benchmarks | src/main/java/org/apache/flink/benchmark/InputBenchmark.java | // Path: src/main/java/org/apache/flink/benchmark/functions/LongSource.java
// public class LongSource extends RichParallelSourceFunction<Long> {
//
// private volatile boolean running = true;
// private long maxValue;
//
// public LongSource(long maxValue) {
// this.maxValue = maxValue;
// }
//
// @Override
// public void run(SourceContext<Long> ctx) throws Exception {
// long counter = 0;
//
// while (running) {
// synchronized (ctx.getCheckpointLock()) {
// ctx.collect(counter);
// counter++;
// if (counter >= maxValue) {
// cancel();
// }
// }
// }
// }
//
// @Override
// public void cancel() {
// running = false;
// }
// }
//
// Path: src/main/java/org/apache/flink/benchmark/functions/MultiplyByTwo.java
// public class MultiplyByTwo implements MapFunction<Long, Long> {
// @Override
// public Long map(Long value) throws Exception {
// return value * 2;
// }
// }
| import org.openjdk.jmh.runner.options.VerboseMode;
import org.apache.flink.benchmark.functions.LongSource;
import org.apache.flink.benchmark.functions.MultiplyByTwo;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.apache.flink.streaming.api.functions.sink.DiscardingSink;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.OperationsPerInvocation;
import org.openjdk.jmh.runner.Runner;
import org.openjdk.jmh.runner.RunnerException;
import org.openjdk.jmh.runner.options.Options;
import org.openjdk.jmh.runner.options.OptionsBuilder; | /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.flink.benchmark;
@OperationsPerInvocation(value = InputBenchmark.RECORDS_PER_INVOCATION)
public class InputBenchmark extends BenchmarkBase {
public static final int RECORDS_PER_INVOCATION = 15_000_000;
private static final long CHECKPOINT_INTERVAL_MS = 100;
public static void main(String[] args)
throws RunnerException {
Options options = new OptionsBuilder()
.verbosity(VerboseMode.NORMAL)
.include(".*" + InputBenchmark.class.getCanonicalName() + ".*")
.build();
new Runner(options).run();
}
@Benchmark
public void mapSink(FlinkEnvironmentContext context) throws Exception {
StreamExecutionEnvironment env = context.env;
env.enableCheckpointing(CHECKPOINT_INTERVAL_MS);
env.setParallelism(1);
DataStreamSource<Long> source = env.addSource(new LongSource(RECORDS_PER_INVOCATION));
source | // Path: src/main/java/org/apache/flink/benchmark/functions/LongSource.java
// public class LongSource extends RichParallelSourceFunction<Long> {
//
// private volatile boolean running = true;
// private long maxValue;
//
// public LongSource(long maxValue) {
// this.maxValue = maxValue;
// }
//
// @Override
// public void run(SourceContext<Long> ctx) throws Exception {
// long counter = 0;
//
// while (running) {
// synchronized (ctx.getCheckpointLock()) {
// ctx.collect(counter);
// counter++;
// if (counter >= maxValue) {
// cancel();
// }
// }
// }
// }
//
// @Override
// public void cancel() {
// running = false;
// }
// }
//
// Path: src/main/java/org/apache/flink/benchmark/functions/MultiplyByTwo.java
// public class MultiplyByTwo implements MapFunction<Long, Long> {
// @Override
// public Long map(Long value) throws Exception {
// return value * 2;
// }
// }
// Path: src/main/java/org/apache/flink/benchmark/InputBenchmark.java
import org.openjdk.jmh.runner.options.VerboseMode;
import org.apache.flink.benchmark.functions.LongSource;
import org.apache.flink.benchmark.functions.MultiplyByTwo;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.apache.flink.streaming.api.functions.sink.DiscardingSink;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.OperationsPerInvocation;
import org.openjdk.jmh.runner.Runner;
import org.openjdk.jmh.runner.RunnerException;
import org.openjdk.jmh.runner.options.Options;
import org.openjdk.jmh.runner.options.OptionsBuilder;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.flink.benchmark;
@OperationsPerInvocation(value = InputBenchmark.RECORDS_PER_INVOCATION)
public class InputBenchmark extends BenchmarkBase {
public static final int RECORDS_PER_INVOCATION = 15_000_000;
private static final long CHECKPOINT_INTERVAL_MS = 100;
public static void main(String[] args)
throws RunnerException {
Options options = new OptionsBuilder()
.verbosity(VerboseMode.NORMAL)
.include(".*" + InputBenchmark.class.getCanonicalName() + ".*")
.build();
new Runner(options).run();
}
@Benchmark
public void mapSink(FlinkEnvironmentContext context) throws Exception {
StreamExecutionEnvironment env = context.env;
env.enableCheckpointing(CHECKPOINT_INTERVAL_MS);
env.setParallelism(1);
DataStreamSource<Long> source = env.addSource(new LongSource(RECORDS_PER_INVOCATION));
source | .map(new MultiplyByTwo()) |
dataArtisans/flink-benchmarks | src/main/java/org/apache/flink/benchmark/functions/IntLongApplications.java | // Path: src/main/java/org/apache/flink/benchmark/CollectSink.java
// public class CollectSink<T> implements SinkFunction<T> {
// public final List<T> result = new ArrayList<>();
//
// @Override
// public void invoke(T value) throws Exception {
// result.add(value);
// }
// }
| import org.apache.flink.benchmark.CollectSink;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.windowing.assigners.WindowAssigner;
import org.apache.flink.streaming.api.windowing.windows.Window; | /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.flink.benchmark.functions;
public class IntLongApplications {
public static <W extends Window> void reduceWithWindow(
DataStreamSource<IntegerLongSource.Record> source,
WindowAssigner<Object, W> windowAssigner) {
source
.map(new MultiplyIntLongByTwo())
.keyBy(record -> record.key)
.window(windowAssigner)
.reduce(new SumReduceIntLong()) | // Path: src/main/java/org/apache/flink/benchmark/CollectSink.java
// public class CollectSink<T> implements SinkFunction<T> {
// public final List<T> result = new ArrayList<>();
//
// @Override
// public void invoke(T value) throws Exception {
// result.add(value);
// }
// }
// Path: src/main/java/org/apache/flink/benchmark/functions/IntLongApplications.java
import org.apache.flink.benchmark.CollectSink;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.windowing.assigners.WindowAssigner;
import org.apache.flink.streaming.api.windowing.windows.Window;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.flink.benchmark.functions;
public class IntLongApplications {
public static <W extends Window> void reduceWithWindow(
DataStreamSource<IntegerLongSource.Record> source,
WindowAssigner<Object, W> windowAssigner) {
source
.map(new MultiplyIntLongByTwo())
.keyBy(record -> record.key)
.window(windowAssigner)
.reduce(new SumReduceIntLong()) | .addSink(new CollectSink()); |
dataArtisans/flink-benchmarks | src/main/java/org/apache/flink/state/benchmark/MapStateBenchmark.java | // Path: src/main/java/org/apache/flink/state/benchmark/StateBenchmarkConstants.java
// static final int mapKeyCount = 10;
//
// Path: src/main/java/org/apache/flink/state/benchmark/StateBenchmarkConstants.java
// static final ArrayList<Long> mapKeys = new ArrayList<>(mapKeyCount);
//
// Path: src/main/java/org/apache/flink/state/benchmark/StateBenchmarkConstants.java
// static final int setupKeyCount = 500_000;
| import org.apache.flink.api.common.state.MapState;
import org.apache.flink.api.common.state.MapStateDescriptor;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.OperationsPerInvocation;
import org.openjdk.jmh.annotations.Setup;
import org.openjdk.jmh.infra.Blackhole;
import org.openjdk.jmh.runner.Runner;
import org.openjdk.jmh.runner.RunnerException;
import org.openjdk.jmh.runner.options.Options;
import org.openjdk.jmh.runner.options.OptionsBuilder;
import org.openjdk.jmh.runner.options.VerboseMode;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.concurrent.atomic.AtomicInteger;
import static org.apache.flink.contrib.streaming.state.benchmark.StateBackendBenchmarkUtils.createKeyedStateBackend;
import static org.apache.flink.contrib.streaming.state.benchmark.StateBackendBenchmarkUtils.getMapState;
import static org.apache.flink.state.benchmark.StateBenchmarkConstants.mapKeyCount;
import static org.apache.flink.state.benchmark.StateBenchmarkConstants.mapKeys;
import static org.apache.flink.state.benchmark.StateBenchmarkConstants.setupKeyCount; | /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.flink.state.benchmark;
/**
* Implementation for map state benchmark testing.
*/
public class MapStateBenchmark extends StateBenchmarkBase {
private MapState<Long, Double> mapState;
private Map<Long, Double> dummyMaps;
public static void main(String[] args) throws RunnerException {
Options opt = new OptionsBuilder()
.verbosity(VerboseMode.NORMAL)
.include(".*" + MapStateBenchmark.class.getCanonicalName() + ".*")
.build();
new Runner(opt).run();
}
@Setup
public void setUp() throws Exception {
keyedStateBackend = createKeyedStateBackend(backendType);
mapState = getMapState(
keyedStateBackend,
new MapStateDescriptor<>("mapState", Long.class, Double.class)); | // Path: src/main/java/org/apache/flink/state/benchmark/StateBenchmarkConstants.java
// static final int mapKeyCount = 10;
//
// Path: src/main/java/org/apache/flink/state/benchmark/StateBenchmarkConstants.java
// static final ArrayList<Long> mapKeys = new ArrayList<>(mapKeyCount);
//
// Path: src/main/java/org/apache/flink/state/benchmark/StateBenchmarkConstants.java
// static final int setupKeyCount = 500_000;
// Path: src/main/java/org/apache/flink/state/benchmark/MapStateBenchmark.java
import org.apache.flink.api.common.state.MapState;
import org.apache.flink.api.common.state.MapStateDescriptor;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.OperationsPerInvocation;
import org.openjdk.jmh.annotations.Setup;
import org.openjdk.jmh.infra.Blackhole;
import org.openjdk.jmh.runner.Runner;
import org.openjdk.jmh.runner.RunnerException;
import org.openjdk.jmh.runner.options.Options;
import org.openjdk.jmh.runner.options.OptionsBuilder;
import org.openjdk.jmh.runner.options.VerboseMode;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.concurrent.atomic.AtomicInteger;
import static org.apache.flink.contrib.streaming.state.benchmark.StateBackendBenchmarkUtils.createKeyedStateBackend;
import static org.apache.flink.contrib.streaming.state.benchmark.StateBackendBenchmarkUtils.getMapState;
import static org.apache.flink.state.benchmark.StateBenchmarkConstants.mapKeyCount;
import static org.apache.flink.state.benchmark.StateBenchmarkConstants.mapKeys;
import static org.apache.flink.state.benchmark.StateBenchmarkConstants.setupKeyCount;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.flink.state.benchmark;
/**
* Implementation for map state benchmark testing.
*/
public class MapStateBenchmark extends StateBenchmarkBase {
private MapState<Long, Double> mapState;
private Map<Long, Double> dummyMaps;
public static void main(String[] args) throws RunnerException {
Options opt = new OptionsBuilder()
.verbosity(VerboseMode.NORMAL)
.include(".*" + MapStateBenchmark.class.getCanonicalName() + ".*")
.build();
new Runner(opt).run();
}
@Setup
public void setUp() throws Exception {
keyedStateBackend = createKeyedStateBackend(backendType);
mapState = getMapState(
keyedStateBackend,
new MapStateDescriptor<>("mapState", Long.class, Double.class)); | dummyMaps = new HashMap<>(mapKeyCount); |
dataArtisans/flink-benchmarks | src/main/java/org/apache/flink/state/benchmark/MapStateBenchmark.java | // Path: src/main/java/org/apache/flink/state/benchmark/StateBenchmarkConstants.java
// static final int mapKeyCount = 10;
//
// Path: src/main/java/org/apache/flink/state/benchmark/StateBenchmarkConstants.java
// static final ArrayList<Long> mapKeys = new ArrayList<>(mapKeyCount);
//
// Path: src/main/java/org/apache/flink/state/benchmark/StateBenchmarkConstants.java
// static final int setupKeyCount = 500_000;
| import org.apache.flink.api.common.state.MapState;
import org.apache.flink.api.common.state.MapStateDescriptor;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.OperationsPerInvocation;
import org.openjdk.jmh.annotations.Setup;
import org.openjdk.jmh.infra.Blackhole;
import org.openjdk.jmh.runner.Runner;
import org.openjdk.jmh.runner.RunnerException;
import org.openjdk.jmh.runner.options.Options;
import org.openjdk.jmh.runner.options.OptionsBuilder;
import org.openjdk.jmh.runner.options.VerboseMode;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.concurrent.atomic.AtomicInteger;
import static org.apache.flink.contrib.streaming.state.benchmark.StateBackendBenchmarkUtils.createKeyedStateBackend;
import static org.apache.flink.contrib.streaming.state.benchmark.StateBackendBenchmarkUtils.getMapState;
import static org.apache.flink.state.benchmark.StateBenchmarkConstants.mapKeyCount;
import static org.apache.flink.state.benchmark.StateBenchmarkConstants.mapKeys;
import static org.apache.flink.state.benchmark.StateBenchmarkConstants.setupKeyCount; | /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.flink.state.benchmark;
/**
* Implementation for map state benchmark testing.
*/
public class MapStateBenchmark extends StateBenchmarkBase {
private MapState<Long, Double> mapState;
private Map<Long, Double> dummyMaps;
public static void main(String[] args) throws RunnerException {
Options opt = new OptionsBuilder()
.verbosity(VerboseMode.NORMAL)
.include(".*" + MapStateBenchmark.class.getCanonicalName() + ".*")
.build();
new Runner(opt).run();
}
@Setup
public void setUp() throws Exception {
keyedStateBackend = createKeyedStateBackend(backendType);
mapState = getMapState(
keyedStateBackend,
new MapStateDescriptor<>("mapState", Long.class, Double.class));
dummyMaps = new HashMap<>(mapKeyCount);
for (int i = 0; i < mapKeyCount; ++i) { | // Path: src/main/java/org/apache/flink/state/benchmark/StateBenchmarkConstants.java
// static final int mapKeyCount = 10;
//
// Path: src/main/java/org/apache/flink/state/benchmark/StateBenchmarkConstants.java
// static final ArrayList<Long> mapKeys = new ArrayList<>(mapKeyCount);
//
// Path: src/main/java/org/apache/flink/state/benchmark/StateBenchmarkConstants.java
// static final int setupKeyCount = 500_000;
// Path: src/main/java/org/apache/flink/state/benchmark/MapStateBenchmark.java
import org.apache.flink.api.common.state.MapState;
import org.apache.flink.api.common.state.MapStateDescriptor;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.OperationsPerInvocation;
import org.openjdk.jmh.annotations.Setup;
import org.openjdk.jmh.infra.Blackhole;
import org.openjdk.jmh.runner.Runner;
import org.openjdk.jmh.runner.RunnerException;
import org.openjdk.jmh.runner.options.Options;
import org.openjdk.jmh.runner.options.OptionsBuilder;
import org.openjdk.jmh.runner.options.VerboseMode;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.concurrent.atomic.AtomicInteger;
import static org.apache.flink.contrib.streaming.state.benchmark.StateBackendBenchmarkUtils.createKeyedStateBackend;
import static org.apache.flink.contrib.streaming.state.benchmark.StateBackendBenchmarkUtils.getMapState;
import static org.apache.flink.state.benchmark.StateBenchmarkConstants.mapKeyCount;
import static org.apache.flink.state.benchmark.StateBenchmarkConstants.mapKeys;
import static org.apache.flink.state.benchmark.StateBenchmarkConstants.setupKeyCount;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.flink.state.benchmark;
/**
* Implementation for map state benchmark testing.
*/
public class MapStateBenchmark extends StateBenchmarkBase {
private MapState<Long, Double> mapState;
private Map<Long, Double> dummyMaps;
public static void main(String[] args) throws RunnerException {
Options opt = new OptionsBuilder()
.verbosity(VerboseMode.NORMAL)
.include(".*" + MapStateBenchmark.class.getCanonicalName() + ".*")
.build();
new Runner(opt).run();
}
@Setup
public void setUp() throws Exception {
keyedStateBackend = createKeyedStateBackend(backendType);
mapState = getMapState(
keyedStateBackend,
new MapStateDescriptor<>("mapState", Long.class, Double.class));
dummyMaps = new HashMap<>(mapKeyCount);
for (int i = 0; i < mapKeyCount; ++i) { | dummyMaps.put(mapKeys.get(i), random.nextDouble()); |
dataArtisans/flink-benchmarks | src/main/java/org/apache/flink/state/benchmark/MapStateBenchmark.java | // Path: src/main/java/org/apache/flink/state/benchmark/StateBenchmarkConstants.java
// static final int mapKeyCount = 10;
//
// Path: src/main/java/org/apache/flink/state/benchmark/StateBenchmarkConstants.java
// static final ArrayList<Long> mapKeys = new ArrayList<>(mapKeyCount);
//
// Path: src/main/java/org/apache/flink/state/benchmark/StateBenchmarkConstants.java
// static final int setupKeyCount = 500_000;
| import org.apache.flink.api.common.state.MapState;
import org.apache.flink.api.common.state.MapStateDescriptor;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.OperationsPerInvocation;
import org.openjdk.jmh.annotations.Setup;
import org.openjdk.jmh.infra.Blackhole;
import org.openjdk.jmh.runner.Runner;
import org.openjdk.jmh.runner.RunnerException;
import org.openjdk.jmh.runner.options.Options;
import org.openjdk.jmh.runner.options.OptionsBuilder;
import org.openjdk.jmh.runner.options.VerboseMode;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.concurrent.atomic.AtomicInteger;
import static org.apache.flink.contrib.streaming.state.benchmark.StateBackendBenchmarkUtils.createKeyedStateBackend;
import static org.apache.flink.contrib.streaming.state.benchmark.StateBackendBenchmarkUtils.getMapState;
import static org.apache.flink.state.benchmark.StateBenchmarkConstants.mapKeyCount;
import static org.apache.flink.state.benchmark.StateBenchmarkConstants.mapKeys;
import static org.apache.flink.state.benchmark.StateBenchmarkConstants.setupKeyCount; | /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.flink.state.benchmark;
/**
* Implementation for map state benchmark testing.
*/
public class MapStateBenchmark extends StateBenchmarkBase {
private MapState<Long, Double> mapState;
private Map<Long, Double> dummyMaps;
public static void main(String[] args) throws RunnerException {
Options opt = new OptionsBuilder()
.verbosity(VerboseMode.NORMAL)
.include(".*" + MapStateBenchmark.class.getCanonicalName() + ".*")
.build();
new Runner(opt).run();
}
@Setup
public void setUp() throws Exception {
keyedStateBackend = createKeyedStateBackend(backendType);
mapState = getMapState(
keyedStateBackend,
new MapStateDescriptor<>("mapState", Long.class, Double.class));
dummyMaps = new HashMap<>(mapKeyCount);
for (int i = 0; i < mapKeyCount; ++i) {
dummyMaps.put(mapKeys.get(i), random.nextDouble());
} | // Path: src/main/java/org/apache/flink/state/benchmark/StateBenchmarkConstants.java
// static final int mapKeyCount = 10;
//
// Path: src/main/java/org/apache/flink/state/benchmark/StateBenchmarkConstants.java
// static final ArrayList<Long> mapKeys = new ArrayList<>(mapKeyCount);
//
// Path: src/main/java/org/apache/flink/state/benchmark/StateBenchmarkConstants.java
// static final int setupKeyCount = 500_000;
// Path: src/main/java/org/apache/flink/state/benchmark/MapStateBenchmark.java
import org.apache.flink.api.common.state.MapState;
import org.apache.flink.api.common.state.MapStateDescriptor;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.OperationsPerInvocation;
import org.openjdk.jmh.annotations.Setup;
import org.openjdk.jmh.infra.Blackhole;
import org.openjdk.jmh.runner.Runner;
import org.openjdk.jmh.runner.RunnerException;
import org.openjdk.jmh.runner.options.Options;
import org.openjdk.jmh.runner.options.OptionsBuilder;
import org.openjdk.jmh.runner.options.VerboseMode;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.concurrent.atomic.AtomicInteger;
import static org.apache.flink.contrib.streaming.state.benchmark.StateBackendBenchmarkUtils.createKeyedStateBackend;
import static org.apache.flink.contrib.streaming.state.benchmark.StateBackendBenchmarkUtils.getMapState;
import static org.apache.flink.state.benchmark.StateBenchmarkConstants.mapKeyCount;
import static org.apache.flink.state.benchmark.StateBenchmarkConstants.mapKeys;
import static org.apache.flink.state.benchmark.StateBenchmarkConstants.setupKeyCount;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.flink.state.benchmark;
/**
* Implementation for map state benchmark testing.
*/
public class MapStateBenchmark extends StateBenchmarkBase {
private MapState<Long, Double> mapState;
private Map<Long, Double> dummyMaps;
public static void main(String[] args) throws RunnerException {
Options opt = new OptionsBuilder()
.verbosity(VerboseMode.NORMAL)
.include(".*" + MapStateBenchmark.class.getCanonicalName() + ".*")
.build();
new Runner(opt).run();
}
@Setup
public void setUp() throws Exception {
keyedStateBackend = createKeyedStateBackend(backendType);
mapState = getMapState(
keyedStateBackend,
new MapStateDescriptor<>("mapState", Long.class, Double.class));
dummyMaps = new HashMap<>(mapKeyCount);
for (int i = 0; i < mapKeyCount; ++i) {
dummyMaps.put(mapKeys.get(i), random.nextDouble());
} | for (int i = 0; i < setupKeyCount; ++i) { |
dataArtisans/flink-benchmarks | src/main/java/org/apache/flink/benchmark/WindowBenchmarks.java | // Path: src/main/java/org/apache/flink/benchmark/functions/IntLongApplications.java
// public class IntLongApplications {
// public static <W extends Window> void reduceWithWindow(
// DataStreamSource<IntegerLongSource.Record> source,
// WindowAssigner<Object, W> windowAssigner) {
// source
// .map(new MultiplyIntLongByTwo())
// .keyBy(record -> record.key)
// .window(windowAssigner)
// .reduce(new SumReduceIntLong())
// .addSink(new CollectSink());
// }
// }
//
// Path: src/main/java/org/apache/flink/benchmark/functions/IntegerLongSource.java
// public class IntegerLongSource extends RichParallelSourceFunction<IntegerLongSource.Record> {
// public static final class Record {
// public final int key;
// public final long value;
//
// public Record() {
// this(0, 0);
// }
//
// public Record(int key, long value) {
// this.key = key;
// this.value = value;
// }
//
// public static Record of(int key, long value) {
// return new Record(key, value);
// }
//
// public int getKey() {
// return key;
// }
//
// @Override
// public String toString() {
// return String.format("(%s, %s)", key, value);
// }
// }
//
// private volatile boolean running = true;
// private int numberOfKeys;
// private long numberOfElements;
//
// public IntegerLongSource(int numberOfKeys, long numberOfElements) {
// this.numberOfKeys = numberOfKeys;
// this.numberOfElements = numberOfElements;
// }
//
// @Override
// public void run(SourceContext<Record> ctx) throws Exception {
// long counter = 0;
//
// while (running && counter < numberOfElements) {
// synchronized (ctx.getCheckpointLock()) {
// ctx.collectWithTimestamp(Record.of((int) (counter % numberOfKeys), counter), counter);
// counter++;
// }
// }
// running = false;
// }
//
// @Override
// public void cancel() {
// running = false;
// }
// }
| import org.openjdk.jmh.annotations.Setup;
import org.openjdk.jmh.runner.Runner;
import org.openjdk.jmh.runner.RunnerException;
import org.openjdk.jmh.runner.options.Options;
import org.openjdk.jmh.runner.options.OptionsBuilder;
import org.openjdk.jmh.runner.options.VerboseMode;
import java.io.IOException;
import org.apache.flink.benchmark.functions.IntLongApplications;
import org.apache.flink.benchmark.functions.IntegerLongSource;
import org.apache.flink.streaming.api.TimeCharacteristic;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.windowing.assigners.EventTimeSessionWindows;
import org.apache.flink.streaming.api.windowing.assigners.GlobalWindows;
import org.apache.flink.streaming.api.windowing.assigners.SlidingEventTimeWindows;
import org.apache.flink.streaming.api.windowing.assigners.TumblingEventTimeWindows;
import org.apache.flink.streaming.api.windowing.time.Time;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.OperationsPerInvocation; | /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.flink.benchmark;
@OperationsPerInvocation(value = WindowBenchmarks.RECORDS_PER_INVOCATION)
public class WindowBenchmarks extends BenchmarkBase {
public static final int RECORDS_PER_INVOCATION = 7_000_000;
public static void main(String[] args)
throws RunnerException {
Options options = new OptionsBuilder()
.verbosity(VerboseMode.NORMAL)
.include(".*" + WindowBenchmarks.class.getCanonicalName() + ".*")
.build();
new Runner(options).run();
}
@Benchmark
public void globalWindow(TimeWindowContext context) throws Exception { | // Path: src/main/java/org/apache/flink/benchmark/functions/IntLongApplications.java
// public class IntLongApplications {
// public static <W extends Window> void reduceWithWindow(
// DataStreamSource<IntegerLongSource.Record> source,
// WindowAssigner<Object, W> windowAssigner) {
// source
// .map(new MultiplyIntLongByTwo())
// .keyBy(record -> record.key)
// .window(windowAssigner)
// .reduce(new SumReduceIntLong())
// .addSink(new CollectSink());
// }
// }
//
// Path: src/main/java/org/apache/flink/benchmark/functions/IntegerLongSource.java
// public class IntegerLongSource extends RichParallelSourceFunction<IntegerLongSource.Record> {
// public static final class Record {
// public final int key;
// public final long value;
//
// public Record() {
// this(0, 0);
// }
//
// public Record(int key, long value) {
// this.key = key;
// this.value = value;
// }
//
// public static Record of(int key, long value) {
// return new Record(key, value);
// }
//
// public int getKey() {
// return key;
// }
//
// @Override
// public String toString() {
// return String.format("(%s, %s)", key, value);
// }
// }
//
// private volatile boolean running = true;
// private int numberOfKeys;
// private long numberOfElements;
//
// public IntegerLongSource(int numberOfKeys, long numberOfElements) {
// this.numberOfKeys = numberOfKeys;
// this.numberOfElements = numberOfElements;
// }
//
// @Override
// public void run(SourceContext<Record> ctx) throws Exception {
// long counter = 0;
//
// while (running && counter < numberOfElements) {
// synchronized (ctx.getCheckpointLock()) {
// ctx.collectWithTimestamp(Record.of((int) (counter % numberOfKeys), counter), counter);
// counter++;
// }
// }
// running = false;
// }
//
// @Override
// public void cancel() {
// running = false;
// }
// }
// Path: src/main/java/org/apache/flink/benchmark/WindowBenchmarks.java
import org.openjdk.jmh.annotations.Setup;
import org.openjdk.jmh.runner.Runner;
import org.openjdk.jmh.runner.RunnerException;
import org.openjdk.jmh.runner.options.Options;
import org.openjdk.jmh.runner.options.OptionsBuilder;
import org.openjdk.jmh.runner.options.VerboseMode;
import java.io.IOException;
import org.apache.flink.benchmark.functions.IntLongApplications;
import org.apache.flink.benchmark.functions.IntegerLongSource;
import org.apache.flink.streaming.api.TimeCharacteristic;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.windowing.assigners.EventTimeSessionWindows;
import org.apache.flink.streaming.api.windowing.assigners.GlobalWindows;
import org.apache.flink.streaming.api.windowing.assigners.SlidingEventTimeWindows;
import org.apache.flink.streaming.api.windowing.assigners.TumblingEventTimeWindows;
import org.apache.flink.streaming.api.windowing.time.Time;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.OperationsPerInvocation;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.flink.benchmark;
@OperationsPerInvocation(value = WindowBenchmarks.RECORDS_PER_INVOCATION)
public class WindowBenchmarks extends BenchmarkBase {
public static final int RECORDS_PER_INVOCATION = 7_000_000;
public static void main(String[] args)
throws RunnerException {
Options options = new OptionsBuilder()
.verbosity(VerboseMode.NORMAL)
.include(".*" + WindowBenchmarks.class.getCanonicalName() + ".*")
.build();
new Runner(options).run();
}
@Benchmark
public void globalWindow(TimeWindowContext context) throws Exception { | IntLongApplications.reduceWithWindow(context.source, GlobalWindows.create()); |
dataArtisans/flink-benchmarks | src/main/java/org/apache/flink/benchmark/WindowBenchmarks.java | // Path: src/main/java/org/apache/flink/benchmark/functions/IntLongApplications.java
// public class IntLongApplications {
// public static <W extends Window> void reduceWithWindow(
// DataStreamSource<IntegerLongSource.Record> source,
// WindowAssigner<Object, W> windowAssigner) {
// source
// .map(new MultiplyIntLongByTwo())
// .keyBy(record -> record.key)
// .window(windowAssigner)
// .reduce(new SumReduceIntLong())
// .addSink(new CollectSink());
// }
// }
//
// Path: src/main/java/org/apache/flink/benchmark/functions/IntegerLongSource.java
// public class IntegerLongSource extends RichParallelSourceFunction<IntegerLongSource.Record> {
// public static final class Record {
// public final int key;
// public final long value;
//
// public Record() {
// this(0, 0);
// }
//
// public Record(int key, long value) {
// this.key = key;
// this.value = value;
// }
//
// public static Record of(int key, long value) {
// return new Record(key, value);
// }
//
// public int getKey() {
// return key;
// }
//
// @Override
// public String toString() {
// return String.format("(%s, %s)", key, value);
// }
// }
//
// private volatile boolean running = true;
// private int numberOfKeys;
// private long numberOfElements;
//
// public IntegerLongSource(int numberOfKeys, long numberOfElements) {
// this.numberOfKeys = numberOfKeys;
// this.numberOfElements = numberOfElements;
// }
//
// @Override
// public void run(SourceContext<Record> ctx) throws Exception {
// long counter = 0;
//
// while (running && counter < numberOfElements) {
// synchronized (ctx.getCheckpointLock()) {
// ctx.collectWithTimestamp(Record.of((int) (counter % numberOfKeys), counter), counter);
// counter++;
// }
// }
// running = false;
// }
//
// @Override
// public void cancel() {
// running = false;
// }
// }
| import org.openjdk.jmh.annotations.Setup;
import org.openjdk.jmh.runner.Runner;
import org.openjdk.jmh.runner.RunnerException;
import org.openjdk.jmh.runner.options.Options;
import org.openjdk.jmh.runner.options.OptionsBuilder;
import org.openjdk.jmh.runner.options.VerboseMode;
import java.io.IOException;
import org.apache.flink.benchmark.functions.IntLongApplications;
import org.apache.flink.benchmark.functions.IntegerLongSource;
import org.apache.flink.streaming.api.TimeCharacteristic;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.windowing.assigners.EventTimeSessionWindows;
import org.apache.flink.streaming.api.windowing.assigners.GlobalWindows;
import org.apache.flink.streaming.api.windowing.assigners.SlidingEventTimeWindows;
import org.apache.flink.streaming.api.windowing.assigners.TumblingEventTimeWindows;
import org.apache.flink.streaming.api.windowing.time.Time;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.OperationsPerInvocation; | new Runner(options).run();
}
@Benchmark
public void globalWindow(TimeWindowContext context) throws Exception {
IntLongApplications.reduceWithWindow(context.source, GlobalWindows.create());
context.execute();
}
@Benchmark
public void tumblingWindow(TimeWindowContext context) throws Exception {
IntLongApplications.reduceWithWindow(context.source, TumblingEventTimeWindows.of(Time.seconds(10_000)));
context.execute();
}
@Benchmark
public void slidingWindow(TimeWindowContext context) throws Exception {
IntLongApplications.reduceWithWindow(context.source, SlidingEventTimeWindows.of(Time.seconds(10_000), Time.seconds(1000)));
context.execute();
}
@Benchmark
public void sessionWindow(TimeWindowContext context) throws Exception {
IntLongApplications.reduceWithWindow(context.source, EventTimeSessionWindows.withGap(Time.seconds(500)));
context.execute();
}
public static class TimeWindowContext extends FlinkEnvironmentContext {
public final int numberOfElements = 1000;
| // Path: src/main/java/org/apache/flink/benchmark/functions/IntLongApplications.java
// public class IntLongApplications {
// public static <W extends Window> void reduceWithWindow(
// DataStreamSource<IntegerLongSource.Record> source,
// WindowAssigner<Object, W> windowAssigner) {
// source
// .map(new MultiplyIntLongByTwo())
// .keyBy(record -> record.key)
// .window(windowAssigner)
// .reduce(new SumReduceIntLong())
// .addSink(new CollectSink());
// }
// }
//
// Path: src/main/java/org/apache/flink/benchmark/functions/IntegerLongSource.java
// public class IntegerLongSource extends RichParallelSourceFunction<IntegerLongSource.Record> {
// public static final class Record {
// public final int key;
// public final long value;
//
// public Record() {
// this(0, 0);
// }
//
// public Record(int key, long value) {
// this.key = key;
// this.value = value;
// }
//
// public static Record of(int key, long value) {
// return new Record(key, value);
// }
//
// public int getKey() {
// return key;
// }
//
// @Override
// public String toString() {
// return String.format("(%s, %s)", key, value);
// }
// }
//
// private volatile boolean running = true;
// private int numberOfKeys;
// private long numberOfElements;
//
// public IntegerLongSource(int numberOfKeys, long numberOfElements) {
// this.numberOfKeys = numberOfKeys;
// this.numberOfElements = numberOfElements;
// }
//
// @Override
// public void run(SourceContext<Record> ctx) throws Exception {
// long counter = 0;
//
// while (running && counter < numberOfElements) {
// synchronized (ctx.getCheckpointLock()) {
// ctx.collectWithTimestamp(Record.of((int) (counter % numberOfKeys), counter), counter);
// counter++;
// }
// }
// running = false;
// }
//
// @Override
// public void cancel() {
// running = false;
// }
// }
// Path: src/main/java/org/apache/flink/benchmark/WindowBenchmarks.java
import org.openjdk.jmh.annotations.Setup;
import org.openjdk.jmh.runner.Runner;
import org.openjdk.jmh.runner.RunnerException;
import org.openjdk.jmh.runner.options.Options;
import org.openjdk.jmh.runner.options.OptionsBuilder;
import org.openjdk.jmh.runner.options.VerboseMode;
import java.io.IOException;
import org.apache.flink.benchmark.functions.IntLongApplications;
import org.apache.flink.benchmark.functions.IntegerLongSource;
import org.apache.flink.streaming.api.TimeCharacteristic;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.windowing.assigners.EventTimeSessionWindows;
import org.apache.flink.streaming.api.windowing.assigners.GlobalWindows;
import org.apache.flink.streaming.api.windowing.assigners.SlidingEventTimeWindows;
import org.apache.flink.streaming.api.windowing.assigners.TumblingEventTimeWindows;
import org.apache.flink.streaming.api.windowing.time.Time;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.OperationsPerInvocation;
new Runner(options).run();
}
@Benchmark
public void globalWindow(TimeWindowContext context) throws Exception {
IntLongApplications.reduceWithWindow(context.source, GlobalWindows.create());
context.execute();
}
@Benchmark
public void tumblingWindow(TimeWindowContext context) throws Exception {
IntLongApplications.reduceWithWindow(context.source, TumblingEventTimeWindows.of(Time.seconds(10_000)));
context.execute();
}
@Benchmark
public void slidingWindow(TimeWindowContext context) throws Exception {
IntLongApplications.reduceWithWindow(context.source, SlidingEventTimeWindows.of(Time.seconds(10_000), Time.seconds(1000)));
context.execute();
}
@Benchmark
public void sessionWindow(TimeWindowContext context) throws Exception {
IntLongApplications.reduceWithWindow(context.source, EventTimeSessionWindows.withGap(Time.seconds(500)));
context.execute();
}
public static class TimeWindowContext extends FlinkEnvironmentContext {
public final int numberOfElements = 1000;
| public DataStreamSource<IntegerLongSource.Record> source; |
dataArtisans/flink-benchmarks | src/main/java/org/apache/flink/state/benchmark/ValueStateBenchmark.java | // Path: src/main/java/org/apache/flink/state/benchmark/StateBenchmarkConstants.java
// static final int setupKeyCount = 500_000;
| import java.util.concurrent.atomic.AtomicInteger;
import static org.apache.flink.contrib.streaming.state.benchmark.StateBackendBenchmarkUtils.createKeyedStateBackend;
import static org.apache.flink.contrib.streaming.state.benchmark.StateBackendBenchmarkUtils.getValueState;
import static org.apache.flink.state.benchmark.StateBenchmarkConstants.setupKeyCount;
import org.apache.flink.api.common.state.ValueState;
import org.apache.flink.api.common.state.ValueStateDescriptor;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.Setup;
import org.openjdk.jmh.runner.Runner;
import org.openjdk.jmh.runner.RunnerException;
import org.openjdk.jmh.runner.options.Options;
import org.openjdk.jmh.runner.options.OptionsBuilder;
import org.openjdk.jmh.runner.options.VerboseMode;
import java.io.IOException; | /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.flink.state.benchmark;
/**
* Implementation for listValue state benchmark testing.
*/
public class ValueStateBenchmark extends StateBenchmarkBase {
private ValueState<Long> valueState;
public static void main(String[] args) throws RunnerException {
Options opt = new OptionsBuilder()
.verbosity(VerboseMode.NORMAL)
.include(".*" + ValueStateBenchmark.class.getCanonicalName() + ".*")
.build();
new Runner(opt).run();
}
@Setup
public void setUp() throws Exception {
keyedStateBackend = createKeyedStateBackend(backendType);
valueState = getValueState(
keyedStateBackend,
new ValueStateDescriptor<>("kvState", Long.class)); | // Path: src/main/java/org/apache/flink/state/benchmark/StateBenchmarkConstants.java
// static final int setupKeyCount = 500_000;
// Path: src/main/java/org/apache/flink/state/benchmark/ValueStateBenchmark.java
import java.util.concurrent.atomic.AtomicInteger;
import static org.apache.flink.contrib.streaming.state.benchmark.StateBackendBenchmarkUtils.createKeyedStateBackend;
import static org.apache.flink.contrib.streaming.state.benchmark.StateBackendBenchmarkUtils.getValueState;
import static org.apache.flink.state.benchmark.StateBenchmarkConstants.setupKeyCount;
import org.apache.flink.api.common.state.ValueState;
import org.apache.flink.api.common.state.ValueStateDescriptor;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.Setup;
import org.openjdk.jmh.runner.Runner;
import org.openjdk.jmh.runner.RunnerException;
import org.openjdk.jmh.runner.options.Options;
import org.openjdk.jmh.runner.options.OptionsBuilder;
import org.openjdk.jmh.runner.options.VerboseMode;
import java.io.IOException;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.flink.state.benchmark;
/**
* Implementation for listValue state benchmark testing.
*/
public class ValueStateBenchmark extends StateBenchmarkBase {
private ValueState<Long> valueState;
public static void main(String[] args) throws RunnerException {
Options opt = new OptionsBuilder()
.verbosity(VerboseMode.NORMAL)
.include(".*" + ValueStateBenchmark.class.getCanonicalName() + ".*")
.build();
new Runner(opt).run();
}
@Setup
public void setUp() throws Exception {
keyedStateBackend = createKeyedStateBackend(backendType);
valueState = getValueState(
keyedStateBackend,
new ValueStateDescriptor<>("kvState", Long.class)); | for (int i = 0; i < setupKeyCount; ++i) { |
dataArtisans/flink-benchmarks | src/main/java/org/apache/flink/benchmark/MemoryStateBackendBenchmark.java | // Path: src/main/java/org/apache/flink/benchmark/functions/IntLongApplications.java
// public class IntLongApplications {
// public static <W extends Window> void reduceWithWindow(
// DataStreamSource<IntegerLongSource.Record> source,
// WindowAssigner<Object, W> windowAssigner) {
// source
// .map(new MultiplyIntLongByTwo())
// .keyBy(record -> record.key)
// .window(windowAssigner)
// .reduce(new SumReduceIntLong())
// .addSink(new CollectSink());
// }
// }
| import org.openjdk.jmh.runner.options.Options;
import org.openjdk.jmh.runner.options.OptionsBuilder;
import org.openjdk.jmh.runner.options.VerboseMode;
import java.io.IOException;
import static org.openjdk.jmh.annotations.Scope.Thread;
import org.apache.flink.benchmark.functions.IntLongApplications;
import org.apache.flink.streaming.api.windowing.assigners.TumblingEventTimeWindows;
import org.apache.flink.streaming.api.windowing.time.Time;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.OperationsPerInvocation;
import org.openjdk.jmh.annotations.Param;
import org.openjdk.jmh.annotations.Setup;
import org.openjdk.jmh.annotations.State;
import org.openjdk.jmh.annotations.TearDown;
import org.openjdk.jmh.runner.Runner;
import org.openjdk.jmh.runner.RunnerException; | /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.flink.benchmark;
@OperationsPerInvocation(value = MemoryStateBackendBenchmark.RECORDS_PER_INVOCATION)
public class MemoryStateBackendBenchmark extends StateBackendBenchmarkBase {
public static final int RECORDS_PER_INVOCATION = 7_000_000;
public static void main(String[] args)
throws RunnerException {
Options options = new OptionsBuilder()
.verbosity(VerboseMode.NORMAL)
.include(".*" + MemoryStateBackendBenchmark.class.getCanonicalName() + ".*")
.build();
new Runner(options).run();
}
@Benchmark
public void stateBackends(MemoryStateBackendContext context) throws Exception { | // Path: src/main/java/org/apache/flink/benchmark/functions/IntLongApplications.java
// public class IntLongApplications {
// public static <W extends Window> void reduceWithWindow(
// DataStreamSource<IntegerLongSource.Record> source,
// WindowAssigner<Object, W> windowAssigner) {
// source
// .map(new MultiplyIntLongByTwo())
// .keyBy(record -> record.key)
// .window(windowAssigner)
// .reduce(new SumReduceIntLong())
// .addSink(new CollectSink());
// }
// }
// Path: src/main/java/org/apache/flink/benchmark/MemoryStateBackendBenchmark.java
import org.openjdk.jmh.runner.options.Options;
import org.openjdk.jmh.runner.options.OptionsBuilder;
import org.openjdk.jmh.runner.options.VerboseMode;
import java.io.IOException;
import static org.openjdk.jmh.annotations.Scope.Thread;
import org.apache.flink.benchmark.functions.IntLongApplications;
import org.apache.flink.streaming.api.windowing.assigners.TumblingEventTimeWindows;
import org.apache.flink.streaming.api.windowing.time.Time;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.OperationsPerInvocation;
import org.openjdk.jmh.annotations.Param;
import org.openjdk.jmh.annotations.Setup;
import org.openjdk.jmh.annotations.State;
import org.openjdk.jmh.annotations.TearDown;
import org.openjdk.jmh.runner.Runner;
import org.openjdk.jmh.runner.RunnerException;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.flink.benchmark;
@OperationsPerInvocation(value = MemoryStateBackendBenchmark.RECORDS_PER_INVOCATION)
public class MemoryStateBackendBenchmark extends StateBackendBenchmarkBase {
public static final int RECORDS_PER_INVOCATION = 7_000_000;
public static void main(String[] args)
throws RunnerException {
Options options = new OptionsBuilder()
.verbosity(VerboseMode.NORMAL)
.include(".*" + MemoryStateBackendBenchmark.class.getCanonicalName() + ".*")
.build();
new Runner(options).run();
}
@Benchmark
public void stateBackends(MemoryStateBackendContext context) throws Exception { | IntLongApplications.reduceWithWindow(context.source, TumblingEventTimeWindows.of(Time.seconds(10_000))); |
dataArtisans/flink-benchmarks | src/main/java/org/apache/flink/benchmark/RemoteChannelThroughputBenchmark.java | // Path: src/main/java/org/apache/flink/benchmark/functions/LongSource.java
// public class LongSource extends RichParallelSourceFunction<Long> {
//
// private volatile boolean running = true;
// private long maxValue;
//
// public LongSource(long maxValue) {
// this.maxValue = maxValue;
// }
//
// @Override
// public void run(SourceContext<Long> ctx) throws Exception {
// long counter = 0;
//
// while (running) {
// synchronized (ctx.getCheckpointLock()) {
// ctx.collect(counter);
// counter++;
// if (counter >= maxValue) {
// cancel();
// }
// }
// }
// }
//
// @Override
// public void cancel() {
// running = false;
// }
// }
| import org.openjdk.jmh.annotations.TearDown;
import org.openjdk.jmh.runner.Runner;
import org.openjdk.jmh.runner.RunnerException;
import org.openjdk.jmh.runner.options.Options;
import org.openjdk.jmh.runner.options.OptionsBuilder;
import org.openjdk.jmh.runner.options.VerboseMode;
import org.apache.flink.api.common.functions.MapFunction;
import org.apache.flink.benchmark.functions.LongSource;
import org.apache.flink.runtime.minicluster.MiniCluster;
import org.apache.flink.runtime.minicluster.MiniClusterConfiguration;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.apache.flink.streaming.api.functions.sink.DiscardingSink;
import org.apache.flink.streaming.api.graph.StreamingJobGraphGenerator;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.OperationsPerInvocation;
import org.openjdk.jmh.annotations.Setup; | .verbosity(VerboseMode.NORMAL)
.include(RemoteChannelThroughputBenchmark.class.getCanonicalName())
.build();
new Runner(options).run();
}
@Setup
public void setUp() throws Exception {
MiniClusterConfiguration miniClusterConfiguration = new MiniClusterConfiguration.Builder()
.setNumTaskManagers(NUM_VERTICES * PARALLELISM)
.setNumSlotsPerTaskManager(1)
.build();
miniCluster = new MiniCluster(miniClusterConfiguration);
miniCluster.start();
}
@TearDown
public void tearDown() throws Exception {
if (miniCluster != null) {
miniCluster.close();
}
}
@Benchmark
public void remoteRebalance(FlinkEnvironmentContext context) throws Exception {
StreamExecutionEnvironment env = context.env;
env.enableCheckpointing(CHECKPOINT_INTERVAL_MS);
env.setParallelism(PARALLELISM);
| // Path: src/main/java/org/apache/flink/benchmark/functions/LongSource.java
// public class LongSource extends RichParallelSourceFunction<Long> {
//
// private volatile boolean running = true;
// private long maxValue;
//
// public LongSource(long maxValue) {
// this.maxValue = maxValue;
// }
//
// @Override
// public void run(SourceContext<Long> ctx) throws Exception {
// long counter = 0;
//
// while (running) {
// synchronized (ctx.getCheckpointLock()) {
// ctx.collect(counter);
// counter++;
// if (counter >= maxValue) {
// cancel();
// }
// }
// }
// }
//
// @Override
// public void cancel() {
// running = false;
// }
// }
// Path: src/main/java/org/apache/flink/benchmark/RemoteChannelThroughputBenchmark.java
import org.openjdk.jmh.annotations.TearDown;
import org.openjdk.jmh.runner.Runner;
import org.openjdk.jmh.runner.RunnerException;
import org.openjdk.jmh.runner.options.Options;
import org.openjdk.jmh.runner.options.OptionsBuilder;
import org.openjdk.jmh.runner.options.VerboseMode;
import org.apache.flink.api.common.functions.MapFunction;
import org.apache.flink.benchmark.functions.LongSource;
import org.apache.flink.runtime.minicluster.MiniCluster;
import org.apache.flink.runtime.minicluster.MiniClusterConfiguration;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.apache.flink.streaming.api.functions.sink.DiscardingSink;
import org.apache.flink.streaming.api.graph.StreamingJobGraphGenerator;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.OperationsPerInvocation;
import org.openjdk.jmh.annotations.Setup;
.verbosity(VerboseMode.NORMAL)
.include(RemoteChannelThroughputBenchmark.class.getCanonicalName())
.build();
new Runner(options).run();
}
@Setup
public void setUp() throws Exception {
MiniClusterConfiguration miniClusterConfiguration = new MiniClusterConfiguration.Builder()
.setNumTaskManagers(NUM_VERTICES * PARALLELISM)
.setNumSlotsPerTaskManager(1)
.build();
miniCluster = new MiniCluster(miniClusterConfiguration);
miniCluster.start();
}
@TearDown
public void tearDown() throws Exception {
if (miniCluster != null) {
miniCluster.close();
}
}
@Benchmark
public void remoteRebalance(FlinkEnvironmentContext context) throws Exception {
StreamExecutionEnvironment env = context.env;
env.enableCheckpointing(CHECKPOINT_INTERVAL_MS);
env.setParallelism(PARALLELISM);
| DataStreamSource<Long> source = env.addSource(new LongSource(RECORDS_PER_SUBTASK)); |
dataArtisans/flink-benchmarks | src/main/java/org/apache/flink/benchmark/BlockingPartitionBenchmark.java | // Path: src/main/java/org/apache/flink/benchmark/functions/LongSource.java
// public class LongSource extends RichParallelSourceFunction<Long> {
//
// private volatile boolean running = true;
// private long maxValue;
//
// public LongSource(long maxValue) {
// this.maxValue = maxValue;
// }
//
// @Override
// public void run(SourceContext<Long> ctx) throws Exception {
// long counter = 0;
//
// while (running) {
// synchronized (ctx.getCheckpointLock()) {
// ctx.collect(counter);
// counter++;
// if (counter >= maxValue) {
// cancel();
// }
// }
// }
// }
//
// @Override
// public void cancel() {
// running = false;
// }
// }
| import org.apache.flink.benchmark.functions.LongSource;
import org.apache.flink.configuration.Configuration;
import org.apache.flink.configuration.CoreOptions;
import org.apache.flink.configuration.NettyShuffleEnvironmentOptions;
import org.apache.flink.runtime.jobgraph.ScheduleMode;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.apache.flink.streaming.api.functions.sink.DiscardingSink;
import org.apache.flink.streaming.api.graph.GlobalDataExchangeMode;
import org.apache.flink.streaming.api.graph.StreamGraph;
import org.apache.flink.util.FileUtils;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.OperationsPerInvocation;
import org.openjdk.jmh.annotations.Setup;
import org.openjdk.jmh.runner.Runner;
import org.openjdk.jmh.runner.RunnerException;
import org.openjdk.jmh.runner.options.Options;
import org.openjdk.jmh.runner.options.OptionsBuilder;
import org.openjdk.jmh.runner.options.VerboseMode;
import java.io.IOException; | /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.flink.benchmark;
/**
* JMH throughput benchmark runner.
*/
@OperationsPerInvocation(value = BlockingPartitionBenchmark.RECORDS_PER_INVOCATION)
public class BlockingPartitionBenchmark extends BenchmarkBase {
public static final int RECORDS_PER_INVOCATION = 15_000_000;
public static void main(String[] args)
throws RunnerException {
Options options = new OptionsBuilder()
.verbosity(VerboseMode.NORMAL)
.include(".*" + BlockingPartitionBenchmark.class.getCanonicalName() + ".*")
.build();
new Runner(options).run();
}
@Benchmark
public void uncompressedFilePartition(UncompressedFileEnvironmentContext context) throws Exception {
executeBenchmark(context.env);
}
@Benchmark
public void compressedFilePartition(CompressedFileEnvironmentContext context) throws Exception {
executeBenchmark(context.env);
}
@Benchmark
public void uncompressedMmapPartition(UncompressedMmapEnvironmentContext context) throws Exception {
executeBenchmark(context.env);
}
private void executeBenchmark(StreamExecutionEnvironment env) throws Exception { | // Path: src/main/java/org/apache/flink/benchmark/functions/LongSource.java
// public class LongSource extends RichParallelSourceFunction<Long> {
//
// private volatile boolean running = true;
// private long maxValue;
//
// public LongSource(long maxValue) {
// this.maxValue = maxValue;
// }
//
// @Override
// public void run(SourceContext<Long> ctx) throws Exception {
// long counter = 0;
//
// while (running) {
// synchronized (ctx.getCheckpointLock()) {
// ctx.collect(counter);
// counter++;
// if (counter >= maxValue) {
// cancel();
// }
// }
// }
// }
//
// @Override
// public void cancel() {
// running = false;
// }
// }
// Path: src/main/java/org/apache/flink/benchmark/BlockingPartitionBenchmark.java
import org.apache.flink.benchmark.functions.LongSource;
import org.apache.flink.configuration.Configuration;
import org.apache.flink.configuration.CoreOptions;
import org.apache.flink.configuration.NettyShuffleEnvironmentOptions;
import org.apache.flink.runtime.jobgraph.ScheduleMode;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.apache.flink.streaming.api.functions.sink.DiscardingSink;
import org.apache.flink.streaming.api.graph.GlobalDataExchangeMode;
import org.apache.flink.streaming.api.graph.StreamGraph;
import org.apache.flink.util.FileUtils;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.OperationsPerInvocation;
import org.openjdk.jmh.annotations.Setup;
import org.openjdk.jmh.runner.Runner;
import org.openjdk.jmh.runner.RunnerException;
import org.openjdk.jmh.runner.options.Options;
import org.openjdk.jmh.runner.options.OptionsBuilder;
import org.openjdk.jmh.runner.options.VerboseMode;
import java.io.IOException;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.flink.benchmark;
/**
* JMH throughput benchmark runner.
*/
@OperationsPerInvocation(value = BlockingPartitionBenchmark.RECORDS_PER_INVOCATION)
public class BlockingPartitionBenchmark extends BenchmarkBase {
public static final int RECORDS_PER_INVOCATION = 15_000_000;
public static void main(String[] args)
throws RunnerException {
Options options = new OptionsBuilder()
.verbosity(VerboseMode.NORMAL)
.include(".*" + BlockingPartitionBenchmark.class.getCanonicalName() + ".*")
.build();
new Runner(options).run();
}
@Benchmark
public void uncompressedFilePartition(UncompressedFileEnvironmentContext context) throws Exception {
executeBenchmark(context.env);
}
@Benchmark
public void compressedFilePartition(CompressedFileEnvironmentContext context) throws Exception {
executeBenchmark(context.env);
}
@Benchmark
public void uncompressedMmapPartition(UncompressedMmapEnvironmentContext context) throws Exception {
executeBenchmark(context.env);
}
private void executeBenchmark(StreamExecutionEnvironment env) throws Exception { | DataStreamSource<Long> source = env.addSource(new LongSource(RECORDS_PER_INVOCATION)); |
dataArtisans/flink-benchmarks | src/main/java/org/apache/flink/state/benchmark/ListStateBenchmark.java | // Path: src/main/java/org/apache/flink/state/benchmark/StateBenchmarkConstants.java
// static final int listValueCount = 100;
//
// Path: src/main/java/org/apache/flink/state/benchmark/StateBenchmarkConstants.java
// static final int setupKeyCount = 500_000;
| import org.apache.flink.api.common.state.ListState;
import org.apache.flink.api.common.state.ListStateDescriptor;
import org.apache.flink.contrib.streaming.state.RocksDBKeyedStateBackend;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.Level;
import org.openjdk.jmh.annotations.Setup;
import org.openjdk.jmh.annotations.TearDown;
import org.openjdk.jmh.infra.Blackhole;
import org.openjdk.jmh.runner.Runner;
import org.openjdk.jmh.runner.RunnerException;
import org.openjdk.jmh.runner.options.Options;
import org.openjdk.jmh.runner.options.OptionsBuilder;
import org.openjdk.jmh.runner.options.VerboseMode;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;
import static org.apache.flink.contrib.streaming.state.benchmark.StateBackendBenchmarkUtils.applyToAllKeys;
import static org.apache.flink.contrib.streaming.state.benchmark.StateBackendBenchmarkUtils.compactState;
import static org.apache.flink.contrib.streaming.state.benchmark.StateBackendBenchmarkUtils.createKeyedStateBackend;
import static org.apache.flink.contrib.streaming.state.benchmark.StateBackendBenchmarkUtils.getListState;
import static org.apache.flink.state.benchmark.StateBenchmarkConstants.listValueCount;
import static org.apache.flink.state.benchmark.StateBenchmarkConstants.setupKeyCount; | /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.flink.state.benchmark;
/**
* Implementation for list state benchmark testing.
*/
public class ListStateBenchmark extends StateBenchmarkBase {
private final String STATE_NAME = "listState";
private final ListStateDescriptor<Long> STATE_DESC = new ListStateDescriptor<>(STATE_NAME, Long.class);
private ListState<Long> listState;
private List<Long> dummyLists;
public static void main(String[] args) throws RunnerException {
Options opt = new OptionsBuilder()
.verbosity(VerboseMode.NORMAL)
.include(".*" + ListStateBenchmark.class.getCanonicalName() + ".*")
.build();
new Runner(opt).run();
}
@Setup
public void setUp() throws Exception {
keyedStateBackend = createKeyedStateBackend(backendType);
listState = getListState(keyedStateBackend, STATE_DESC); | // Path: src/main/java/org/apache/flink/state/benchmark/StateBenchmarkConstants.java
// static final int listValueCount = 100;
//
// Path: src/main/java/org/apache/flink/state/benchmark/StateBenchmarkConstants.java
// static final int setupKeyCount = 500_000;
// Path: src/main/java/org/apache/flink/state/benchmark/ListStateBenchmark.java
import org.apache.flink.api.common.state.ListState;
import org.apache.flink.api.common.state.ListStateDescriptor;
import org.apache.flink.contrib.streaming.state.RocksDBKeyedStateBackend;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.Level;
import org.openjdk.jmh.annotations.Setup;
import org.openjdk.jmh.annotations.TearDown;
import org.openjdk.jmh.infra.Blackhole;
import org.openjdk.jmh.runner.Runner;
import org.openjdk.jmh.runner.RunnerException;
import org.openjdk.jmh.runner.options.Options;
import org.openjdk.jmh.runner.options.OptionsBuilder;
import org.openjdk.jmh.runner.options.VerboseMode;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;
import static org.apache.flink.contrib.streaming.state.benchmark.StateBackendBenchmarkUtils.applyToAllKeys;
import static org.apache.flink.contrib.streaming.state.benchmark.StateBackendBenchmarkUtils.compactState;
import static org.apache.flink.contrib.streaming.state.benchmark.StateBackendBenchmarkUtils.createKeyedStateBackend;
import static org.apache.flink.contrib.streaming.state.benchmark.StateBackendBenchmarkUtils.getListState;
import static org.apache.flink.state.benchmark.StateBenchmarkConstants.listValueCount;
import static org.apache.flink.state.benchmark.StateBenchmarkConstants.setupKeyCount;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.flink.state.benchmark;
/**
* Implementation for list state benchmark testing.
*/
public class ListStateBenchmark extends StateBenchmarkBase {
private final String STATE_NAME = "listState";
private final ListStateDescriptor<Long> STATE_DESC = new ListStateDescriptor<>(STATE_NAME, Long.class);
private ListState<Long> listState;
private List<Long> dummyLists;
public static void main(String[] args) throws RunnerException {
Options opt = new OptionsBuilder()
.verbosity(VerboseMode.NORMAL)
.include(".*" + ListStateBenchmark.class.getCanonicalName() + ".*")
.build();
new Runner(opt).run();
}
@Setup
public void setUp() throws Exception {
keyedStateBackend = createKeyedStateBackend(backendType);
listState = getListState(keyedStateBackend, STATE_DESC); | dummyLists = new ArrayList<>(listValueCount); |
dataArtisans/flink-benchmarks | src/main/java/org/apache/flink/state/benchmark/ListStateBenchmark.java | // Path: src/main/java/org/apache/flink/state/benchmark/StateBenchmarkConstants.java
// static final int listValueCount = 100;
//
// Path: src/main/java/org/apache/flink/state/benchmark/StateBenchmarkConstants.java
// static final int setupKeyCount = 500_000;
| import org.apache.flink.api.common.state.ListState;
import org.apache.flink.api.common.state.ListStateDescriptor;
import org.apache.flink.contrib.streaming.state.RocksDBKeyedStateBackend;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.Level;
import org.openjdk.jmh.annotations.Setup;
import org.openjdk.jmh.annotations.TearDown;
import org.openjdk.jmh.infra.Blackhole;
import org.openjdk.jmh.runner.Runner;
import org.openjdk.jmh.runner.RunnerException;
import org.openjdk.jmh.runner.options.Options;
import org.openjdk.jmh.runner.options.OptionsBuilder;
import org.openjdk.jmh.runner.options.VerboseMode;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;
import static org.apache.flink.contrib.streaming.state.benchmark.StateBackendBenchmarkUtils.applyToAllKeys;
import static org.apache.flink.contrib.streaming.state.benchmark.StateBackendBenchmarkUtils.compactState;
import static org.apache.flink.contrib.streaming.state.benchmark.StateBackendBenchmarkUtils.createKeyedStateBackend;
import static org.apache.flink.contrib.streaming.state.benchmark.StateBackendBenchmarkUtils.getListState;
import static org.apache.flink.state.benchmark.StateBenchmarkConstants.listValueCount;
import static org.apache.flink.state.benchmark.StateBenchmarkConstants.setupKeyCount; | /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.flink.state.benchmark;
/**
* Implementation for list state benchmark testing.
*/
public class ListStateBenchmark extends StateBenchmarkBase {
private final String STATE_NAME = "listState";
private final ListStateDescriptor<Long> STATE_DESC = new ListStateDescriptor<>(STATE_NAME, Long.class);
private ListState<Long> listState;
private List<Long> dummyLists;
public static void main(String[] args) throws RunnerException {
Options opt = new OptionsBuilder()
.verbosity(VerboseMode.NORMAL)
.include(".*" + ListStateBenchmark.class.getCanonicalName() + ".*")
.build();
new Runner(opt).run();
}
@Setup
public void setUp() throws Exception {
keyedStateBackend = createKeyedStateBackend(backendType);
listState = getListState(keyedStateBackend, STATE_DESC);
dummyLists = new ArrayList<>(listValueCount);
for (int i = 0; i < listValueCount; ++i) {
dummyLists.add(random.nextLong());
}
keyIndex = new AtomicInteger();
}
@Setup(Level.Iteration)
public void setUpPerIteration() throws Exception { | // Path: src/main/java/org/apache/flink/state/benchmark/StateBenchmarkConstants.java
// static final int listValueCount = 100;
//
// Path: src/main/java/org/apache/flink/state/benchmark/StateBenchmarkConstants.java
// static final int setupKeyCount = 500_000;
// Path: src/main/java/org/apache/flink/state/benchmark/ListStateBenchmark.java
import org.apache.flink.api.common.state.ListState;
import org.apache.flink.api.common.state.ListStateDescriptor;
import org.apache.flink.contrib.streaming.state.RocksDBKeyedStateBackend;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.Level;
import org.openjdk.jmh.annotations.Setup;
import org.openjdk.jmh.annotations.TearDown;
import org.openjdk.jmh.infra.Blackhole;
import org.openjdk.jmh.runner.Runner;
import org.openjdk.jmh.runner.RunnerException;
import org.openjdk.jmh.runner.options.Options;
import org.openjdk.jmh.runner.options.OptionsBuilder;
import org.openjdk.jmh.runner.options.VerboseMode;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;
import static org.apache.flink.contrib.streaming.state.benchmark.StateBackendBenchmarkUtils.applyToAllKeys;
import static org.apache.flink.contrib.streaming.state.benchmark.StateBackendBenchmarkUtils.compactState;
import static org.apache.flink.contrib.streaming.state.benchmark.StateBackendBenchmarkUtils.createKeyedStateBackend;
import static org.apache.flink.contrib.streaming.state.benchmark.StateBackendBenchmarkUtils.getListState;
import static org.apache.flink.state.benchmark.StateBenchmarkConstants.listValueCount;
import static org.apache.flink.state.benchmark.StateBenchmarkConstants.setupKeyCount;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.flink.state.benchmark;
/**
* Implementation for list state benchmark testing.
*/
public class ListStateBenchmark extends StateBenchmarkBase {
private final String STATE_NAME = "listState";
private final ListStateDescriptor<Long> STATE_DESC = new ListStateDescriptor<>(STATE_NAME, Long.class);
private ListState<Long> listState;
private List<Long> dummyLists;
public static void main(String[] args) throws RunnerException {
Options opt = new OptionsBuilder()
.verbosity(VerboseMode.NORMAL)
.include(".*" + ListStateBenchmark.class.getCanonicalName() + ".*")
.build();
new Runner(opt).run();
}
@Setup
public void setUp() throws Exception {
keyedStateBackend = createKeyedStateBackend(backendType);
listState = getListState(keyedStateBackend, STATE_DESC);
dummyLists = new ArrayList<>(listValueCount);
for (int i = 0; i < listValueCount; ++i) {
dummyLists.add(random.nextLong());
}
keyIndex = new AtomicInteger();
}
@Setup(Level.Iteration)
public void setUpPerIteration() throws Exception { | for (int i = 0; i < setupKeyCount; ++i) { |
dataArtisans/flink-benchmarks | src/main/java/org/apache/flink/benchmark/AsyncWaitOperatorBenchmark.java | // Path: src/main/java/org/apache/flink/benchmark/functions/LongSource.java
// public class LongSource extends RichParallelSourceFunction<Long> {
//
// private volatile boolean running = true;
// private long maxValue;
//
// public LongSource(long maxValue) {
// this.maxValue = maxValue;
// }
//
// @Override
// public void run(SourceContext<Long> ctx) throws Exception {
// long counter = 0;
//
// while (running) {
// synchronized (ctx.getCheckpointLock()) {
// ctx.collect(counter);
// counter++;
// if (counter >= maxValue) {
// cancel();
// }
// }
// }
// }
//
// @Override
// public void cancel() {
// running = false;
// }
// }
| import org.apache.flink.benchmark.functions.LongSource;
import org.apache.flink.streaming.api.datastream.AsyncDataStream;
import org.apache.flink.streaming.api.datastream.DataStream;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.apache.flink.streaming.api.functions.async.ResultFuture;
import org.apache.flink.streaming.api.functions.async.RichAsyncFunction;
import org.apache.flink.streaming.api.functions.sink.DiscardingSink;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.OperationsPerInvocation;
import org.openjdk.jmh.annotations.Param;
import org.openjdk.jmh.annotations.Setup;
import org.openjdk.jmh.annotations.TearDown;
import org.openjdk.jmh.runner.Runner;
import org.openjdk.jmh.runner.RunnerException;
import org.openjdk.jmh.runner.options.Options;
import org.openjdk.jmh.runner.options.OptionsBuilder;
import org.openjdk.jmh.runner.options.VerboseMode;
import java.util.Collections;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit; | /*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.flink.benchmark;
@OperationsPerInvocation(value = AsyncWaitOperatorBenchmark.RECORDS_PER_INVOCATION)
public class AsyncWaitOperatorBenchmark extends BenchmarkBase {
public static final int RECORDS_PER_INVOCATION = 1_000_000;
private static final long CHECKPOINT_INTERVAL_MS = 100;
private static ExecutorService executor;
@Param
public AsyncDataStream.OutputMode outputMode;
public static void main(String[] args)
throws RunnerException {
Options options = new OptionsBuilder()
.verbosity(VerboseMode.NORMAL)
.include(".*" + AsyncWaitOperatorBenchmark.class.getCanonicalName() + ".*")
.build();
new Runner(options).run();
}
@Setup
public void setUp() {
executor = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors());
}
@TearDown
public void tearDown() {
executor.shutdown();
}
@Benchmark
public void asyncWait(FlinkEnvironmentContext context) throws Exception {
StreamExecutionEnvironment env = context.env;
env.enableCheckpointing(CHECKPOINT_INTERVAL_MS);
env.setParallelism(1);
| // Path: src/main/java/org/apache/flink/benchmark/functions/LongSource.java
// public class LongSource extends RichParallelSourceFunction<Long> {
//
// private volatile boolean running = true;
// private long maxValue;
//
// public LongSource(long maxValue) {
// this.maxValue = maxValue;
// }
//
// @Override
// public void run(SourceContext<Long> ctx) throws Exception {
// long counter = 0;
//
// while (running) {
// synchronized (ctx.getCheckpointLock()) {
// ctx.collect(counter);
// counter++;
// if (counter >= maxValue) {
// cancel();
// }
// }
// }
// }
//
// @Override
// public void cancel() {
// running = false;
// }
// }
// Path: src/main/java/org/apache/flink/benchmark/AsyncWaitOperatorBenchmark.java
import org.apache.flink.benchmark.functions.LongSource;
import org.apache.flink.streaming.api.datastream.AsyncDataStream;
import org.apache.flink.streaming.api.datastream.DataStream;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.apache.flink.streaming.api.functions.async.ResultFuture;
import org.apache.flink.streaming.api.functions.async.RichAsyncFunction;
import org.apache.flink.streaming.api.functions.sink.DiscardingSink;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.OperationsPerInvocation;
import org.openjdk.jmh.annotations.Param;
import org.openjdk.jmh.annotations.Setup;
import org.openjdk.jmh.annotations.TearDown;
import org.openjdk.jmh.runner.Runner;
import org.openjdk.jmh.runner.RunnerException;
import org.openjdk.jmh.runner.options.Options;
import org.openjdk.jmh.runner.options.OptionsBuilder;
import org.openjdk.jmh.runner.options.VerboseMode;
import java.util.Collections;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.flink.benchmark;
@OperationsPerInvocation(value = AsyncWaitOperatorBenchmark.RECORDS_PER_INVOCATION)
public class AsyncWaitOperatorBenchmark extends BenchmarkBase {
public static final int RECORDS_PER_INVOCATION = 1_000_000;
private static final long CHECKPOINT_INTERVAL_MS = 100;
private static ExecutorService executor;
@Param
public AsyncDataStream.OutputMode outputMode;
public static void main(String[] args)
throws RunnerException {
Options options = new OptionsBuilder()
.verbosity(VerboseMode.NORMAL)
.include(".*" + AsyncWaitOperatorBenchmark.class.getCanonicalName() + ".*")
.build();
new Runner(options).run();
}
@Setup
public void setUp() {
executor = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors());
}
@TearDown
public void tearDown() {
executor.shutdown();
}
@Benchmark
public void asyncWait(FlinkEnvironmentContext context) throws Exception {
StreamExecutionEnvironment env = context.env;
env.enableCheckpointing(CHECKPOINT_INTERVAL_MS);
env.setParallelism(1);
| DataStreamSource<Long> source = env.addSource(new LongSource(RECORDS_PER_INVOCATION)); |
dataArtisans/flink-benchmarks | src/main/java/org/apache/flink/benchmark/KeyByBenchmarks.java | // Path: src/main/java/org/apache/flink/benchmark/functions/BaseSourceWithKeyRange.java
// abstract public class BaseSourceWithKeyRange<T> implements ParallelSourceFunction<T> {
// private static final long serialVersionUID = 8318018060123048234L;
//
// protected final int numKeys;
// protected int remainingEvents;
//
// public BaseSourceWithKeyRange(int numEvents, int numKeys) {
// this.remainingEvents = numEvents;
// this.numKeys = numKeys;
// }
//
// protected void init() {
// }
//
// protected abstract T getElement(int keyId);
//
// @Override
// public void run(SourceContext<T> out) {
// init();
//
// int keyId = 0;
// while (--remainingEvents >= 0) {
// T element = getElement(keyId);
// synchronized (out.getCheckpointLock()) {
// out.collect(element);
// }
// ++keyId;
// if (keyId >= numKeys) {
// keyId = 0;
// }
// }
// }
//
// @Override
// public void cancel() {
// this.remainingEvents = 0;
// }
// }
| import org.apache.flink.api.java.tuple.Tuple2;
import org.apache.flink.benchmark.functions.BaseSourceWithKeyRange;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.apache.flink.streaming.api.functions.sink.DiscardingSink;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.OperationsPerInvocation;
import org.openjdk.jmh.runner.Runner;
import org.openjdk.jmh.runner.RunnerException;
import org.openjdk.jmh.runner.options.Options;
import org.openjdk.jmh.runner.options.OptionsBuilder;
import org.openjdk.jmh.runner.options.VerboseMode; |
new Runner(options).run();
}
@Benchmark
@OperationsPerInvocation(value = KeyByBenchmarks.TUPLE_RECORDS_PER_INVOCATION)
public void tupleKeyBy(FlinkEnvironmentContext context) throws Exception {
StreamExecutionEnvironment env = context.env;
env.setParallelism(4);
env.addSource(new IncreasingTupleSource(TUPLE_RECORDS_PER_INVOCATION, 10))
.keyBy(0)
.addSink(new DiscardingSink<>());
env.execute();
}
@Benchmark
@OperationsPerInvocation(value = KeyByBenchmarks.ARRAY_RECORDS_PER_INVOCATION)
public void arrayKeyBy(FlinkEnvironmentContext context) throws Exception {
StreamExecutionEnvironment env = context.env;
env.setParallelism(4);
env.addSource(new IncreasingArraySource(ARRAY_RECORDS_PER_INVOCATION, 10))
.keyBy(0)
.addSink(new DiscardingSink<>());
env.execute();
}
| // Path: src/main/java/org/apache/flink/benchmark/functions/BaseSourceWithKeyRange.java
// abstract public class BaseSourceWithKeyRange<T> implements ParallelSourceFunction<T> {
// private static final long serialVersionUID = 8318018060123048234L;
//
// protected final int numKeys;
// protected int remainingEvents;
//
// public BaseSourceWithKeyRange(int numEvents, int numKeys) {
// this.remainingEvents = numEvents;
// this.numKeys = numKeys;
// }
//
// protected void init() {
// }
//
// protected abstract T getElement(int keyId);
//
// @Override
// public void run(SourceContext<T> out) {
// init();
//
// int keyId = 0;
// while (--remainingEvents >= 0) {
// T element = getElement(keyId);
// synchronized (out.getCheckpointLock()) {
// out.collect(element);
// }
// ++keyId;
// if (keyId >= numKeys) {
// keyId = 0;
// }
// }
// }
//
// @Override
// public void cancel() {
// this.remainingEvents = 0;
// }
// }
// Path: src/main/java/org/apache/flink/benchmark/KeyByBenchmarks.java
import org.apache.flink.api.java.tuple.Tuple2;
import org.apache.flink.benchmark.functions.BaseSourceWithKeyRange;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.apache.flink.streaming.api.functions.sink.DiscardingSink;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.OperationsPerInvocation;
import org.openjdk.jmh.runner.Runner;
import org.openjdk.jmh.runner.RunnerException;
import org.openjdk.jmh.runner.options.Options;
import org.openjdk.jmh.runner.options.OptionsBuilder;
import org.openjdk.jmh.runner.options.VerboseMode;
new Runner(options).run();
}
@Benchmark
@OperationsPerInvocation(value = KeyByBenchmarks.TUPLE_RECORDS_PER_INVOCATION)
public void tupleKeyBy(FlinkEnvironmentContext context) throws Exception {
StreamExecutionEnvironment env = context.env;
env.setParallelism(4);
env.addSource(new IncreasingTupleSource(TUPLE_RECORDS_PER_INVOCATION, 10))
.keyBy(0)
.addSink(new DiscardingSink<>());
env.execute();
}
@Benchmark
@OperationsPerInvocation(value = KeyByBenchmarks.ARRAY_RECORDS_PER_INVOCATION)
public void arrayKeyBy(FlinkEnvironmentContext context) throws Exception {
StreamExecutionEnvironment env = context.env;
env.setParallelism(4);
env.addSource(new IncreasingArraySource(ARRAY_RECORDS_PER_INVOCATION, 10))
.keyBy(0)
.addSink(new DiscardingSink<>());
env.execute();
}
| private static class IncreasingTupleSource extends BaseSourceWithKeyRange<Tuple2<Integer, Integer>> { |
dataArtisans/flink-benchmarks | src/main/java/org/apache/flink/state/benchmark/StateBenchmarkBase.java | // Path: src/main/java/org/apache/flink/benchmark/BenchmarkBase.java
// @SuppressWarnings("MethodMayBeStatic")
// @State(Thread)
// @OutputTimeUnit(MILLISECONDS)
// @BenchmarkMode(Throughput)
// @Fork(value = 3, jvmArgsAppend = {
// "-Djava.rmi.server.hostname=127.0.0.1",
// "-Dcom.sun.management.jmxremote.authenticate=false",
// "-Dcom.sun.management.jmxremote.ssl=false",
// "-Dcom.sun.management.jmxremote.ssl"})
// @Warmup(iterations = 10)
// @Measurement(iterations = 10)
// public class BenchmarkBase {
// }
//
// Path: src/main/java/org/apache/flink/state/benchmark/StateBenchmarkConstants.java
// static final int mapKeyCount = 10;
//
// Path: src/main/java/org/apache/flink/state/benchmark/StateBenchmarkConstants.java
// static final ArrayList<Long> mapKeys = new ArrayList<>(mapKeyCount);
//
// Path: src/main/java/org/apache/flink/state/benchmark/StateBenchmarkConstants.java
// static final ArrayList<Double> mapValues = new ArrayList<>(mapKeyCount);
//
// Path: src/main/java/org/apache/flink/state/benchmark/StateBenchmarkConstants.java
// static final int newKeyCount = 500_000;
//
// Path: src/main/java/org/apache/flink/state/benchmark/StateBenchmarkConstants.java
// static final ArrayList<Long> newKeys = new ArrayList<>(newKeyCount);
//
// Path: src/main/java/org/apache/flink/state/benchmark/StateBenchmarkConstants.java
// static final int randomValueCount = 1_000_000;
//
// Path: src/main/java/org/apache/flink/state/benchmark/StateBenchmarkConstants.java
// static final ArrayList<Long> randomValues = new ArrayList<>(randomValueCount);
//
// Path: src/main/java/org/apache/flink/state/benchmark/StateBenchmarkConstants.java
// static final int setupKeyCount = 500_000;
//
// Path: src/main/java/org/apache/flink/state/benchmark/StateBenchmarkConstants.java
// static final ArrayList<Long> setupKeys = new ArrayList<>(setupKeyCount);
| import org.apache.flink.benchmark.BenchmarkBase;
import org.apache.flink.contrib.streaming.state.benchmark.StateBackendBenchmarkUtils;
import org.apache.flink.runtime.state.KeyedStateBackend;
import org.openjdk.jmh.annotations.Level;
import org.openjdk.jmh.annotations.Param;
import org.openjdk.jmh.annotations.Scope;
import org.openjdk.jmh.annotations.Setup;
import org.openjdk.jmh.annotations.State;
import org.openjdk.jmh.annotations.TearDown;
import java.io.IOException;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.ThreadLocalRandom;
import java.util.concurrent.atomic.AtomicInteger;
import static org.apache.flink.contrib.streaming.state.benchmark.StateBackendBenchmarkUtils.cleanUp;
import static org.apache.flink.state.benchmark.StateBenchmarkConstants.mapKeyCount;
import static org.apache.flink.state.benchmark.StateBenchmarkConstants.mapKeys;
import static org.apache.flink.state.benchmark.StateBenchmarkConstants.mapValues;
import static org.apache.flink.state.benchmark.StateBenchmarkConstants.newKeyCount;
import static org.apache.flink.state.benchmark.StateBenchmarkConstants.newKeys;
import static org.apache.flink.state.benchmark.StateBenchmarkConstants.randomValueCount;
import static org.apache.flink.state.benchmark.StateBenchmarkConstants.randomValues;
import static org.apache.flink.state.benchmark.StateBenchmarkConstants.setupKeyCount;
import static org.apache.flink.state.benchmark.StateBenchmarkConstants.setupKeys; | /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.flink.state.benchmark;
/**
* Base implementation of the state benchmarks.
*/
public class StateBenchmarkBase extends BenchmarkBase {
KeyedStateBackend<Long> keyedStateBackend;
@Param({"HEAP", "ROCKSDB"})
protected StateBackendBenchmarkUtils.StateBackendType backendType;
final ThreadLocalRandom random = ThreadLocalRandom.current();
@TearDown
public void tearDown() throws IOException {
cleanUp(keyedStateBackend);
}
static AtomicInteger keyIndex;
private static int getCurrentIndex() {
int currentIndex = keyIndex.getAndIncrement();
if (currentIndex == Integer.MAX_VALUE) {
keyIndex.set(0);
}
return currentIndex;
}
@State(Scope.Thread)
public static class KeyValue {
@Setup(Level.Invocation)
public void kvSetup() {
int currentIndex = getCurrentIndex(); | // Path: src/main/java/org/apache/flink/benchmark/BenchmarkBase.java
// @SuppressWarnings("MethodMayBeStatic")
// @State(Thread)
// @OutputTimeUnit(MILLISECONDS)
// @BenchmarkMode(Throughput)
// @Fork(value = 3, jvmArgsAppend = {
// "-Djava.rmi.server.hostname=127.0.0.1",
// "-Dcom.sun.management.jmxremote.authenticate=false",
// "-Dcom.sun.management.jmxremote.ssl=false",
// "-Dcom.sun.management.jmxremote.ssl"})
// @Warmup(iterations = 10)
// @Measurement(iterations = 10)
// public class BenchmarkBase {
// }
//
// Path: src/main/java/org/apache/flink/state/benchmark/StateBenchmarkConstants.java
// static final int mapKeyCount = 10;
//
// Path: src/main/java/org/apache/flink/state/benchmark/StateBenchmarkConstants.java
// static final ArrayList<Long> mapKeys = new ArrayList<>(mapKeyCount);
//
// Path: src/main/java/org/apache/flink/state/benchmark/StateBenchmarkConstants.java
// static final ArrayList<Double> mapValues = new ArrayList<>(mapKeyCount);
//
// Path: src/main/java/org/apache/flink/state/benchmark/StateBenchmarkConstants.java
// static final int newKeyCount = 500_000;
//
// Path: src/main/java/org/apache/flink/state/benchmark/StateBenchmarkConstants.java
// static final ArrayList<Long> newKeys = new ArrayList<>(newKeyCount);
//
// Path: src/main/java/org/apache/flink/state/benchmark/StateBenchmarkConstants.java
// static final int randomValueCount = 1_000_000;
//
// Path: src/main/java/org/apache/flink/state/benchmark/StateBenchmarkConstants.java
// static final ArrayList<Long> randomValues = new ArrayList<>(randomValueCount);
//
// Path: src/main/java/org/apache/flink/state/benchmark/StateBenchmarkConstants.java
// static final int setupKeyCount = 500_000;
//
// Path: src/main/java/org/apache/flink/state/benchmark/StateBenchmarkConstants.java
// static final ArrayList<Long> setupKeys = new ArrayList<>(setupKeyCount);
// Path: src/main/java/org/apache/flink/state/benchmark/StateBenchmarkBase.java
import org.apache.flink.benchmark.BenchmarkBase;
import org.apache.flink.contrib.streaming.state.benchmark.StateBackendBenchmarkUtils;
import org.apache.flink.runtime.state.KeyedStateBackend;
import org.openjdk.jmh.annotations.Level;
import org.openjdk.jmh.annotations.Param;
import org.openjdk.jmh.annotations.Scope;
import org.openjdk.jmh.annotations.Setup;
import org.openjdk.jmh.annotations.State;
import org.openjdk.jmh.annotations.TearDown;
import java.io.IOException;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.ThreadLocalRandom;
import java.util.concurrent.atomic.AtomicInteger;
import static org.apache.flink.contrib.streaming.state.benchmark.StateBackendBenchmarkUtils.cleanUp;
import static org.apache.flink.state.benchmark.StateBenchmarkConstants.mapKeyCount;
import static org.apache.flink.state.benchmark.StateBenchmarkConstants.mapKeys;
import static org.apache.flink.state.benchmark.StateBenchmarkConstants.mapValues;
import static org.apache.flink.state.benchmark.StateBenchmarkConstants.newKeyCount;
import static org.apache.flink.state.benchmark.StateBenchmarkConstants.newKeys;
import static org.apache.flink.state.benchmark.StateBenchmarkConstants.randomValueCount;
import static org.apache.flink.state.benchmark.StateBenchmarkConstants.randomValues;
import static org.apache.flink.state.benchmark.StateBenchmarkConstants.setupKeyCount;
import static org.apache.flink.state.benchmark.StateBenchmarkConstants.setupKeys;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.flink.state.benchmark;
/**
* Base implementation of the state benchmarks.
*/
public class StateBenchmarkBase extends BenchmarkBase {
KeyedStateBackend<Long> keyedStateBackend;
@Param({"HEAP", "ROCKSDB"})
protected StateBackendBenchmarkUtils.StateBackendType backendType;
final ThreadLocalRandom random = ThreadLocalRandom.current();
@TearDown
public void tearDown() throws IOException {
cleanUp(keyedStateBackend);
}
static AtomicInteger keyIndex;
private static int getCurrentIndex() {
int currentIndex = keyIndex.getAndIncrement();
if (currentIndex == Integer.MAX_VALUE) {
keyIndex.set(0);
}
return currentIndex;
}
@State(Scope.Thread)
public static class KeyValue {
@Setup(Level.Invocation)
public void kvSetup() {
int currentIndex = getCurrentIndex(); | setUpKey = setupKeys.get(currentIndex % setupKeyCount); |
dataArtisans/flink-benchmarks | src/main/java/org/apache/flink/state/benchmark/StateBenchmarkBase.java | // Path: src/main/java/org/apache/flink/benchmark/BenchmarkBase.java
// @SuppressWarnings("MethodMayBeStatic")
// @State(Thread)
// @OutputTimeUnit(MILLISECONDS)
// @BenchmarkMode(Throughput)
// @Fork(value = 3, jvmArgsAppend = {
// "-Djava.rmi.server.hostname=127.0.0.1",
// "-Dcom.sun.management.jmxremote.authenticate=false",
// "-Dcom.sun.management.jmxremote.ssl=false",
// "-Dcom.sun.management.jmxremote.ssl"})
// @Warmup(iterations = 10)
// @Measurement(iterations = 10)
// public class BenchmarkBase {
// }
//
// Path: src/main/java/org/apache/flink/state/benchmark/StateBenchmarkConstants.java
// static final int mapKeyCount = 10;
//
// Path: src/main/java/org/apache/flink/state/benchmark/StateBenchmarkConstants.java
// static final ArrayList<Long> mapKeys = new ArrayList<>(mapKeyCount);
//
// Path: src/main/java/org/apache/flink/state/benchmark/StateBenchmarkConstants.java
// static final ArrayList<Double> mapValues = new ArrayList<>(mapKeyCount);
//
// Path: src/main/java/org/apache/flink/state/benchmark/StateBenchmarkConstants.java
// static final int newKeyCount = 500_000;
//
// Path: src/main/java/org/apache/flink/state/benchmark/StateBenchmarkConstants.java
// static final ArrayList<Long> newKeys = new ArrayList<>(newKeyCount);
//
// Path: src/main/java/org/apache/flink/state/benchmark/StateBenchmarkConstants.java
// static final int randomValueCount = 1_000_000;
//
// Path: src/main/java/org/apache/flink/state/benchmark/StateBenchmarkConstants.java
// static final ArrayList<Long> randomValues = new ArrayList<>(randomValueCount);
//
// Path: src/main/java/org/apache/flink/state/benchmark/StateBenchmarkConstants.java
// static final int setupKeyCount = 500_000;
//
// Path: src/main/java/org/apache/flink/state/benchmark/StateBenchmarkConstants.java
// static final ArrayList<Long> setupKeys = new ArrayList<>(setupKeyCount);
| import org.apache.flink.benchmark.BenchmarkBase;
import org.apache.flink.contrib.streaming.state.benchmark.StateBackendBenchmarkUtils;
import org.apache.flink.runtime.state.KeyedStateBackend;
import org.openjdk.jmh.annotations.Level;
import org.openjdk.jmh.annotations.Param;
import org.openjdk.jmh.annotations.Scope;
import org.openjdk.jmh.annotations.Setup;
import org.openjdk.jmh.annotations.State;
import org.openjdk.jmh.annotations.TearDown;
import java.io.IOException;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.ThreadLocalRandom;
import java.util.concurrent.atomic.AtomicInteger;
import static org.apache.flink.contrib.streaming.state.benchmark.StateBackendBenchmarkUtils.cleanUp;
import static org.apache.flink.state.benchmark.StateBenchmarkConstants.mapKeyCount;
import static org.apache.flink.state.benchmark.StateBenchmarkConstants.mapKeys;
import static org.apache.flink.state.benchmark.StateBenchmarkConstants.mapValues;
import static org.apache.flink.state.benchmark.StateBenchmarkConstants.newKeyCount;
import static org.apache.flink.state.benchmark.StateBenchmarkConstants.newKeys;
import static org.apache.flink.state.benchmark.StateBenchmarkConstants.randomValueCount;
import static org.apache.flink.state.benchmark.StateBenchmarkConstants.randomValues;
import static org.apache.flink.state.benchmark.StateBenchmarkConstants.setupKeyCount;
import static org.apache.flink.state.benchmark.StateBenchmarkConstants.setupKeys; | /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.flink.state.benchmark;
/**
* Base implementation of the state benchmarks.
*/
public class StateBenchmarkBase extends BenchmarkBase {
KeyedStateBackend<Long> keyedStateBackend;
@Param({"HEAP", "ROCKSDB"})
protected StateBackendBenchmarkUtils.StateBackendType backendType;
final ThreadLocalRandom random = ThreadLocalRandom.current();
@TearDown
public void tearDown() throws IOException {
cleanUp(keyedStateBackend);
}
static AtomicInteger keyIndex;
private static int getCurrentIndex() {
int currentIndex = keyIndex.getAndIncrement();
if (currentIndex == Integer.MAX_VALUE) {
keyIndex.set(0);
}
return currentIndex;
}
@State(Scope.Thread)
public static class KeyValue {
@Setup(Level.Invocation)
public void kvSetup() {
int currentIndex = getCurrentIndex(); | // Path: src/main/java/org/apache/flink/benchmark/BenchmarkBase.java
// @SuppressWarnings("MethodMayBeStatic")
// @State(Thread)
// @OutputTimeUnit(MILLISECONDS)
// @BenchmarkMode(Throughput)
// @Fork(value = 3, jvmArgsAppend = {
// "-Djava.rmi.server.hostname=127.0.0.1",
// "-Dcom.sun.management.jmxremote.authenticate=false",
// "-Dcom.sun.management.jmxremote.ssl=false",
// "-Dcom.sun.management.jmxremote.ssl"})
// @Warmup(iterations = 10)
// @Measurement(iterations = 10)
// public class BenchmarkBase {
// }
//
// Path: src/main/java/org/apache/flink/state/benchmark/StateBenchmarkConstants.java
// static final int mapKeyCount = 10;
//
// Path: src/main/java/org/apache/flink/state/benchmark/StateBenchmarkConstants.java
// static final ArrayList<Long> mapKeys = new ArrayList<>(mapKeyCount);
//
// Path: src/main/java/org/apache/flink/state/benchmark/StateBenchmarkConstants.java
// static final ArrayList<Double> mapValues = new ArrayList<>(mapKeyCount);
//
// Path: src/main/java/org/apache/flink/state/benchmark/StateBenchmarkConstants.java
// static final int newKeyCount = 500_000;
//
// Path: src/main/java/org/apache/flink/state/benchmark/StateBenchmarkConstants.java
// static final ArrayList<Long> newKeys = new ArrayList<>(newKeyCount);
//
// Path: src/main/java/org/apache/flink/state/benchmark/StateBenchmarkConstants.java
// static final int randomValueCount = 1_000_000;
//
// Path: src/main/java/org/apache/flink/state/benchmark/StateBenchmarkConstants.java
// static final ArrayList<Long> randomValues = new ArrayList<>(randomValueCount);
//
// Path: src/main/java/org/apache/flink/state/benchmark/StateBenchmarkConstants.java
// static final int setupKeyCount = 500_000;
//
// Path: src/main/java/org/apache/flink/state/benchmark/StateBenchmarkConstants.java
// static final ArrayList<Long> setupKeys = new ArrayList<>(setupKeyCount);
// Path: src/main/java/org/apache/flink/state/benchmark/StateBenchmarkBase.java
import org.apache.flink.benchmark.BenchmarkBase;
import org.apache.flink.contrib.streaming.state.benchmark.StateBackendBenchmarkUtils;
import org.apache.flink.runtime.state.KeyedStateBackend;
import org.openjdk.jmh.annotations.Level;
import org.openjdk.jmh.annotations.Param;
import org.openjdk.jmh.annotations.Scope;
import org.openjdk.jmh.annotations.Setup;
import org.openjdk.jmh.annotations.State;
import org.openjdk.jmh.annotations.TearDown;
import java.io.IOException;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.ThreadLocalRandom;
import java.util.concurrent.atomic.AtomicInteger;
import static org.apache.flink.contrib.streaming.state.benchmark.StateBackendBenchmarkUtils.cleanUp;
import static org.apache.flink.state.benchmark.StateBenchmarkConstants.mapKeyCount;
import static org.apache.flink.state.benchmark.StateBenchmarkConstants.mapKeys;
import static org.apache.flink.state.benchmark.StateBenchmarkConstants.mapValues;
import static org.apache.flink.state.benchmark.StateBenchmarkConstants.newKeyCount;
import static org.apache.flink.state.benchmark.StateBenchmarkConstants.newKeys;
import static org.apache.flink.state.benchmark.StateBenchmarkConstants.randomValueCount;
import static org.apache.flink.state.benchmark.StateBenchmarkConstants.randomValues;
import static org.apache.flink.state.benchmark.StateBenchmarkConstants.setupKeyCount;
import static org.apache.flink.state.benchmark.StateBenchmarkConstants.setupKeys;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.flink.state.benchmark;
/**
* Base implementation of the state benchmarks.
*/
public class StateBenchmarkBase extends BenchmarkBase {
KeyedStateBackend<Long> keyedStateBackend;
@Param({"HEAP", "ROCKSDB"})
protected StateBackendBenchmarkUtils.StateBackendType backendType;
final ThreadLocalRandom random = ThreadLocalRandom.current();
@TearDown
public void tearDown() throws IOException {
cleanUp(keyedStateBackend);
}
static AtomicInteger keyIndex;
private static int getCurrentIndex() {
int currentIndex = keyIndex.getAndIncrement();
if (currentIndex == Integer.MAX_VALUE) {
keyIndex.set(0);
}
return currentIndex;
}
@State(Scope.Thread)
public static class KeyValue {
@Setup(Level.Invocation)
public void kvSetup() {
int currentIndex = getCurrentIndex(); | setUpKey = setupKeys.get(currentIndex % setupKeyCount); |
dataArtisans/flink-benchmarks | src/main/java/org/apache/flink/state/benchmark/StateBenchmarkBase.java | // Path: src/main/java/org/apache/flink/benchmark/BenchmarkBase.java
// @SuppressWarnings("MethodMayBeStatic")
// @State(Thread)
// @OutputTimeUnit(MILLISECONDS)
// @BenchmarkMode(Throughput)
// @Fork(value = 3, jvmArgsAppend = {
// "-Djava.rmi.server.hostname=127.0.0.1",
// "-Dcom.sun.management.jmxremote.authenticate=false",
// "-Dcom.sun.management.jmxremote.ssl=false",
// "-Dcom.sun.management.jmxremote.ssl"})
// @Warmup(iterations = 10)
// @Measurement(iterations = 10)
// public class BenchmarkBase {
// }
//
// Path: src/main/java/org/apache/flink/state/benchmark/StateBenchmarkConstants.java
// static final int mapKeyCount = 10;
//
// Path: src/main/java/org/apache/flink/state/benchmark/StateBenchmarkConstants.java
// static final ArrayList<Long> mapKeys = new ArrayList<>(mapKeyCount);
//
// Path: src/main/java/org/apache/flink/state/benchmark/StateBenchmarkConstants.java
// static final ArrayList<Double> mapValues = new ArrayList<>(mapKeyCount);
//
// Path: src/main/java/org/apache/flink/state/benchmark/StateBenchmarkConstants.java
// static final int newKeyCount = 500_000;
//
// Path: src/main/java/org/apache/flink/state/benchmark/StateBenchmarkConstants.java
// static final ArrayList<Long> newKeys = new ArrayList<>(newKeyCount);
//
// Path: src/main/java/org/apache/flink/state/benchmark/StateBenchmarkConstants.java
// static final int randomValueCount = 1_000_000;
//
// Path: src/main/java/org/apache/flink/state/benchmark/StateBenchmarkConstants.java
// static final ArrayList<Long> randomValues = new ArrayList<>(randomValueCount);
//
// Path: src/main/java/org/apache/flink/state/benchmark/StateBenchmarkConstants.java
// static final int setupKeyCount = 500_000;
//
// Path: src/main/java/org/apache/flink/state/benchmark/StateBenchmarkConstants.java
// static final ArrayList<Long> setupKeys = new ArrayList<>(setupKeyCount);
| import org.apache.flink.benchmark.BenchmarkBase;
import org.apache.flink.contrib.streaming.state.benchmark.StateBackendBenchmarkUtils;
import org.apache.flink.runtime.state.KeyedStateBackend;
import org.openjdk.jmh.annotations.Level;
import org.openjdk.jmh.annotations.Param;
import org.openjdk.jmh.annotations.Scope;
import org.openjdk.jmh.annotations.Setup;
import org.openjdk.jmh.annotations.State;
import org.openjdk.jmh.annotations.TearDown;
import java.io.IOException;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.ThreadLocalRandom;
import java.util.concurrent.atomic.AtomicInteger;
import static org.apache.flink.contrib.streaming.state.benchmark.StateBackendBenchmarkUtils.cleanUp;
import static org.apache.flink.state.benchmark.StateBenchmarkConstants.mapKeyCount;
import static org.apache.flink.state.benchmark.StateBenchmarkConstants.mapKeys;
import static org.apache.flink.state.benchmark.StateBenchmarkConstants.mapValues;
import static org.apache.flink.state.benchmark.StateBenchmarkConstants.newKeyCount;
import static org.apache.flink.state.benchmark.StateBenchmarkConstants.newKeys;
import static org.apache.flink.state.benchmark.StateBenchmarkConstants.randomValueCount;
import static org.apache.flink.state.benchmark.StateBenchmarkConstants.randomValues;
import static org.apache.flink.state.benchmark.StateBenchmarkConstants.setupKeyCount;
import static org.apache.flink.state.benchmark.StateBenchmarkConstants.setupKeys; | /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.flink.state.benchmark;
/**
* Base implementation of the state benchmarks.
*/
public class StateBenchmarkBase extends BenchmarkBase {
KeyedStateBackend<Long> keyedStateBackend;
@Param({"HEAP", "ROCKSDB"})
protected StateBackendBenchmarkUtils.StateBackendType backendType;
final ThreadLocalRandom random = ThreadLocalRandom.current();
@TearDown
public void tearDown() throws IOException {
cleanUp(keyedStateBackend);
}
static AtomicInteger keyIndex;
private static int getCurrentIndex() {
int currentIndex = keyIndex.getAndIncrement();
if (currentIndex == Integer.MAX_VALUE) {
keyIndex.set(0);
}
return currentIndex;
}
@State(Scope.Thread)
public static class KeyValue {
@Setup(Level.Invocation)
public void kvSetup() {
int currentIndex = getCurrentIndex();
setUpKey = setupKeys.get(currentIndex % setupKeyCount); | // Path: src/main/java/org/apache/flink/benchmark/BenchmarkBase.java
// @SuppressWarnings("MethodMayBeStatic")
// @State(Thread)
// @OutputTimeUnit(MILLISECONDS)
// @BenchmarkMode(Throughput)
// @Fork(value = 3, jvmArgsAppend = {
// "-Djava.rmi.server.hostname=127.0.0.1",
// "-Dcom.sun.management.jmxremote.authenticate=false",
// "-Dcom.sun.management.jmxremote.ssl=false",
// "-Dcom.sun.management.jmxremote.ssl"})
// @Warmup(iterations = 10)
// @Measurement(iterations = 10)
// public class BenchmarkBase {
// }
//
// Path: src/main/java/org/apache/flink/state/benchmark/StateBenchmarkConstants.java
// static final int mapKeyCount = 10;
//
// Path: src/main/java/org/apache/flink/state/benchmark/StateBenchmarkConstants.java
// static final ArrayList<Long> mapKeys = new ArrayList<>(mapKeyCount);
//
// Path: src/main/java/org/apache/flink/state/benchmark/StateBenchmarkConstants.java
// static final ArrayList<Double> mapValues = new ArrayList<>(mapKeyCount);
//
// Path: src/main/java/org/apache/flink/state/benchmark/StateBenchmarkConstants.java
// static final int newKeyCount = 500_000;
//
// Path: src/main/java/org/apache/flink/state/benchmark/StateBenchmarkConstants.java
// static final ArrayList<Long> newKeys = new ArrayList<>(newKeyCount);
//
// Path: src/main/java/org/apache/flink/state/benchmark/StateBenchmarkConstants.java
// static final int randomValueCount = 1_000_000;
//
// Path: src/main/java/org/apache/flink/state/benchmark/StateBenchmarkConstants.java
// static final ArrayList<Long> randomValues = new ArrayList<>(randomValueCount);
//
// Path: src/main/java/org/apache/flink/state/benchmark/StateBenchmarkConstants.java
// static final int setupKeyCount = 500_000;
//
// Path: src/main/java/org/apache/flink/state/benchmark/StateBenchmarkConstants.java
// static final ArrayList<Long> setupKeys = new ArrayList<>(setupKeyCount);
// Path: src/main/java/org/apache/flink/state/benchmark/StateBenchmarkBase.java
import org.apache.flink.benchmark.BenchmarkBase;
import org.apache.flink.contrib.streaming.state.benchmark.StateBackendBenchmarkUtils;
import org.apache.flink.runtime.state.KeyedStateBackend;
import org.openjdk.jmh.annotations.Level;
import org.openjdk.jmh.annotations.Param;
import org.openjdk.jmh.annotations.Scope;
import org.openjdk.jmh.annotations.Setup;
import org.openjdk.jmh.annotations.State;
import org.openjdk.jmh.annotations.TearDown;
import java.io.IOException;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.ThreadLocalRandom;
import java.util.concurrent.atomic.AtomicInteger;
import static org.apache.flink.contrib.streaming.state.benchmark.StateBackendBenchmarkUtils.cleanUp;
import static org.apache.flink.state.benchmark.StateBenchmarkConstants.mapKeyCount;
import static org.apache.flink.state.benchmark.StateBenchmarkConstants.mapKeys;
import static org.apache.flink.state.benchmark.StateBenchmarkConstants.mapValues;
import static org.apache.flink.state.benchmark.StateBenchmarkConstants.newKeyCount;
import static org.apache.flink.state.benchmark.StateBenchmarkConstants.newKeys;
import static org.apache.flink.state.benchmark.StateBenchmarkConstants.randomValueCount;
import static org.apache.flink.state.benchmark.StateBenchmarkConstants.randomValues;
import static org.apache.flink.state.benchmark.StateBenchmarkConstants.setupKeyCount;
import static org.apache.flink.state.benchmark.StateBenchmarkConstants.setupKeys;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.flink.state.benchmark;
/**
* Base implementation of the state benchmarks.
*/
public class StateBenchmarkBase extends BenchmarkBase {
KeyedStateBackend<Long> keyedStateBackend;
@Param({"HEAP", "ROCKSDB"})
protected StateBackendBenchmarkUtils.StateBackendType backendType;
final ThreadLocalRandom random = ThreadLocalRandom.current();
@TearDown
public void tearDown() throws IOException {
cleanUp(keyedStateBackend);
}
static AtomicInteger keyIndex;
private static int getCurrentIndex() {
int currentIndex = keyIndex.getAndIncrement();
if (currentIndex == Integer.MAX_VALUE) {
keyIndex.set(0);
}
return currentIndex;
}
@State(Scope.Thread)
public static class KeyValue {
@Setup(Level.Invocation)
public void kvSetup() {
int currentIndex = getCurrentIndex();
setUpKey = setupKeys.get(currentIndex % setupKeyCount); | newKey = newKeys.get(currentIndex % newKeyCount); |
dataArtisans/flink-benchmarks | src/main/java/org/apache/flink/state/benchmark/StateBenchmarkBase.java | // Path: src/main/java/org/apache/flink/benchmark/BenchmarkBase.java
// @SuppressWarnings("MethodMayBeStatic")
// @State(Thread)
// @OutputTimeUnit(MILLISECONDS)
// @BenchmarkMode(Throughput)
// @Fork(value = 3, jvmArgsAppend = {
// "-Djava.rmi.server.hostname=127.0.0.1",
// "-Dcom.sun.management.jmxremote.authenticate=false",
// "-Dcom.sun.management.jmxremote.ssl=false",
// "-Dcom.sun.management.jmxremote.ssl"})
// @Warmup(iterations = 10)
// @Measurement(iterations = 10)
// public class BenchmarkBase {
// }
//
// Path: src/main/java/org/apache/flink/state/benchmark/StateBenchmarkConstants.java
// static final int mapKeyCount = 10;
//
// Path: src/main/java/org/apache/flink/state/benchmark/StateBenchmarkConstants.java
// static final ArrayList<Long> mapKeys = new ArrayList<>(mapKeyCount);
//
// Path: src/main/java/org/apache/flink/state/benchmark/StateBenchmarkConstants.java
// static final ArrayList<Double> mapValues = new ArrayList<>(mapKeyCount);
//
// Path: src/main/java/org/apache/flink/state/benchmark/StateBenchmarkConstants.java
// static final int newKeyCount = 500_000;
//
// Path: src/main/java/org/apache/flink/state/benchmark/StateBenchmarkConstants.java
// static final ArrayList<Long> newKeys = new ArrayList<>(newKeyCount);
//
// Path: src/main/java/org/apache/flink/state/benchmark/StateBenchmarkConstants.java
// static final int randomValueCount = 1_000_000;
//
// Path: src/main/java/org/apache/flink/state/benchmark/StateBenchmarkConstants.java
// static final ArrayList<Long> randomValues = new ArrayList<>(randomValueCount);
//
// Path: src/main/java/org/apache/flink/state/benchmark/StateBenchmarkConstants.java
// static final int setupKeyCount = 500_000;
//
// Path: src/main/java/org/apache/flink/state/benchmark/StateBenchmarkConstants.java
// static final ArrayList<Long> setupKeys = new ArrayList<>(setupKeyCount);
| import org.apache.flink.benchmark.BenchmarkBase;
import org.apache.flink.contrib.streaming.state.benchmark.StateBackendBenchmarkUtils;
import org.apache.flink.runtime.state.KeyedStateBackend;
import org.openjdk.jmh.annotations.Level;
import org.openjdk.jmh.annotations.Param;
import org.openjdk.jmh.annotations.Scope;
import org.openjdk.jmh.annotations.Setup;
import org.openjdk.jmh.annotations.State;
import org.openjdk.jmh.annotations.TearDown;
import java.io.IOException;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.ThreadLocalRandom;
import java.util.concurrent.atomic.AtomicInteger;
import static org.apache.flink.contrib.streaming.state.benchmark.StateBackendBenchmarkUtils.cleanUp;
import static org.apache.flink.state.benchmark.StateBenchmarkConstants.mapKeyCount;
import static org.apache.flink.state.benchmark.StateBenchmarkConstants.mapKeys;
import static org.apache.flink.state.benchmark.StateBenchmarkConstants.mapValues;
import static org.apache.flink.state.benchmark.StateBenchmarkConstants.newKeyCount;
import static org.apache.flink.state.benchmark.StateBenchmarkConstants.newKeys;
import static org.apache.flink.state.benchmark.StateBenchmarkConstants.randomValueCount;
import static org.apache.flink.state.benchmark.StateBenchmarkConstants.randomValues;
import static org.apache.flink.state.benchmark.StateBenchmarkConstants.setupKeyCount;
import static org.apache.flink.state.benchmark.StateBenchmarkConstants.setupKeys; | /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.flink.state.benchmark;
/**
* Base implementation of the state benchmarks.
*/
public class StateBenchmarkBase extends BenchmarkBase {
KeyedStateBackend<Long> keyedStateBackend;
@Param({"HEAP", "ROCKSDB"})
protected StateBackendBenchmarkUtils.StateBackendType backendType;
final ThreadLocalRandom random = ThreadLocalRandom.current();
@TearDown
public void tearDown() throws IOException {
cleanUp(keyedStateBackend);
}
static AtomicInteger keyIndex;
private static int getCurrentIndex() {
int currentIndex = keyIndex.getAndIncrement();
if (currentIndex == Integer.MAX_VALUE) {
keyIndex.set(0);
}
return currentIndex;
}
@State(Scope.Thread)
public static class KeyValue {
@Setup(Level.Invocation)
public void kvSetup() {
int currentIndex = getCurrentIndex();
setUpKey = setupKeys.get(currentIndex % setupKeyCount); | // Path: src/main/java/org/apache/flink/benchmark/BenchmarkBase.java
// @SuppressWarnings("MethodMayBeStatic")
// @State(Thread)
// @OutputTimeUnit(MILLISECONDS)
// @BenchmarkMode(Throughput)
// @Fork(value = 3, jvmArgsAppend = {
// "-Djava.rmi.server.hostname=127.0.0.1",
// "-Dcom.sun.management.jmxremote.authenticate=false",
// "-Dcom.sun.management.jmxremote.ssl=false",
// "-Dcom.sun.management.jmxremote.ssl"})
// @Warmup(iterations = 10)
// @Measurement(iterations = 10)
// public class BenchmarkBase {
// }
//
// Path: src/main/java/org/apache/flink/state/benchmark/StateBenchmarkConstants.java
// static final int mapKeyCount = 10;
//
// Path: src/main/java/org/apache/flink/state/benchmark/StateBenchmarkConstants.java
// static final ArrayList<Long> mapKeys = new ArrayList<>(mapKeyCount);
//
// Path: src/main/java/org/apache/flink/state/benchmark/StateBenchmarkConstants.java
// static final ArrayList<Double> mapValues = new ArrayList<>(mapKeyCount);
//
// Path: src/main/java/org/apache/flink/state/benchmark/StateBenchmarkConstants.java
// static final int newKeyCount = 500_000;
//
// Path: src/main/java/org/apache/flink/state/benchmark/StateBenchmarkConstants.java
// static final ArrayList<Long> newKeys = new ArrayList<>(newKeyCount);
//
// Path: src/main/java/org/apache/flink/state/benchmark/StateBenchmarkConstants.java
// static final int randomValueCount = 1_000_000;
//
// Path: src/main/java/org/apache/flink/state/benchmark/StateBenchmarkConstants.java
// static final ArrayList<Long> randomValues = new ArrayList<>(randomValueCount);
//
// Path: src/main/java/org/apache/flink/state/benchmark/StateBenchmarkConstants.java
// static final int setupKeyCount = 500_000;
//
// Path: src/main/java/org/apache/flink/state/benchmark/StateBenchmarkConstants.java
// static final ArrayList<Long> setupKeys = new ArrayList<>(setupKeyCount);
// Path: src/main/java/org/apache/flink/state/benchmark/StateBenchmarkBase.java
import org.apache.flink.benchmark.BenchmarkBase;
import org.apache.flink.contrib.streaming.state.benchmark.StateBackendBenchmarkUtils;
import org.apache.flink.runtime.state.KeyedStateBackend;
import org.openjdk.jmh.annotations.Level;
import org.openjdk.jmh.annotations.Param;
import org.openjdk.jmh.annotations.Scope;
import org.openjdk.jmh.annotations.Setup;
import org.openjdk.jmh.annotations.State;
import org.openjdk.jmh.annotations.TearDown;
import java.io.IOException;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.ThreadLocalRandom;
import java.util.concurrent.atomic.AtomicInteger;
import static org.apache.flink.contrib.streaming.state.benchmark.StateBackendBenchmarkUtils.cleanUp;
import static org.apache.flink.state.benchmark.StateBenchmarkConstants.mapKeyCount;
import static org.apache.flink.state.benchmark.StateBenchmarkConstants.mapKeys;
import static org.apache.flink.state.benchmark.StateBenchmarkConstants.mapValues;
import static org.apache.flink.state.benchmark.StateBenchmarkConstants.newKeyCount;
import static org.apache.flink.state.benchmark.StateBenchmarkConstants.newKeys;
import static org.apache.flink.state.benchmark.StateBenchmarkConstants.randomValueCount;
import static org.apache.flink.state.benchmark.StateBenchmarkConstants.randomValues;
import static org.apache.flink.state.benchmark.StateBenchmarkConstants.setupKeyCount;
import static org.apache.flink.state.benchmark.StateBenchmarkConstants.setupKeys;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.flink.state.benchmark;
/**
* Base implementation of the state benchmarks.
*/
public class StateBenchmarkBase extends BenchmarkBase {
KeyedStateBackend<Long> keyedStateBackend;
@Param({"HEAP", "ROCKSDB"})
protected StateBackendBenchmarkUtils.StateBackendType backendType;
final ThreadLocalRandom random = ThreadLocalRandom.current();
@TearDown
public void tearDown() throws IOException {
cleanUp(keyedStateBackend);
}
static AtomicInteger keyIndex;
private static int getCurrentIndex() {
int currentIndex = keyIndex.getAndIncrement();
if (currentIndex == Integer.MAX_VALUE) {
keyIndex.set(0);
}
return currentIndex;
}
@State(Scope.Thread)
public static class KeyValue {
@Setup(Level.Invocation)
public void kvSetup() {
int currentIndex = getCurrentIndex();
setUpKey = setupKeys.get(currentIndex % setupKeyCount); | newKey = newKeys.get(currentIndex % newKeyCount); |
dataArtisans/flink-benchmarks | src/main/java/org/apache/flink/state/benchmark/StateBenchmarkBase.java | // Path: src/main/java/org/apache/flink/benchmark/BenchmarkBase.java
// @SuppressWarnings("MethodMayBeStatic")
// @State(Thread)
// @OutputTimeUnit(MILLISECONDS)
// @BenchmarkMode(Throughput)
// @Fork(value = 3, jvmArgsAppend = {
// "-Djava.rmi.server.hostname=127.0.0.1",
// "-Dcom.sun.management.jmxremote.authenticate=false",
// "-Dcom.sun.management.jmxremote.ssl=false",
// "-Dcom.sun.management.jmxremote.ssl"})
// @Warmup(iterations = 10)
// @Measurement(iterations = 10)
// public class BenchmarkBase {
// }
//
// Path: src/main/java/org/apache/flink/state/benchmark/StateBenchmarkConstants.java
// static final int mapKeyCount = 10;
//
// Path: src/main/java/org/apache/flink/state/benchmark/StateBenchmarkConstants.java
// static final ArrayList<Long> mapKeys = new ArrayList<>(mapKeyCount);
//
// Path: src/main/java/org/apache/flink/state/benchmark/StateBenchmarkConstants.java
// static final ArrayList<Double> mapValues = new ArrayList<>(mapKeyCount);
//
// Path: src/main/java/org/apache/flink/state/benchmark/StateBenchmarkConstants.java
// static final int newKeyCount = 500_000;
//
// Path: src/main/java/org/apache/flink/state/benchmark/StateBenchmarkConstants.java
// static final ArrayList<Long> newKeys = new ArrayList<>(newKeyCount);
//
// Path: src/main/java/org/apache/flink/state/benchmark/StateBenchmarkConstants.java
// static final int randomValueCount = 1_000_000;
//
// Path: src/main/java/org/apache/flink/state/benchmark/StateBenchmarkConstants.java
// static final ArrayList<Long> randomValues = new ArrayList<>(randomValueCount);
//
// Path: src/main/java/org/apache/flink/state/benchmark/StateBenchmarkConstants.java
// static final int setupKeyCount = 500_000;
//
// Path: src/main/java/org/apache/flink/state/benchmark/StateBenchmarkConstants.java
// static final ArrayList<Long> setupKeys = new ArrayList<>(setupKeyCount);
| import org.apache.flink.benchmark.BenchmarkBase;
import org.apache.flink.contrib.streaming.state.benchmark.StateBackendBenchmarkUtils;
import org.apache.flink.runtime.state.KeyedStateBackend;
import org.openjdk.jmh.annotations.Level;
import org.openjdk.jmh.annotations.Param;
import org.openjdk.jmh.annotations.Scope;
import org.openjdk.jmh.annotations.Setup;
import org.openjdk.jmh.annotations.State;
import org.openjdk.jmh.annotations.TearDown;
import java.io.IOException;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.ThreadLocalRandom;
import java.util.concurrent.atomic.AtomicInteger;
import static org.apache.flink.contrib.streaming.state.benchmark.StateBackendBenchmarkUtils.cleanUp;
import static org.apache.flink.state.benchmark.StateBenchmarkConstants.mapKeyCount;
import static org.apache.flink.state.benchmark.StateBenchmarkConstants.mapKeys;
import static org.apache.flink.state.benchmark.StateBenchmarkConstants.mapValues;
import static org.apache.flink.state.benchmark.StateBenchmarkConstants.newKeyCount;
import static org.apache.flink.state.benchmark.StateBenchmarkConstants.newKeys;
import static org.apache.flink.state.benchmark.StateBenchmarkConstants.randomValueCount;
import static org.apache.flink.state.benchmark.StateBenchmarkConstants.randomValues;
import static org.apache.flink.state.benchmark.StateBenchmarkConstants.setupKeyCount;
import static org.apache.flink.state.benchmark.StateBenchmarkConstants.setupKeys; | /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.flink.state.benchmark;
/**
* Base implementation of the state benchmarks.
*/
public class StateBenchmarkBase extends BenchmarkBase {
KeyedStateBackend<Long> keyedStateBackend;
@Param({"HEAP", "ROCKSDB"})
protected StateBackendBenchmarkUtils.StateBackendType backendType;
final ThreadLocalRandom random = ThreadLocalRandom.current();
@TearDown
public void tearDown() throws IOException {
cleanUp(keyedStateBackend);
}
static AtomicInteger keyIndex;
private static int getCurrentIndex() {
int currentIndex = keyIndex.getAndIncrement();
if (currentIndex == Integer.MAX_VALUE) {
keyIndex.set(0);
}
return currentIndex;
}
@State(Scope.Thread)
public static class KeyValue {
@Setup(Level.Invocation)
public void kvSetup() {
int currentIndex = getCurrentIndex();
setUpKey = setupKeys.get(currentIndex % setupKeyCount);
newKey = newKeys.get(currentIndex % newKeyCount); | // Path: src/main/java/org/apache/flink/benchmark/BenchmarkBase.java
// @SuppressWarnings("MethodMayBeStatic")
// @State(Thread)
// @OutputTimeUnit(MILLISECONDS)
// @BenchmarkMode(Throughput)
// @Fork(value = 3, jvmArgsAppend = {
// "-Djava.rmi.server.hostname=127.0.0.1",
// "-Dcom.sun.management.jmxremote.authenticate=false",
// "-Dcom.sun.management.jmxremote.ssl=false",
// "-Dcom.sun.management.jmxremote.ssl"})
// @Warmup(iterations = 10)
// @Measurement(iterations = 10)
// public class BenchmarkBase {
// }
//
// Path: src/main/java/org/apache/flink/state/benchmark/StateBenchmarkConstants.java
// static final int mapKeyCount = 10;
//
// Path: src/main/java/org/apache/flink/state/benchmark/StateBenchmarkConstants.java
// static final ArrayList<Long> mapKeys = new ArrayList<>(mapKeyCount);
//
// Path: src/main/java/org/apache/flink/state/benchmark/StateBenchmarkConstants.java
// static final ArrayList<Double> mapValues = new ArrayList<>(mapKeyCount);
//
// Path: src/main/java/org/apache/flink/state/benchmark/StateBenchmarkConstants.java
// static final int newKeyCount = 500_000;
//
// Path: src/main/java/org/apache/flink/state/benchmark/StateBenchmarkConstants.java
// static final ArrayList<Long> newKeys = new ArrayList<>(newKeyCount);
//
// Path: src/main/java/org/apache/flink/state/benchmark/StateBenchmarkConstants.java
// static final int randomValueCount = 1_000_000;
//
// Path: src/main/java/org/apache/flink/state/benchmark/StateBenchmarkConstants.java
// static final ArrayList<Long> randomValues = new ArrayList<>(randomValueCount);
//
// Path: src/main/java/org/apache/flink/state/benchmark/StateBenchmarkConstants.java
// static final int setupKeyCount = 500_000;
//
// Path: src/main/java/org/apache/flink/state/benchmark/StateBenchmarkConstants.java
// static final ArrayList<Long> setupKeys = new ArrayList<>(setupKeyCount);
// Path: src/main/java/org/apache/flink/state/benchmark/StateBenchmarkBase.java
import org.apache.flink.benchmark.BenchmarkBase;
import org.apache.flink.contrib.streaming.state.benchmark.StateBackendBenchmarkUtils;
import org.apache.flink.runtime.state.KeyedStateBackend;
import org.openjdk.jmh.annotations.Level;
import org.openjdk.jmh.annotations.Param;
import org.openjdk.jmh.annotations.Scope;
import org.openjdk.jmh.annotations.Setup;
import org.openjdk.jmh.annotations.State;
import org.openjdk.jmh.annotations.TearDown;
import java.io.IOException;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.ThreadLocalRandom;
import java.util.concurrent.atomic.AtomicInteger;
import static org.apache.flink.contrib.streaming.state.benchmark.StateBackendBenchmarkUtils.cleanUp;
import static org.apache.flink.state.benchmark.StateBenchmarkConstants.mapKeyCount;
import static org.apache.flink.state.benchmark.StateBenchmarkConstants.mapKeys;
import static org.apache.flink.state.benchmark.StateBenchmarkConstants.mapValues;
import static org.apache.flink.state.benchmark.StateBenchmarkConstants.newKeyCount;
import static org.apache.flink.state.benchmark.StateBenchmarkConstants.newKeys;
import static org.apache.flink.state.benchmark.StateBenchmarkConstants.randomValueCount;
import static org.apache.flink.state.benchmark.StateBenchmarkConstants.randomValues;
import static org.apache.flink.state.benchmark.StateBenchmarkConstants.setupKeyCount;
import static org.apache.flink.state.benchmark.StateBenchmarkConstants.setupKeys;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.flink.state.benchmark;
/**
* Base implementation of the state benchmarks.
*/
public class StateBenchmarkBase extends BenchmarkBase {
KeyedStateBackend<Long> keyedStateBackend;
@Param({"HEAP", "ROCKSDB"})
protected StateBackendBenchmarkUtils.StateBackendType backendType;
final ThreadLocalRandom random = ThreadLocalRandom.current();
@TearDown
public void tearDown() throws IOException {
cleanUp(keyedStateBackend);
}
static AtomicInteger keyIndex;
private static int getCurrentIndex() {
int currentIndex = keyIndex.getAndIncrement();
if (currentIndex == Integer.MAX_VALUE) {
keyIndex.set(0);
}
return currentIndex;
}
@State(Scope.Thread)
public static class KeyValue {
@Setup(Level.Invocation)
public void kvSetup() {
int currentIndex = getCurrentIndex();
setUpKey = setupKeys.get(currentIndex % setupKeyCount);
newKey = newKeys.get(currentIndex % newKeyCount); | mapKey = mapKeys.get(currentIndex % mapKeyCount); |
dataArtisans/flink-benchmarks | src/main/java/org/apache/flink/state/benchmark/StateBenchmarkBase.java | // Path: src/main/java/org/apache/flink/benchmark/BenchmarkBase.java
// @SuppressWarnings("MethodMayBeStatic")
// @State(Thread)
// @OutputTimeUnit(MILLISECONDS)
// @BenchmarkMode(Throughput)
// @Fork(value = 3, jvmArgsAppend = {
// "-Djava.rmi.server.hostname=127.0.0.1",
// "-Dcom.sun.management.jmxremote.authenticate=false",
// "-Dcom.sun.management.jmxremote.ssl=false",
// "-Dcom.sun.management.jmxremote.ssl"})
// @Warmup(iterations = 10)
// @Measurement(iterations = 10)
// public class BenchmarkBase {
// }
//
// Path: src/main/java/org/apache/flink/state/benchmark/StateBenchmarkConstants.java
// static final int mapKeyCount = 10;
//
// Path: src/main/java/org/apache/flink/state/benchmark/StateBenchmarkConstants.java
// static final ArrayList<Long> mapKeys = new ArrayList<>(mapKeyCount);
//
// Path: src/main/java/org/apache/flink/state/benchmark/StateBenchmarkConstants.java
// static final ArrayList<Double> mapValues = new ArrayList<>(mapKeyCount);
//
// Path: src/main/java/org/apache/flink/state/benchmark/StateBenchmarkConstants.java
// static final int newKeyCount = 500_000;
//
// Path: src/main/java/org/apache/flink/state/benchmark/StateBenchmarkConstants.java
// static final ArrayList<Long> newKeys = new ArrayList<>(newKeyCount);
//
// Path: src/main/java/org/apache/flink/state/benchmark/StateBenchmarkConstants.java
// static final int randomValueCount = 1_000_000;
//
// Path: src/main/java/org/apache/flink/state/benchmark/StateBenchmarkConstants.java
// static final ArrayList<Long> randomValues = new ArrayList<>(randomValueCount);
//
// Path: src/main/java/org/apache/flink/state/benchmark/StateBenchmarkConstants.java
// static final int setupKeyCount = 500_000;
//
// Path: src/main/java/org/apache/flink/state/benchmark/StateBenchmarkConstants.java
// static final ArrayList<Long> setupKeys = new ArrayList<>(setupKeyCount);
| import org.apache.flink.benchmark.BenchmarkBase;
import org.apache.flink.contrib.streaming.state.benchmark.StateBackendBenchmarkUtils;
import org.apache.flink.runtime.state.KeyedStateBackend;
import org.openjdk.jmh.annotations.Level;
import org.openjdk.jmh.annotations.Param;
import org.openjdk.jmh.annotations.Scope;
import org.openjdk.jmh.annotations.Setup;
import org.openjdk.jmh.annotations.State;
import org.openjdk.jmh.annotations.TearDown;
import java.io.IOException;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.ThreadLocalRandom;
import java.util.concurrent.atomic.AtomicInteger;
import static org.apache.flink.contrib.streaming.state.benchmark.StateBackendBenchmarkUtils.cleanUp;
import static org.apache.flink.state.benchmark.StateBenchmarkConstants.mapKeyCount;
import static org.apache.flink.state.benchmark.StateBenchmarkConstants.mapKeys;
import static org.apache.flink.state.benchmark.StateBenchmarkConstants.mapValues;
import static org.apache.flink.state.benchmark.StateBenchmarkConstants.newKeyCount;
import static org.apache.flink.state.benchmark.StateBenchmarkConstants.newKeys;
import static org.apache.flink.state.benchmark.StateBenchmarkConstants.randomValueCount;
import static org.apache.flink.state.benchmark.StateBenchmarkConstants.randomValues;
import static org.apache.flink.state.benchmark.StateBenchmarkConstants.setupKeyCount;
import static org.apache.flink.state.benchmark.StateBenchmarkConstants.setupKeys; | /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.flink.state.benchmark;
/**
* Base implementation of the state benchmarks.
*/
public class StateBenchmarkBase extends BenchmarkBase {
KeyedStateBackend<Long> keyedStateBackend;
@Param({"HEAP", "ROCKSDB"})
protected StateBackendBenchmarkUtils.StateBackendType backendType;
final ThreadLocalRandom random = ThreadLocalRandom.current();
@TearDown
public void tearDown() throws IOException {
cleanUp(keyedStateBackend);
}
static AtomicInteger keyIndex;
private static int getCurrentIndex() {
int currentIndex = keyIndex.getAndIncrement();
if (currentIndex == Integer.MAX_VALUE) {
keyIndex.set(0);
}
return currentIndex;
}
@State(Scope.Thread)
public static class KeyValue {
@Setup(Level.Invocation)
public void kvSetup() {
int currentIndex = getCurrentIndex();
setUpKey = setupKeys.get(currentIndex % setupKeyCount);
newKey = newKeys.get(currentIndex % newKeyCount); | // Path: src/main/java/org/apache/flink/benchmark/BenchmarkBase.java
// @SuppressWarnings("MethodMayBeStatic")
// @State(Thread)
// @OutputTimeUnit(MILLISECONDS)
// @BenchmarkMode(Throughput)
// @Fork(value = 3, jvmArgsAppend = {
// "-Djava.rmi.server.hostname=127.0.0.1",
// "-Dcom.sun.management.jmxremote.authenticate=false",
// "-Dcom.sun.management.jmxremote.ssl=false",
// "-Dcom.sun.management.jmxremote.ssl"})
// @Warmup(iterations = 10)
// @Measurement(iterations = 10)
// public class BenchmarkBase {
// }
//
// Path: src/main/java/org/apache/flink/state/benchmark/StateBenchmarkConstants.java
// static final int mapKeyCount = 10;
//
// Path: src/main/java/org/apache/flink/state/benchmark/StateBenchmarkConstants.java
// static final ArrayList<Long> mapKeys = new ArrayList<>(mapKeyCount);
//
// Path: src/main/java/org/apache/flink/state/benchmark/StateBenchmarkConstants.java
// static final ArrayList<Double> mapValues = new ArrayList<>(mapKeyCount);
//
// Path: src/main/java/org/apache/flink/state/benchmark/StateBenchmarkConstants.java
// static final int newKeyCount = 500_000;
//
// Path: src/main/java/org/apache/flink/state/benchmark/StateBenchmarkConstants.java
// static final ArrayList<Long> newKeys = new ArrayList<>(newKeyCount);
//
// Path: src/main/java/org/apache/flink/state/benchmark/StateBenchmarkConstants.java
// static final int randomValueCount = 1_000_000;
//
// Path: src/main/java/org/apache/flink/state/benchmark/StateBenchmarkConstants.java
// static final ArrayList<Long> randomValues = new ArrayList<>(randomValueCount);
//
// Path: src/main/java/org/apache/flink/state/benchmark/StateBenchmarkConstants.java
// static final int setupKeyCount = 500_000;
//
// Path: src/main/java/org/apache/flink/state/benchmark/StateBenchmarkConstants.java
// static final ArrayList<Long> setupKeys = new ArrayList<>(setupKeyCount);
// Path: src/main/java/org/apache/flink/state/benchmark/StateBenchmarkBase.java
import org.apache.flink.benchmark.BenchmarkBase;
import org.apache.flink.contrib.streaming.state.benchmark.StateBackendBenchmarkUtils;
import org.apache.flink.runtime.state.KeyedStateBackend;
import org.openjdk.jmh.annotations.Level;
import org.openjdk.jmh.annotations.Param;
import org.openjdk.jmh.annotations.Scope;
import org.openjdk.jmh.annotations.Setup;
import org.openjdk.jmh.annotations.State;
import org.openjdk.jmh.annotations.TearDown;
import java.io.IOException;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.ThreadLocalRandom;
import java.util.concurrent.atomic.AtomicInteger;
import static org.apache.flink.contrib.streaming.state.benchmark.StateBackendBenchmarkUtils.cleanUp;
import static org.apache.flink.state.benchmark.StateBenchmarkConstants.mapKeyCount;
import static org.apache.flink.state.benchmark.StateBenchmarkConstants.mapKeys;
import static org.apache.flink.state.benchmark.StateBenchmarkConstants.mapValues;
import static org.apache.flink.state.benchmark.StateBenchmarkConstants.newKeyCount;
import static org.apache.flink.state.benchmark.StateBenchmarkConstants.newKeys;
import static org.apache.flink.state.benchmark.StateBenchmarkConstants.randomValueCount;
import static org.apache.flink.state.benchmark.StateBenchmarkConstants.randomValues;
import static org.apache.flink.state.benchmark.StateBenchmarkConstants.setupKeyCount;
import static org.apache.flink.state.benchmark.StateBenchmarkConstants.setupKeys;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.flink.state.benchmark;
/**
* Base implementation of the state benchmarks.
*/
public class StateBenchmarkBase extends BenchmarkBase {
KeyedStateBackend<Long> keyedStateBackend;
@Param({"HEAP", "ROCKSDB"})
protected StateBackendBenchmarkUtils.StateBackendType backendType;
final ThreadLocalRandom random = ThreadLocalRandom.current();
@TearDown
public void tearDown() throws IOException {
cleanUp(keyedStateBackend);
}
static AtomicInteger keyIndex;
private static int getCurrentIndex() {
int currentIndex = keyIndex.getAndIncrement();
if (currentIndex == Integer.MAX_VALUE) {
keyIndex.set(0);
}
return currentIndex;
}
@State(Scope.Thread)
public static class KeyValue {
@Setup(Level.Invocation)
public void kvSetup() {
int currentIndex = getCurrentIndex();
setUpKey = setupKeys.get(currentIndex % setupKeyCount);
newKey = newKeys.get(currentIndex % newKeyCount); | mapKey = mapKeys.get(currentIndex % mapKeyCount); |
dataArtisans/flink-benchmarks | src/main/java/org/apache/flink/state/benchmark/StateBenchmarkBase.java | // Path: src/main/java/org/apache/flink/benchmark/BenchmarkBase.java
// @SuppressWarnings("MethodMayBeStatic")
// @State(Thread)
// @OutputTimeUnit(MILLISECONDS)
// @BenchmarkMode(Throughput)
// @Fork(value = 3, jvmArgsAppend = {
// "-Djava.rmi.server.hostname=127.0.0.1",
// "-Dcom.sun.management.jmxremote.authenticate=false",
// "-Dcom.sun.management.jmxremote.ssl=false",
// "-Dcom.sun.management.jmxremote.ssl"})
// @Warmup(iterations = 10)
// @Measurement(iterations = 10)
// public class BenchmarkBase {
// }
//
// Path: src/main/java/org/apache/flink/state/benchmark/StateBenchmarkConstants.java
// static final int mapKeyCount = 10;
//
// Path: src/main/java/org/apache/flink/state/benchmark/StateBenchmarkConstants.java
// static final ArrayList<Long> mapKeys = new ArrayList<>(mapKeyCount);
//
// Path: src/main/java/org/apache/flink/state/benchmark/StateBenchmarkConstants.java
// static final ArrayList<Double> mapValues = new ArrayList<>(mapKeyCount);
//
// Path: src/main/java/org/apache/flink/state/benchmark/StateBenchmarkConstants.java
// static final int newKeyCount = 500_000;
//
// Path: src/main/java/org/apache/flink/state/benchmark/StateBenchmarkConstants.java
// static final ArrayList<Long> newKeys = new ArrayList<>(newKeyCount);
//
// Path: src/main/java/org/apache/flink/state/benchmark/StateBenchmarkConstants.java
// static final int randomValueCount = 1_000_000;
//
// Path: src/main/java/org/apache/flink/state/benchmark/StateBenchmarkConstants.java
// static final ArrayList<Long> randomValues = new ArrayList<>(randomValueCount);
//
// Path: src/main/java/org/apache/flink/state/benchmark/StateBenchmarkConstants.java
// static final int setupKeyCount = 500_000;
//
// Path: src/main/java/org/apache/flink/state/benchmark/StateBenchmarkConstants.java
// static final ArrayList<Long> setupKeys = new ArrayList<>(setupKeyCount);
| import org.apache.flink.benchmark.BenchmarkBase;
import org.apache.flink.contrib.streaming.state.benchmark.StateBackendBenchmarkUtils;
import org.apache.flink.runtime.state.KeyedStateBackend;
import org.openjdk.jmh.annotations.Level;
import org.openjdk.jmh.annotations.Param;
import org.openjdk.jmh.annotations.Scope;
import org.openjdk.jmh.annotations.Setup;
import org.openjdk.jmh.annotations.State;
import org.openjdk.jmh.annotations.TearDown;
import java.io.IOException;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.ThreadLocalRandom;
import java.util.concurrent.atomic.AtomicInteger;
import static org.apache.flink.contrib.streaming.state.benchmark.StateBackendBenchmarkUtils.cleanUp;
import static org.apache.flink.state.benchmark.StateBenchmarkConstants.mapKeyCount;
import static org.apache.flink.state.benchmark.StateBenchmarkConstants.mapKeys;
import static org.apache.flink.state.benchmark.StateBenchmarkConstants.mapValues;
import static org.apache.flink.state.benchmark.StateBenchmarkConstants.newKeyCount;
import static org.apache.flink.state.benchmark.StateBenchmarkConstants.newKeys;
import static org.apache.flink.state.benchmark.StateBenchmarkConstants.randomValueCount;
import static org.apache.flink.state.benchmark.StateBenchmarkConstants.randomValues;
import static org.apache.flink.state.benchmark.StateBenchmarkConstants.setupKeyCount;
import static org.apache.flink.state.benchmark.StateBenchmarkConstants.setupKeys; | /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.flink.state.benchmark;
/**
* Base implementation of the state benchmarks.
*/
public class StateBenchmarkBase extends BenchmarkBase {
KeyedStateBackend<Long> keyedStateBackend;
@Param({"HEAP", "ROCKSDB"})
protected StateBackendBenchmarkUtils.StateBackendType backendType;
final ThreadLocalRandom random = ThreadLocalRandom.current();
@TearDown
public void tearDown() throws IOException {
cleanUp(keyedStateBackend);
}
static AtomicInteger keyIndex;
private static int getCurrentIndex() {
int currentIndex = keyIndex.getAndIncrement();
if (currentIndex == Integer.MAX_VALUE) {
keyIndex.set(0);
}
return currentIndex;
}
@State(Scope.Thread)
public static class KeyValue {
@Setup(Level.Invocation)
public void kvSetup() {
int currentIndex = getCurrentIndex();
setUpKey = setupKeys.get(currentIndex % setupKeyCount);
newKey = newKeys.get(currentIndex % newKeyCount);
mapKey = mapKeys.get(currentIndex % mapKeyCount); | // Path: src/main/java/org/apache/flink/benchmark/BenchmarkBase.java
// @SuppressWarnings("MethodMayBeStatic")
// @State(Thread)
// @OutputTimeUnit(MILLISECONDS)
// @BenchmarkMode(Throughput)
// @Fork(value = 3, jvmArgsAppend = {
// "-Djava.rmi.server.hostname=127.0.0.1",
// "-Dcom.sun.management.jmxremote.authenticate=false",
// "-Dcom.sun.management.jmxremote.ssl=false",
// "-Dcom.sun.management.jmxremote.ssl"})
// @Warmup(iterations = 10)
// @Measurement(iterations = 10)
// public class BenchmarkBase {
// }
//
// Path: src/main/java/org/apache/flink/state/benchmark/StateBenchmarkConstants.java
// static final int mapKeyCount = 10;
//
// Path: src/main/java/org/apache/flink/state/benchmark/StateBenchmarkConstants.java
// static final ArrayList<Long> mapKeys = new ArrayList<>(mapKeyCount);
//
// Path: src/main/java/org/apache/flink/state/benchmark/StateBenchmarkConstants.java
// static final ArrayList<Double> mapValues = new ArrayList<>(mapKeyCount);
//
// Path: src/main/java/org/apache/flink/state/benchmark/StateBenchmarkConstants.java
// static final int newKeyCount = 500_000;
//
// Path: src/main/java/org/apache/flink/state/benchmark/StateBenchmarkConstants.java
// static final ArrayList<Long> newKeys = new ArrayList<>(newKeyCount);
//
// Path: src/main/java/org/apache/flink/state/benchmark/StateBenchmarkConstants.java
// static final int randomValueCount = 1_000_000;
//
// Path: src/main/java/org/apache/flink/state/benchmark/StateBenchmarkConstants.java
// static final ArrayList<Long> randomValues = new ArrayList<>(randomValueCount);
//
// Path: src/main/java/org/apache/flink/state/benchmark/StateBenchmarkConstants.java
// static final int setupKeyCount = 500_000;
//
// Path: src/main/java/org/apache/flink/state/benchmark/StateBenchmarkConstants.java
// static final ArrayList<Long> setupKeys = new ArrayList<>(setupKeyCount);
// Path: src/main/java/org/apache/flink/state/benchmark/StateBenchmarkBase.java
import org.apache.flink.benchmark.BenchmarkBase;
import org.apache.flink.contrib.streaming.state.benchmark.StateBackendBenchmarkUtils;
import org.apache.flink.runtime.state.KeyedStateBackend;
import org.openjdk.jmh.annotations.Level;
import org.openjdk.jmh.annotations.Param;
import org.openjdk.jmh.annotations.Scope;
import org.openjdk.jmh.annotations.Setup;
import org.openjdk.jmh.annotations.State;
import org.openjdk.jmh.annotations.TearDown;
import java.io.IOException;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.ThreadLocalRandom;
import java.util.concurrent.atomic.AtomicInteger;
import static org.apache.flink.contrib.streaming.state.benchmark.StateBackendBenchmarkUtils.cleanUp;
import static org.apache.flink.state.benchmark.StateBenchmarkConstants.mapKeyCount;
import static org.apache.flink.state.benchmark.StateBenchmarkConstants.mapKeys;
import static org.apache.flink.state.benchmark.StateBenchmarkConstants.mapValues;
import static org.apache.flink.state.benchmark.StateBenchmarkConstants.newKeyCount;
import static org.apache.flink.state.benchmark.StateBenchmarkConstants.newKeys;
import static org.apache.flink.state.benchmark.StateBenchmarkConstants.randomValueCount;
import static org.apache.flink.state.benchmark.StateBenchmarkConstants.randomValues;
import static org.apache.flink.state.benchmark.StateBenchmarkConstants.setupKeyCount;
import static org.apache.flink.state.benchmark.StateBenchmarkConstants.setupKeys;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.flink.state.benchmark;
/**
* Base implementation of the state benchmarks.
*/
public class StateBenchmarkBase extends BenchmarkBase {
KeyedStateBackend<Long> keyedStateBackend;
@Param({"HEAP", "ROCKSDB"})
protected StateBackendBenchmarkUtils.StateBackendType backendType;
final ThreadLocalRandom random = ThreadLocalRandom.current();
@TearDown
public void tearDown() throws IOException {
cleanUp(keyedStateBackend);
}
static AtomicInteger keyIndex;
private static int getCurrentIndex() {
int currentIndex = keyIndex.getAndIncrement();
if (currentIndex == Integer.MAX_VALUE) {
keyIndex.set(0);
}
return currentIndex;
}
@State(Scope.Thread)
public static class KeyValue {
@Setup(Level.Invocation)
public void kvSetup() {
int currentIndex = getCurrentIndex();
setUpKey = setupKeys.get(currentIndex % setupKeyCount);
newKey = newKeys.get(currentIndex % newKeyCount);
mapKey = mapKeys.get(currentIndex % mapKeyCount); | mapValue = mapValues.get(currentIndex % mapKeyCount); |
dataArtisans/flink-benchmarks | src/main/java/org/apache/flink/state/benchmark/StateBenchmarkBase.java | // Path: src/main/java/org/apache/flink/benchmark/BenchmarkBase.java
// @SuppressWarnings("MethodMayBeStatic")
// @State(Thread)
// @OutputTimeUnit(MILLISECONDS)
// @BenchmarkMode(Throughput)
// @Fork(value = 3, jvmArgsAppend = {
// "-Djava.rmi.server.hostname=127.0.0.1",
// "-Dcom.sun.management.jmxremote.authenticate=false",
// "-Dcom.sun.management.jmxremote.ssl=false",
// "-Dcom.sun.management.jmxremote.ssl"})
// @Warmup(iterations = 10)
// @Measurement(iterations = 10)
// public class BenchmarkBase {
// }
//
// Path: src/main/java/org/apache/flink/state/benchmark/StateBenchmarkConstants.java
// static final int mapKeyCount = 10;
//
// Path: src/main/java/org/apache/flink/state/benchmark/StateBenchmarkConstants.java
// static final ArrayList<Long> mapKeys = new ArrayList<>(mapKeyCount);
//
// Path: src/main/java/org/apache/flink/state/benchmark/StateBenchmarkConstants.java
// static final ArrayList<Double> mapValues = new ArrayList<>(mapKeyCount);
//
// Path: src/main/java/org/apache/flink/state/benchmark/StateBenchmarkConstants.java
// static final int newKeyCount = 500_000;
//
// Path: src/main/java/org/apache/flink/state/benchmark/StateBenchmarkConstants.java
// static final ArrayList<Long> newKeys = new ArrayList<>(newKeyCount);
//
// Path: src/main/java/org/apache/flink/state/benchmark/StateBenchmarkConstants.java
// static final int randomValueCount = 1_000_000;
//
// Path: src/main/java/org/apache/flink/state/benchmark/StateBenchmarkConstants.java
// static final ArrayList<Long> randomValues = new ArrayList<>(randomValueCount);
//
// Path: src/main/java/org/apache/flink/state/benchmark/StateBenchmarkConstants.java
// static final int setupKeyCount = 500_000;
//
// Path: src/main/java/org/apache/flink/state/benchmark/StateBenchmarkConstants.java
// static final ArrayList<Long> setupKeys = new ArrayList<>(setupKeyCount);
| import org.apache.flink.benchmark.BenchmarkBase;
import org.apache.flink.contrib.streaming.state.benchmark.StateBackendBenchmarkUtils;
import org.apache.flink.runtime.state.KeyedStateBackend;
import org.openjdk.jmh.annotations.Level;
import org.openjdk.jmh.annotations.Param;
import org.openjdk.jmh.annotations.Scope;
import org.openjdk.jmh.annotations.Setup;
import org.openjdk.jmh.annotations.State;
import org.openjdk.jmh.annotations.TearDown;
import java.io.IOException;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.ThreadLocalRandom;
import java.util.concurrent.atomic.AtomicInteger;
import static org.apache.flink.contrib.streaming.state.benchmark.StateBackendBenchmarkUtils.cleanUp;
import static org.apache.flink.state.benchmark.StateBenchmarkConstants.mapKeyCount;
import static org.apache.flink.state.benchmark.StateBenchmarkConstants.mapKeys;
import static org.apache.flink.state.benchmark.StateBenchmarkConstants.mapValues;
import static org.apache.flink.state.benchmark.StateBenchmarkConstants.newKeyCount;
import static org.apache.flink.state.benchmark.StateBenchmarkConstants.newKeys;
import static org.apache.flink.state.benchmark.StateBenchmarkConstants.randomValueCount;
import static org.apache.flink.state.benchmark.StateBenchmarkConstants.randomValues;
import static org.apache.flink.state.benchmark.StateBenchmarkConstants.setupKeyCount;
import static org.apache.flink.state.benchmark.StateBenchmarkConstants.setupKeys; | /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.flink.state.benchmark;
/**
* Base implementation of the state benchmarks.
*/
public class StateBenchmarkBase extends BenchmarkBase {
KeyedStateBackend<Long> keyedStateBackend;
@Param({"HEAP", "ROCKSDB"})
protected StateBackendBenchmarkUtils.StateBackendType backendType;
final ThreadLocalRandom random = ThreadLocalRandom.current();
@TearDown
public void tearDown() throws IOException {
cleanUp(keyedStateBackend);
}
static AtomicInteger keyIndex;
private static int getCurrentIndex() {
int currentIndex = keyIndex.getAndIncrement();
if (currentIndex == Integer.MAX_VALUE) {
keyIndex.set(0);
}
return currentIndex;
}
@State(Scope.Thread)
public static class KeyValue {
@Setup(Level.Invocation)
public void kvSetup() {
int currentIndex = getCurrentIndex();
setUpKey = setupKeys.get(currentIndex % setupKeyCount);
newKey = newKeys.get(currentIndex % newKeyCount);
mapKey = mapKeys.get(currentIndex % mapKeyCount);
mapValue = mapValues.get(currentIndex % mapKeyCount); | // Path: src/main/java/org/apache/flink/benchmark/BenchmarkBase.java
// @SuppressWarnings("MethodMayBeStatic")
// @State(Thread)
// @OutputTimeUnit(MILLISECONDS)
// @BenchmarkMode(Throughput)
// @Fork(value = 3, jvmArgsAppend = {
// "-Djava.rmi.server.hostname=127.0.0.1",
// "-Dcom.sun.management.jmxremote.authenticate=false",
// "-Dcom.sun.management.jmxremote.ssl=false",
// "-Dcom.sun.management.jmxremote.ssl"})
// @Warmup(iterations = 10)
// @Measurement(iterations = 10)
// public class BenchmarkBase {
// }
//
// Path: src/main/java/org/apache/flink/state/benchmark/StateBenchmarkConstants.java
// static final int mapKeyCount = 10;
//
// Path: src/main/java/org/apache/flink/state/benchmark/StateBenchmarkConstants.java
// static final ArrayList<Long> mapKeys = new ArrayList<>(mapKeyCount);
//
// Path: src/main/java/org/apache/flink/state/benchmark/StateBenchmarkConstants.java
// static final ArrayList<Double> mapValues = new ArrayList<>(mapKeyCount);
//
// Path: src/main/java/org/apache/flink/state/benchmark/StateBenchmarkConstants.java
// static final int newKeyCount = 500_000;
//
// Path: src/main/java/org/apache/flink/state/benchmark/StateBenchmarkConstants.java
// static final ArrayList<Long> newKeys = new ArrayList<>(newKeyCount);
//
// Path: src/main/java/org/apache/flink/state/benchmark/StateBenchmarkConstants.java
// static final int randomValueCount = 1_000_000;
//
// Path: src/main/java/org/apache/flink/state/benchmark/StateBenchmarkConstants.java
// static final ArrayList<Long> randomValues = new ArrayList<>(randomValueCount);
//
// Path: src/main/java/org/apache/flink/state/benchmark/StateBenchmarkConstants.java
// static final int setupKeyCount = 500_000;
//
// Path: src/main/java/org/apache/flink/state/benchmark/StateBenchmarkConstants.java
// static final ArrayList<Long> setupKeys = new ArrayList<>(setupKeyCount);
// Path: src/main/java/org/apache/flink/state/benchmark/StateBenchmarkBase.java
import org.apache.flink.benchmark.BenchmarkBase;
import org.apache.flink.contrib.streaming.state.benchmark.StateBackendBenchmarkUtils;
import org.apache.flink.runtime.state.KeyedStateBackend;
import org.openjdk.jmh.annotations.Level;
import org.openjdk.jmh.annotations.Param;
import org.openjdk.jmh.annotations.Scope;
import org.openjdk.jmh.annotations.Setup;
import org.openjdk.jmh.annotations.State;
import org.openjdk.jmh.annotations.TearDown;
import java.io.IOException;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.ThreadLocalRandom;
import java.util.concurrent.atomic.AtomicInteger;
import static org.apache.flink.contrib.streaming.state.benchmark.StateBackendBenchmarkUtils.cleanUp;
import static org.apache.flink.state.benchmark.StateBenchmarkConstants.mapKeyCount;
import static org.apache.flink.state.benchmark.StateBenchmarkConstants.mapKeys;
import static org.apache.flink.state.benchmark.StateBenchmarkConstants.mapValues;
import static org.apache.flink.state.benchmark.StateBenchmarkConstants.newKeyCount;
import static org.apache.flink.state.benchmark.StateBenchmarkConstants.newKeys;
import static org.apache.flink.state.benchmark.StateBenchmarkConstants.randomValueCount;
import static org.apache.flink.state.benchmark.StateBenchmarkConstants.randomValues;
import static org.apache.flink.state.benchmark.StateBenchmarkConstants.setupKeyCount;
import static org.apache.flink.state.benchmark.StateBenchmarkConstants.setupKeys;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.flink.state.benchmark;
/**
* Base implementation of the state benchmarks.
*/
public class StateBenchmarkBase extends BenchmarkBase {
KeyedStateBackend<Long> keyedStateBackend;
@Param({"HEAP", "ROCKSDB"})
protected StateBackendBenchmarkUtils.StateBackendType backendType;
final ThreadLocalRandom random = ThreadLocalRandom.current();
@TearDown
public void tearDown() throws IOException {
cleanUp(keyedStateBackend);
}
static AtomicInteger keyIndex;
private static int getCurrentIndex() {
int currentIndex = keyIndex.getAndIncrement();
if (currentIndex == Integer.MAX_VALUE) {
keyIndex.set(0);
}
return currentIndex;
}
@State(Scope.Thread)
public static class KeyValue {
@Setup(Level.Invocation)
public void kvSetup() {
int currentIndex = getCurrentIndex();
setUpKey = setupKeys.get(currentIndex % setupKeyCount);
newKey = newKeys.get(currentIndex % newKeyCount);
mapKey = mapKeys.get(currentIndex % mapKeyCount);
mapValue = mapValues.get(currentIndex % mapKeyCount); | value = randomValues.get(currentIndex % randomValueCount); |
dataArtisans/flink-benchmarks | src/main/java/org/apache/flink/state/benchmark/StateBenchmarkBase.java | // Path: src/main/java/org/apache/flink/benchmark/BenchmarkBase.java
// @SuppressWarnings("MethodMayBeStatic")
// @State(Thread)
// @OutputTimeUnit(MILLISECONDS)
// @BenchmarkMode(Throughput)
// @Fork(value = 3, jvmArgsAppend = {
// "-Djava.rmi.server.hostname=127.0.0.1",
// "-Dcom.sun.management.jmxremote.authenticate=false",
// "-Dcom.sun.management.jmxremote.ssl=false",
// "-Dcom.sun.management.jmxremote.ssl"})
// @Warmup(iterations = 10)
// @Measurement(iterations = 10)
// public class BenchmarkBase {
// }
//
// Path: src/main/java/org/apache/flink/state/benchmark/StateBenchmarkConstants.java
// static final int mapKeyCount = 10;
//
// Path: src/main/java/org/apache/flink/state/benchmark/StateBenchmarkConstants.java
// static final ArrayList<Long> mapKeys = new ArrayList<>(mapKeyCount);
//
// Path: src/main/java/org/apache/flink/state/benchmark/StateBenchmarkConstants.java
// static final ArrayList<Double> mapValues = new ArrayList<>(mapKeyCount);
//
// Path: src/main/java/org/apache/flink/state/benchmark/StateBenchmarkConstants.java
// static final int newKeyCount = 500_000;
//
// Path: src/main/java/org/apache/flink/state/benchmark/StateBenchmarkConstants.java
// static final ArrayList<Long> newKeys = new ArrayList<>(newKeyCount);
//
// Path: src/main/java/org/apache/flink/state/benchmark/StateBenchmarkConstants.java
// static final int randomValueCount = 1_000_000;
//
// Path: src/main/java/org/apache/flink/state/benchmark/StateBenchmarkConstants.java
// static final ArrayList<Long> randomValues = new ArrayList<>(randomValueCount);
//
// Path: src/main/java/org/apache/flink/state/benchmark/StateBenchmarkConstants.java
// static final int setupKeyCount = 500_000;
//
// Path: src/main/java/org/apache/flink/state/benchmark/StateBenchmarkConstants.java
// static final ArrayList<Long> setupKeys = new ArrayList<>(setupKeyCount);
| import org.apache.flink.benchmark.BenchmarkBase;
import org.apache.flink.contrib.streaming.state.benchmark.StateBackendBenchmarkUtils;
import org.apache.flink.runtime.state.KeyedStateBackend;
import org.openjdk.jmh.annotations.Level;
import org.openjdk.jmh.annotations.Param;
import org.openjdk.jmh.annotations.Scope;
import org.openjdk.jmh.annotations.Setup;
import org.openjdk.jmh.annotations.State;
import org.openjdk.jmh.annotations.TearDown;
import java.io.IOException;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.ThreadLocalRandom;
import java.util.concurrent.atomic.AtomicInteger;
import static org.apache.flink.contrib.streaming.state.benchmark.StateBackendBenchmarkUtils.cleanUp;
import static org.apache.flink.state.benchmark.StateBenchmarkConstants.mapKeyCount;
import static org.apache.flink.state.benchmark.StateBenchmarkConstants.mapKeys;
import static org.apache.flink.state.benchmark.StateBenchmarkConstants.mapValues;
import static org.apache.flink.state.benchmark.StateBenchmarkConstants.newKeyCount;
import static org.apache.flink.state.benchmark.StateBenchmarkConstants.newKeys;
import static org.apache.flink.state.benchmark.StateBenchmarkConstants.randomValueCount;
import static org.apache.flink.state.benchmark.StateBenchmarkConstants.randomValues;
import static org.apache.flink.state.benchmark.StateBenchmarkConstants.setupKeyCount;
import static org.apache.flink.state.benchmark.StateBenchmarkConstants.setupKeys; | /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.flink.state.benchmark;
/**
* Base implementation of the state benchmarks.
*/
public class StateBenchmarkBase extends BenchmarkBase {
KeyedStateBackend<Long> keyedStateBackend;
@Param({"HEAP", "ROCKSDB"})
protected StateBackendBenchmarkUtils.StateBackendType backendType;
final ThreadLocalRandom random = ThreadLocalRandom.current();
@TearDown
public void tearDown() throws IOException {
cleanUp(keyedStateBackend);
}
static AtomicInteger keyIndex;
private static int getCurrentIndex() {
int currentIndex = keyIndex.getAndIncrement();
if (currentIndex == Integer.MAX_VALUE) {
keyIndex.set(0);
}
return currentIndex;
}
@State(Scope.Thread)
public static class KeyValue {
@Setup(Level.Invocation)
public void kvSetup() {
int currentIndex = getCurrentIndex();
setUpKey = setupKeys.get(currentIndex % setupKeyCount);
newKey = newKeys.get(currentIndex % newKeyCount);
mapKey = mapKeys.get(currentIndex % mapKeyCount);
mapValue = mapValues.get(currentIndex % mapKeyCount); | // Path: src/main/java/org/apache/flink/benchmark/BenchmarkBase.java
// @SuppressWarnings("MethodMayBeStatic")
// @State(Thread)
// @OutputTimeUnit(MILLISECONDS)
// @BenchmarkMode(Throughput)
// @Fork(value = 3, jvmArgsAppend = {
// "-Djava.rmi.server.hostname=127.0.0.1",
// "-Dcom.sun.management.jmxremote.authenticate=false",
// "-Dcom.sun.management.jmxremote.ssl=false",
// "-Dcom.sun.management.jmxremote.ssl"})
// @Warmup(iterations = 10)
// @Measurement(iterations = 10)
// public class BenchmarkBase {
// }
//
// Path: src/main/java/org/apache/flink/state/benchmark/StateBenchmarkConstants.java
// static final int mapKeyCount = 10;
//
// Path: src/main/java/org/apache/flink/state/benchmark/StateBenchmarkConstants.java
// static final ArrayList<Long> mapKeys = new ArrayList<>(mapKeyCount);
//
// Path: src/main/java/org/apache/flink/state/benchmark/StateBenchmarkConstants.java
// static final ArrayList<Double> mapValues = new ArrayList<>(mapKeyCount);
//
// Path: src/main/java/org/apache/flink/state/benchmark/StateBenchmarkConstants.java
// static final int newKeyCount = 500_000;
//
// Path: src/main/java/org/apache/flink/state/benchmark/StateBenchmarkConstants.java
// static final ArrayList<Long> newKeys = new ArrayList<>(newKeyCount);
//
// Path: src/main/java/org/apache/flink/state/benchmark/StateBenchmarkConstants.java
// static final int randomValueCount = 1_000_000;
//
// Path: src/main/java/org/apache/flink/state/benchmark/StateBenchmarkConstants.java
// static final ArrayList<Long> randomValues = new ArrayList<>(randomValueCount);
//
// Path: src/main/java/org/apache/flink/state/benchmark/StateBenchmarkConstants.java
// static final int setupKeyCount = 500_000;
//
// Path: src/main/java/org/apache/flink/state/benchmark/StateBenchmarkConstants.java
// static final ArrayList<Long> setupKeys = new ArrayList<>(setupKeyCount);
// Path: src/main/java/org/apache/flink/state/benchmark/StateBenchmarkBase.java
import org.apache.flink.benchmark.BenchmarkBase;
import org.apache.flink.contrib.streaming.state.benchmark.StateBackendBenchmarkUtils;
import org.apache.flink.runtime.state.KeyedStateBackend;
import org.openjdk.jmh.annotations.Level;
import org.openjdk.jmh.annotations.Param;
import org.openjdk.jmh.annotations.Scope;
import org.openjdk.jmh.annotations.Setup;
import org.openjdk.jmh.annotations.State;
import org.openjdk.jmh.annotations.TearDown;
import java.io.IOException;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.ThreadLocalRandom;
import java.util.concurrent.atomic.AtomicInteger;
import static org.apache.flink.contrib.streaming.state.benchmark.StateBackendBenchmarkUtils.cleanUp;
import static org.apache.flink.state.benchmark.StateBenchmarkConstants.mapKeyCount;
import static org.apache.flink.state.benchmark.StateBenchmarkConstants.mapKeys;
import static org.apache.flink.state.benchmark.StateBenchmarkConstants.mapValues;
import static org.apache.flink.state.benchmark.StateBenchmarkConstants.newKeyCount;
import static org.apache.flink.state.benchmark.StateBenchmarkConstants.newKeys;
import static org.apache.flink.state.benchmark.StateBenchmarkConstants.randomValueCount;
import static org.apache.flink.state.benchmark.StateBenchmarkConstants.randomValues;
import static org.apache.flink.state.benchmark.StateBenchmarkConstants.setupKeyCount;
import static org.apache.flink.state.benchmark.StateBenchmarkConstants.setupKeys;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.flink.state.benchmark;
/**
* Base implementation of the state benchmarks.
*/
public class StateBenchmarkBase extends BenchmarkBase {
KeyedStateBackend<Long> keyedStateBackend;
@Param({"HEAP", "ROCKSDB"})
protected StateBackendBenchmarkUtils.StateBackendType backendType;
final ThreadLocalRandom random = ThreadLocalRandom.current();
@TearDown
public void tearDown() throws IOException {
cleanUp(keyedStateBackend);
}
static AtomicInteger keyIndex;
private static int getCurrentIndex() {
int currentIndex = keyIndex.getAndIncrement();
if (currentIndex == Integer.MAX_VALUE) {
keyIndex.set(0);
}
return currentIndex;
}
@State(Scope.Thread)
public static class KeyValue {
@Setup(Level.Invocation)
public void kvSetup() {
int currentIndex = getCurrentIndex();
setUpKey = setupKeys.get(currentIndex % setupKeyCount);
newKey = newKeys.get(currentIndex % newKeyCount);
mapKey = mapKeys.get(currentIndex % mapKeyCount);
mapValue = mapValues.get(currentIndex % mapKeyCount); | value = randomValues.get(currentIndex % randomValueCount); |
dataArtisans/flink-benchmarks | src/main/java/org/apache/flink/benchmark/full/StringSerializationBenchmark.java | // Path: src/main/java/org/apache/flink/benchmark/BenchmarkBase.java
// @SuppressWarnings("MethodMayBeStatic")
// @State(Thread)
// @OutputTimeUnit(MILLISECONDS)
// @BenchmarkMode(Throughput)
// @Fork(value = 3, jvmArgsAppend = {
// "-Djava.rmi.server.hostname=127.0.0.1",
// "-Dcom.sun.management.jmxremote.authenticate=false",
// "-Dcom.sun.management.jmxremote.ssl=false",
// "-Dcom.sun.management.jmxremote.ssl"})
// @Warmup(iterations = 10)
// @Measurement(iterations = 10)
// public class BenchmarkBase {
// }
| import org.apache.flink.api.common.ExecutionConfig;
import org.apache.flink.api.common.typeinfo.TypeInformation;
import org.apache.flink.api.common.typeutils.TypeSerializer;
import org.apache.flink.benchmark.BenchmarkBase;
import org.apache.flink.core.memory.DataInputView;
import org.apache.flink.core.memory.DataInputViewStreamWrapper;
import org.apache.flink.core.memory.DataOutputView;
import org.apache.flink.core.memory.DataOutputViewStreamWrapper;
import org.openjdk.jmh.runner.Runner;
import org.openjdk.jmh.runner.RunnerException;
import org.openjdk.jmh.runner.options.Options;
import org.openjdk.jmh.runner.options.OptionsBuilder;
import org.openjdk.jmh.runner.options.VerboseMode;
import org.openjdk.jmh.annotations.*;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.Random;
import java.util.concurrent.TimeUnit; | /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.flink.benchmark.full;
@State(Scope.Benchmark)
@BenchmarkMode({Mode.Throughput})
@OutputTimeUnit(TimeUnit.MILLISECONDS) | // Path: src/main/java/org/apache/flink/benchmark/BenchmarkBase.java
// @SuppressWarnings("MethodMayBeStatic")
// @State(Thread)
// @OutputTimeUnit(MILLISECONDS)
// @BenchmarkMode(Throughput)
// @Fork(value = 3, jvmArgsAppend = {
// "-Djava.rmi.server.hostname=127.0.0.1",
// "-Dcom.sun.management.jmxremote.authenticate=false",
// "-Dcom.sun.management.jmxremote.ssl=false",
// "-Dcom.sun.management.jmxremote.ssl"})
// @Warmup(iterations = 10)
// @Measurement(iterations = 10)
// public class BenchmarkBase {
// }
// Path: src/main/java/org/apache/flink/benchmark/full/StringSerializationBenchmark.java
import org.apache.flink.api.common.ExecutionConfig;
import org.apache.flink.api.common.typeinfo.TypeInformation;
import org.apache.flink.api.common.typeutils.TypeSerializer;
import org.apache.flink.benchmark.BenchmarkBase;
import org.apache.flink.core.memory.DataInputView;
import org.apache.flink.core.memory.DataInputViewStreamWrapper;
import org.apache.flink.core.memory.DataOutputView;
import org.apache.flink.core.memory.DataOutputViewStreamWrapper;
import org.openjdk.jmh.runner.Runner;
import org.openjdk.jmh.runner.RunnerException;
import org.openjdk.jmh.runner.options.Options;
import org.openjdk.jmh.runner.options.OptionsBuilder;
import org.openjdk.jmh.runner.options.VerboseMode;
import org.openjdk.jmh.annotations.*;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.Random;
import java.util.concurrent.TimeUnit;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.flink.benchmark.full;
@State(Scope.Benchmark)
@BenchmarkMode({Mode.Throughput})
@OutputTimeUnit(TimeUnit.MILLISECONDS) | public class StringSerializationBenchmark extends BenchmarkBase { |
dataArtisans/flink-benchmarks | src/main/java/org/apache/flink/benchmark/StateBackendBenchmarkBase.java | // Path: src/main/java/org/apache/flink/benchmark/functions/IntegerLongSource.java
// public class IntegerLongSource extends RichParallelSourceFunction<IntegerLongSource.Record> {
// public static final class Record {
// public final int key;
// public final long value;
//
// public Record() {
// this(0, 0);
// }
//
// public Record(int key, long value) {
// this.key = key;
// this.value = value;
// }
//
// public static Record of(int key, long value) {
// return new Record(key, value);
// }
//
// public int getKey() {
// return key;
// }
//
// @Override
// public String toString() {
// return String.format("(%s, %s)", key, value);
// }
// }
//
// private volatile boolean running = true;
// private int numberOfKeys;
// private long numberOfElements;
//
// public IntegerLongSource(int numberOfKeys, long numberOfElements) {
// this.numberOfKeys = numberOfKeys;
// this.numberOfElements = numberOfElements;
// }
//
// @Override
// public void run(SourceContext<Record> ctx) throws Exception {
// long counter = 0;
//
// while (running && counter < numberOfElements) {
// synchronized (ctx.getCheckpointLock()) {
// ctx.collectWithTimestamp(Record.of((int) (counter % numberOfKeys), counter), counter);
// counter++;
// }
// }
// running = false;
// }
//
// @Override
// public void cancel() {
// running = false;
// }
// }
| import org.apache.flink.benchmark.functions.IntegerLongSource;
import org.apache.flink.contrib.streaming.state.RocksDBStateBackend;
import org.apache.flink.runtime.state.AbstractStateBackend;
import org.apache.flink.runtime.state.filesystem.FsStateBackend;
import org.apache.flink.runtime.state.memory.MemoryStateBackend;
import org.apache.flink.streaming.api.TimeCharacteristic;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.util.FileUtils;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files; | /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.flink.benchmark;
public class StateBackendBenchmarkBase extends BenchmarkBase {
public enum StateBackend {
MEMORY,
FS,
FS_ASYNC,
ROCKS,
ROCKS_INC
}
public static class StateBackendContext extends FlinkEnvironmentContext {
public final File checkpointDir;
public final int numberOfElements = 1000;
| // Path: src/main/java/org/apache/flink/benchmark/functions/IntegerLongSource.java
// public class IntegerLongSource extends RichParallelSourceFunction<IntegerLongSource.Record> {
// public static final class Record {
// public final int key;
// public final long value;
//
// public Record() {
// this(0, 0);
// }
//
// public Record(int key, long value) {
// this.key = key;
// this.value = value;
// }
//
// public static Record of(int key, long value) {
// return new Record(key, value);
// }
//
// public int getKey() {
// return key;
// }
//
// @Override
// public String toString() {
// return String.format("(%s, %s)", key, value);
// }
// }
//
// private volatile boolean running = true;
// private int numberOfKeys;
// private long numberOfElements;
//
// public IntegerLongSource(int numberOfKeys, long numberOfElements) {
// this.numberOfKeys = numberOfKeys;
// this.numberOfElements = numberOfElements;
// }
//
// @Override
// public void run(SourceContext<Record> ctx) throws Exception {
// long counter = 0;
//
// while (running && counter < numberOfElements) {
// synchronized (ctx.getCheckpointLock()) {
// ctx.collectWithTimestamp(Record.of((int) (counter % numberOfKeys), counter), counter);
// counter++;
// }
// }
// running = false;
// }
//
// @Override
// public void cancel() {
// running = false;
// }
// }
// Path: src/main/java/org/apache/flink/benchmark/StateBackendBenchmarkBase.java
import org.apache.flink.benchmark.functions.IntegerLongSource;
import org.apache.flink.contrib.streaming.state.RocksDBStateBackend;
import org.apache.flink.runtime.state.AbstractStateBackend;
import org.apache.flink.runtime.state.filesystem.FsStateBackend;
import org.apache.flink.runtime.state.memory.MemoryStateBackend;
import org.apache.flink.streaming.api.TimeCharacteristic;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.util.FileUtils;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.flink.benchmark;
public class StateBackendBenchmarkBase extends BenchmarkBase {
public enum StateBackend {
MEMORY,
FS,
FS_ASYNC,
ROCKS,
ROCKS_INC
}
public static class StateBackendContext extends FlinkEnvironmentContext {
public final File checkpointDir;
public final int numberOfElements = 1000;
| public DataStreamSource<IntegerLongSource.Record> source; |
TerrenceMiao/camel-spring | src/main/java/org/paradise/RedisRouter.java | // Path: src/main/java/org/paradise/service/RedisService.java
// @Component
// public class RedisService {
//
// private static final Logger LOG = LoggerFactory.getLogger(RedisService.class);
//
// private RedisRepository redisRepository;
//
// @Autowired
// public RedisService(RedisRepository redisRepository) {
// this.redisRepository = redisRepository;
// }
//
// public void getMessage(String message) {
//
// redisRepository.saveHash("RedisMessage", message);
//
// LOG.debug("Redis message is: " + redisRepository.findHash("RedisMessage"));
// LOG.debug("Redis HSET value is: [" + redisRepository.findHash(Constants.REDIS_FIELD) + "]");
// }
//
// public void handleException(String exceptionMessage) {
//
// LOG.error("Exception thrown while invoke Redis service: " + exceptionMessage);
// }
//
// }
| import org.apache.camel.Processor;
import org.apache.camel.component.redis.RedisConstants;
import org.apache.camel.spring.boot.FatJarRouter;
import org.paradise.service.RedisService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import redis.clients.jedis.exceptions.JedisConnectionException; | package org.paradise;
/**
* Created by terrence on 25/07/2016.
*/
@Component
public class RedisRouter extends FatJarRouter {
private static final Processor enrichExchangeBody
= exchange -> exchange.getIn().setBody("[" + exchange.getIn().getBody().toString() + "]");
@Autowired | // Path: src/main/java/org/paradise/service/RedisService.java
// @Component
// public class RedisService {
//
// private static final Logger LOG = LoggerFactory.getLogger(RedisService.class);
//
// private RedisRepository redisRepository;
//
// @Autowired
// public RedisService(RedisRepository redisRepository) {
// this.redisRepository = redisRepository;
// }
//
// public void getMessage(String message) {
//
// redisRepository.saveHash("RedisMessage", message);
//
// LOG.debug("Redis message is: " + redisRepository.findHash("RedisMessage"));
// LOG.debug("Redis HSET value is: [" + redisRepository.findHash(Constants.REDIS_FIELD) + "]");
// }
//
// public void handleException(String exceptionMessage) {
//
// LOG.error("Exception thrown while invoke Redis service: " + exceptionMessage);
// }
//
// }
// Path: src/main/java/org/paradise/RedisRouter.java
import org.apache.camel.Processor;
import org.apache.camel.component.redis.RedisConstants;
import org.apache.camel.spring.boot.FatJarRouter;
import org.paradise.service.RedisService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import redis.clients.jedis.exceptions.JedisConnectionException;
package org.paradise;
/**
* Created by terrence on 25/07/2016.
*/
@Component
public class RedisRouter extends FatJarRouter {
private static final Processor enrichExchangeBody
= exchange -> exchange.getIn().setBody("[" + exchange.getIn().getBody().toString() + "]");
@Autowired | RedisService redisService; |
TerrenceMiao/camel-spring | src/main/java/org/paradise/controllers/HealthCheckController.java | // Path: src/main/java/org/paradise/Constants.java
// public class Constants {
//
// public static final String OK = "OK";
//
// public static final String CURRENT_VERSION = "/v1";
//
// public static final String HEALTH_CHECK_PATH = CURRENT_VERSION + "/health";
// public static final String PDF_PATH = CURRENT_VERSION + "/pdf";
//
// public static final String REDIS_KEY = "camelKey";
// public static final String REDIS_FIELD = "camelField";
//
// private Constants() {
// }
//
// }
//
// Path: src/main/java/org/paradise/model/Status.java
// @JsonInclude(JsonInclude.Include.NON_NULL)
// public class Status {
//
// @NotNull
// @JsonProperty("status")
// private String status;
//
// public String getStatus() {
// return status;
// }
//
// public void setStatus(String status) {
// this.status = status;
// }
//
// }
| import org.paradise.Constants;
import org.paradise.model.Status;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE; | package org.paradise.controllers;
/**
* Created by terrence on 9/06/2016.
*/
@RestController
public class HealthCheckController {
private static final Logger LOG = LoggerFactory.getLogger(HealthCheckController.class);
| // Path: src/main/java/org/paradise/Constants.java
// public class Constants {
//
// public static final String OK = "OK";
//
// public static final String CURRENT_VERSION = "/v1";
//
// public static final String HEALTH_CHECK_PATH = CURRENT_VERSION + "/health";
// public static final String PDF_PATH = CURRENT_VERSION + "/pdf";
//
// public static final String REDIS_KEY = "camelKey";
// public static final String REDIS_FIELD = "camelField";
//
// private Constants() {
// }
//
// }
//
// Path: src/main/java/org/paradise/model/Status.java
// @JsonInclude(JsonInclude.Include.NON_NULL)
// public class Status {
//
// @NotNull
// @JsonProperty("status")
// private String status;
//
// public String getStatus() {
// return status;
// }
//
// public void setStatus(String status) {
// this.status = status;
// }
//
// }
// Path: src/main/java/org/paradise/controllers/HealthCheckController.java
import org.paradise.Constants;
import org.paradise.model.Status;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE;
package org.paradise.controllers;
/**
* Created by terrence on 9/06/2016.
*/
@RestController
public class HealthCheckController {
private static final Logger LOG = LoggerFactory.getLogger(HealthCheckController.class);
| @RequestMapping(value = Constants.HEALTH_CHECK_PATH, method = RequestMethod.GET, produces = APPLICATION_JSON_VALUE) |
TerrenceMiao/camel-spring | src/main/java/org/paradise/controllers/HealthCheckController.java | // Path: src/main/java/org/paradise/Constants.java
// public class Constants {
//
// public static final String OK = "OK";
//
// public static final String CURRENT_VERSION = "/v1";
//
// public static final String HEALTH_CHECK_PATH = CURRENT_VERSION + "/health";
// public static final String PDF_PATH = CURRENT_VERSION + "/pdf";
//
// public static final String REDIS_KEY = "camelKey";
// public static final String REDIS_FIELD = "camelField";
//
// private Constants() {
// }
//
// }
//
// Path: src/main/java/org/paradise/model/Status.java
// @JsonInclude(JsonInclude.Include.NON_NULL)
// public class Status {
//
// @NotNull
// @JsonProperty("status")
// private String status;
//
// public String getStatus() {
// return status;
// }
//
// public void setStatus(String status) {
// this.status = status;
// }
//
// }
| import org.paradise.Constants;
import org.paradise.model.Status;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE; | package org.paradise.controllers;
/**
* Created by terrence on 9/06/2016.
*/
@RestController
public class HealthCheckController {
private static final Logger LOG = LoggerFactory.getLogger(HealthCheckController.class);
@RequestMapping(value = Constants.HEALTH_CHECK_PATH, method = RequestMethod.GET, produces = APPLICATION_JSON_VALUE) | // Path: src/main/java/org/paradise/Constants.java
// public class Constants {
//
// public static final String OK = "OK";
//
// public static final String CURRENT_VERSION = "/v1";
//
// public static final String HEALTH_CHECK_PATH = CURRENT_VERSION + "/health";
// public static final String PDF_PATH = CURRENT_VERSION + "/pdf";
//
// public static final String REDIS_KEY = "camelKey";
// public static final String REDIS_FIELD = "camelField";
//
// private Constants() {
// }
//
// }
//
// Path: src/main/java/org/paradise/model/Status.java
// @JsonInclude(JsonInclude.Include.NON_NULL)
// public class Status {
//
// @NotNull
// @JsonProperty("status")
// private String status;
//
// public String getStatus() {
// return status;
// }
//
// public void setStatus(String status) {
// this.status = status;
// }
//
// }
// Path: src/main/java/org/paradise/controllers/HealthCheckController.java
import org.paradise.Constants;
import org.paradise.model.Status;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE;
package org.paradise.controllers;
/**
* Created by terrence on 9/06/2016.
*/
@RestController
public class HealthCheckController {
private static final Logger LOG = LoggerFactory.getLogger(HealthCheckController.class);
@RequestMapping(value = Constants.HEALTH_CHECK_PATH, method = RequestMethod.GET, produces = APPLICATION_JSON_VALUE) | public ResponseEntity<Status> getHealthStatus() { |
TerrenceMiao/camel-spring | src/test/java/org/paradise/validator/PersonValidatorTest.java | // Path: src/main/java/org/paradise/domain/Car.java
// public class Car {
//
// private static Optional<Insurance> insurance;
//
// public Car(Insurance insurance) {
// this.insurance = Optional.ofNullable(insurance);
// }
//
// public static <U> Optional<Insurance> getInsurance(U u) {
// return insurance;
// }
//
// }
//
// Path: src/main/java/org/paradise/domain/Insurance.java
// public class Insurance {
//
// private static String name;
// private static String policy;
//
// public Insurance(String name, String policy) {
// this.name = name;
// this.policy = policy;
// }
//
// public static <U> String getName(U u) {
// return name;
// }
//
// public static <U> String getPolicy(U u) {
// return policy;
// }
//
// }
//
// Path: src/main/java/org/paradise/domain/Person.java
// public class Person {
//
// private String name;
// private int age;
//
// private static Optional<Car> car;
//
// private static Address address;
//
//
// public Person(Car car) {
// this.car = Optional.ofNullable(car);
// }
//
// public static <U> Optional<Car> getCar(U u) {
// return car;
// }
//
// public static <U> Try<Address> getAddress(U u) {
//
// return address == null
// ? new TryFailure<>(address).failure(u.toString(), new NullValueException("Address is NULL"))
// : new TrySuccess(address);
// }
//
// public String getName() {
// return name;
// }
//
// public void setName(String name) {
// this.name = name;
// }
//
// public int getAge() {
// return age;
// }
//
// public void setAge(int age) {
// this.age = age;
// }
//
// @Override
// public String toString() {
// return "Person {" +
// "name = [" + name + ']' +
// ", age = [" + age + ']' +
// ", car = [" + car + ']' +
// ", address = [" + address + ']' +
// '}';
// }
//
// }
//
// Path: src/main/java/org/paradise/monad/ValidationFailure.java
// public class ValidationFailure<L, A> extends Validation<L, A> {
//
// protected final L left;
//
// public ValidationFailure(L left, A value) {
// super(value);
// this.left = left;
// }
//
// public <B> Validation<L, B> map(Function<? super A, ? extends B> mapper) {
// return new ValidationFailure(left, mapper.apply(value));
// }
//
// public <B> Validation<L, B> flatMap(Function<? super A, Validation<?, ? extends B>> mapper) {
// Validation<?, ? extends B> result = mapper.apply(value);
//
// return result.isSuccess() ? new ValidationFailure(left, result.value) : new ValidationFailure(((ValidationFailure<L, B>) result).left, result.value);
// }
//
// public boolean isSuccess() {
// return false;
// }
//
// }
//
// Path: src/main/java/org/paradise/monad/ValidationSuccess.java
// public class ValidationSuccess<L, A> extends Validation<L, A> {
//
// public ValidationSuccess(A value) {
// super(value);
// }
//
// public <B> Validation<L, B> map(Function<? super A, ? extends B> mapper) {
// return success(mapper.apply(value));
// }
//
// public <B> Validation<L, B> flatMap(Function<? super A, Validation<?, ? extends B>> mapper) {
// return (Validation<L, B>) mapper.apply(value);
// }
//
// public boolean isSuccess() {
// return true;
// }
//
// public static <L, A> ValidationSuccess<L, A> success(A value) {
// return new ValidationSuccess<>(value);
// }
//
// }
| import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.paradise.domain.Car;
import org.paradise.domain.Insurance;
import org.paradise.domain.Person;
import org.paradise.monad.ValidationFailure;
import org.paradise.monad.ValidationSuccess;
import static org.junit.Assert.assertTrue; | package org.paradise.validator;
/**
* Created by terrence on 12/03/2016.
*/
public class PersonValidatorTest {
String insuranceName = "Pacific Insurance";
String insurancePolicy = "Pacific Insurance Policy";
| // Path: src/main/java/org/paradise/domain/Car.java
// public class Car {
//
// private static Optional<Insurance> insurance;
//
// public Car(Insurance insurance) {
// this.insurance = Optional.ofNullable(insurance);
// }
//
// public static <U> Optional<Insurance> getInsurance(U u) {
// return insurance;
// }
//
// }
//
// Path: src/main/java/org/paradise/domain/Insurance.java
// public class Insurance {
//
// private static String name;
// private static String policy;
//
// public Insurance(String name, String policy) {
// this.name = name;
// this.policy = policy;
// }
//
// public static <U> String getName(U u) {
// return name;
// }
//
// public static <U> String getPolicy(U u) {
// return policy;
// }
//
// }
//
// Path: src/main/java/org/paradise/domain/Person.java
// public class Person {
//
// private String name;
// private int age;
//
// private static Optional<Car> car;
//
// private static Address address;
//
//
// public Person(Car car) {
// this.car = Optional.ofNullable(car);
// }
//
// public static <U> Optional<Car> getCar(U u) {
// return car;
// }
//
// public static <U> Try<Address> getAddress(U u) {
//
// return address == null
// ? new TryFailure<>(address).failure(u.toString(), new NullValueException("Address is NULL"))
// : new TrySuccess(address);
// }
//
// public String getName() {
// return name;
// }
//
// public void setName(String name) {
// this.name = name;
// }
//
// public int getAge() {
// return age;
// }
//
// public void setAge(int age) {
// this.age = age;
// }
//
// @Override
// public String toString() {
// return "Person {" +
// "name = [" + name + ']' +
// ", age = [" + age + ']' +
// ", car = [" + car + ']' +
// ", address = [" + address + ']' +
// '}';
// }
//
// }
//
// Path: src/main/java/org/paradise/monad/ValidationFailure.java
// public class ValidationFailure<L, A> extends Validation<L, A> {
//
// protected final L left;
//
// public ValidationFailure(L left, A value) {
// super(value);
// this.left = left;
// }
//
// public <B> Validation<L, B> map(Function<? super A, ? extends B> mapper) {
// return new ValidationFailure(left, mapper.apply(value));
// }
//
// public <B> Validation<L, B> flatMap(Function<? super A, Validation<?, ? extends B>> mapper) {
// Validation<?, ? extends B> result = mapper.apply(value);
//
// return result.isSuccess() ? new ValidationFailure(left, result.value) : new ValidationFailure(((ValidationFailure<L, B>) result).left, result.value);
// }
//
// public boolean isSuccess() {
// return false;
// }
//
// }
//
// Path: src/main/java/org/paradise/monad/ValidationSuccess.java
// public class ValidationSuccess<L, A> extends Validation<L, A> {
//
// public ValidationSuccess(A value) {
// super(value);
// }
//
// public <B> Validation<L, B> map(Function<? super A, ? extends B> mapper) {
// return success(mapper.apply(value));
// }
//
// public <B> Validation<L, B> flatMap(Function<? super A, Validation<?, ? extends B>> mapper) {
// return (Validation<L, B>) mapper.apply(value);
// }
//
// public boolean isSuccess() {
// return true;
// }
//
// public static <L, A> ValidationSuccess<L, A> success(A value) {
// return new ValidationSuccess<>(value);
// }
//
// }
// Path: src/test/java/org/paradise/validator/PersonValidatorTest.java
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.paradise.domain.Car;
import org.paradise.domain.Insurance;
import org.paradise.domain.Person;
import org.paradise.monad.ValidationFailure;
import org.paradise.monad.ValidationSuccess;
import static org.junit.Assert.assertTrue;
package org.paradise.validator;
/**
* Created by terrence on 12/03/2016.
*/
public class PersonValidatorTest {
String insuranceName = "Pacific Insurance";
String insurancePolicy = "Pacific Insurance Policy";
| Person person = new Person(new Car(new Insurance(insuranceName, insurancePolicy))); |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.