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
|
---|---|---|---|---|---|---|
ykameshrao/spring-mvc-angular-js-hibernate-bootstrap-java-single-page-jwt-auth-rest-api-webapp-framework | src/main/java/yourwebproject2/model/entity/Job.java | // Path: src/main/java/yourwebproject2/framework/data/JPAEntity.java
// @MappedSuperclass
// public abstract class JPAEntity<T extends Serializable> implements Entity {
// protected T id;
// protected Date createdAt;
// protected Date updatedAt;
//
//
// public JPAEntity() {
// createdAt = new Date();
// updatedAt = new Date();
// }
//
//
// /**
// * To make XStream deserialization assign values to
// * base class fields of createdAt and updatedAt
// *
// * @return
// */
// public Object readResolve() {
// if (this.createdAt == null) {
// this.createdAt = new Date();
// this.updatedAt = createdAt;
// }
//
// return this;
// }
//
//
// @XmlElement(type = Object.class) @Id @GeneratedValue
// public T getId() {
// return id;
// }
//
//
// public void setId(T id) {
// this.id = id;
// }
//
//
// @JsonIgnore @Temporal(TemporalType.DATE) @Column
// public Date getCreatedAt() {
// return createdAt;
// }
//
//
// public void setCreatedAt(Date createdAt) {
// this.createdAt = createdAt;
// }
//
//
// @JsonIgnore @Temporal(TemporalType.TIMESTAMP) @Column
// public Date getUpdatedAt() {
// return updatedAt;
// }
//
//
// public void setUpdatedAt(Date updatedAt) {
// this.updatedAt = updatedAt;
// }
// }
| import yourwebproject2.framework.data.JPAEntity;
import org.hibernate.validator.constraints.NotBlank;
import javax.persistence.*;
import javax.validation.constraints.NotNull;
import java.util.Date; | package yourwebproject2.model.entity;
/**
* The core Job Entity
*
* Created by Y.Kamesh on 8/2/2015.
*/
@Entity
@Table(indexes = { @Index(name="name_idx", columnList = "name", unique = true),
@Index(name="status_idx", columnList = "status"),
@Index(name="category_idx", columnList = "category")}) | // Path: src/main/java/yourwebproject2/framework/data/JPAEntity.java
// @MappedSuperclass
// public abstract class JPAEntity<T extends Serializable> implements Entity {
// protected T id;
// protected Date createdAt;
// protected Date updatedAt;
//
//
// public JPAEntity() {
// createdAt = new Date();
// updatedAt = new Date();
// }
//
//
// /**
// * To make XStream deserialization assign values to
// * base class fields of createdAt and updatedAt
// *
// * @return
// */
// public Object readResolve() {
// if (this.createdAt == null) {
// this.createdAt = new Date();
// this.updatedAt = createdAt;
// }
//
// return this;
// }
//
//
// @XmlElement(type = Object.class) @Id @GeneratedValue
// public T getId() {
// return id;
// }
//
//
// public void setId(T id) {
// this.id = id;
// }
//
//
// @JsonIgnore @Temporal(TemporalType.DATE) @Column
// public Date getCreatedAt() {
// return createdAt;
// }
//
//
// public void setCreatedAt(Date createdAt) {
// this.createdAt = createdAt;
// }
//
//
// @JsonIgnore @Temporal(TemporalType.TIMESTAMP) @Column
// public Date getUpdatedAt() {
// return updatedAt;
// }
//
//
// public void setUpdatedAt(Date updatedAt) {
// this.updatedAt = updatedAt;
// }
// }
// Path: src/main/java/yourwebproject2/model/entity/Job.java
import yourwebproject2.framework.data.JPAEntity;
import org.hibernate.validator.constraints.NotBlank;
import javax.persistence.*;
import javax.validation.constraints.NotNull;
import java.util.Date;
package yourwebproject2.model.entity;
/**
* The core Job Entity
*
* Created by Y.Kamesh on 8/2/2015.
*/
@Entity
@Table(indexes = { @Index(name="name_idx", columnList = "name", unique = true),
@Index(name="status_idx", columnList = "status"),
@Index(name="category_idx", columnList = "category")}) | public class Job extends JPAEntity<Long> { |
ykameshrao/spring-mvc-angular-js-hibernate-bootstrap-java-single-page-jwt-auth-rest-api-webapp-framework | src/main/java/yourwebproject2/unusedspringsecurity/UserDetailsServiceImpl.java | // Path: src/main/java/yourwebproject2/framework/exception/EmailNotFoundException.java
// public class EmailNotFoundException extends AuthenticationException {
// public EmailNotFoundException(String message) {
// super(message);
// }
// }
//
// Path: src/main/java/yourwebproject2/model/entity/User.java
// @Entity
// @Inheritance(strategy = InheritanceType.SINGLE_TABLE)
// @Table(indexes = { @Index(name="email_idx", columnList = "email", unique = true),
// @Index(name="displayName_idx", columnList = "display_name") })
// public class User extends JPAEntity<Long> implements Serializable {
// public enum Role {
// USER,
// ADMIN
// }
//
// private String email;
// private @JsonIgnore String password;
// private boolean enabled;
// private Role role;
// private String displayName;
//
// private @JsonIgnore Integer loginCount;
// private Date currentLoginAt;
// private Date lastLoginAt;
// private @JsonIgnore String currentLoginIp;
// private @JsonIgnore String lastLoginIp;
//
// private static BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder();
//
// @Column @Email @NotNull @NotBlank
// public String getEmail() {
// return this.email;
// }
//
// public void setEmail(String email) {
// this.email = email;
// }
//
// @JsonIgnore @Column(nullable = false, length = 60)
// public String getPassword() {
// return this.password;
// }
//
// public void setPassword(String password) {
// this.password = password;
// }
//
// @Column(nullable = false)
// public boolean isEnabled() {
// return this.enabled;
// }
//
// public void setEnabled(boolean enabled) {
// this.enabled = enabled;
// }
//
// @Column(nullable = false)
// public Role getRole() {
// return this.role;
// }
//
// public void setRole(Role role) {
// this.role = role;
// }
//
// @Column(name="display_name")
// public String getDisplayName() {
// return displayName;
// }
//
// public void setDisplayName(String displayName) {
// this.displayName = displayName;
// }
//
// @JsonIgnore @Column
// public Integer getLoginCount() {
// return loginCount;
// }
//
// public void setLoginCount(Integer loginCount) {
// this.loginCount = loginCount;
// }
//
// @Column
// public Date getCurrentLoginAt() {
// return currentLoginAt;
// }
//
// public void setCurrentLoginAt(Date currentLoginAt) {
// this.currentLoginAt = currentLoginAt;
// }
//
// @Column
// public Date getLastLoginAt() {
// return lastLoginAt;
// }
//
// public void setLastLoginAt(Date lastLoginAt) {
// this.lastLoginAt = lastLoginAt;
// }
//
// @JsonIgnore @Column
// public String getCurrentLoginIp() {
// return currentLoginIp;
// }
//
// public void setCurrentLoginIp(String currentLoginIp) {
// this.currentLoginIp = currentLoginIp;
// }
//
// @JsonIgnore @Column
// public String getLastLoginIp() {
// return lastLoginIp;
// }
//
// public void setLastLoginIp(String lastLoginIp) {
// this.lastLoginIp = lastLoginIp;
// }
//
// /**
// * Method to create the hash of the password before storing
// *
// * @param pass
// *
// * @return SHA hash digest of the password
// */
// public static synchronized String hashPassword(String pass) {
// return passwordEncoder.encode(pass);
// }
//
// public static synchronized boolean doesPasswordMatch(String rawPass, String encodedPass) {
// return passwordEncoder.matches(rawPass, encodedPass);
// }
//
// @Override
// public String toString() {
// return "User{" +
// "email='" + email + '\'' +
// ", password='" + password + '\'' +
// ", enabled=" + enabled +
// ", role=" + role +
// ", displayName='" + displayName + '\'' +
// ", loginCount=" + loginCount +
// ", currentLoginAt=" + currentLoginAt +
// ", lastLoginAt=" + lastLoginAt +
// ", currentLoginIp='" + currentLoginIp + '\'' +
// ", lastLoginIp='" + lastLoginIp + '\'' +
// '}';
// }
// }
//
// Path: src/main/java/yourwebproject2/model/repository/UserRepository.java
// public interface UserRepository extends BaseJPARepository<User, Long> {
// /**
// * Finds a user with the given email
// *
// * @param email
// * @return
// */
// public User findByEmail(String email);
// }
| import yourwebproject2.framework.exception.EmailNotFoundException;
import yourwebproject2.model.entity.User;
import yourwebproject2.model.repository.UserRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.*; | package yourwebproject2.unusedspringsecurity;
/**
* @author: kameshr
*/
@Service
@Transactional
public class UserDetailsServiceImpl implements UserDetailsService { | // Path: src/main/java/yourwebproject2/framework/exception/EmailNotFoundException.java
// public class EmailNotFoundException extends AuthenticationException {
// public EmailNotFoundException(String message) {
// super(message);
// }
// }
//
// Path: src/main/java/yourwebproject2/model/entity/User.java
// @Entity
// @Inheritance(strategy = InheritanceType.SINGLE_TABLE)
// @Table(indexes = { @Index(name="email_idx", columnList = "email", unique = true),
// @Index(name="displayName_idx", columnList = "display_name") })
// public class User extends JPAEntity<Long> implements Serializable {
// public enum Role {
// USER,
// ADMIN
// }
//
// private String email;
// private @JsonIgnore String password;
// private boolean enabled;
// private Role role;
// private String displayName;
//
// private @JsonIgnore Integer loginCount;
// private Date currentLoginAt;
// private Date lastLoginAt;
// private @JsonIgnore String currentLoginIp;
// private @JsonIgnore String lastLoginIp;
//
// private static BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder();
//
// @Column @Email @NotNull @NotBlank
// public String getEmail() {
// return this.email;
// }
//
// public void setEmail(String email) {
// this.email = email;
// }
//
// @JsonIgnore @Column(nullable = false, length = 60)
// public String getPassword() {
// return this.password;
// }
//
// public void setPassword(String password) {
// this.password = password;
// }
//
// @Column(nullable = false)
// public boolean isEnabled() {
// return this.enabled;
// }
//
// public void setEnabled(boolean enabled) {
// this.enabled = enabled;
// }
//
// @Column(nullable = false)
// public Role getRole() {
// return this.role;
// }
//
// public void setRole(Role role) {
// this.role = role;
// }
//
// @Column(name="display_name")
// public String getDisplayName() {
// return displayName;
// }
//
// public void setDisplayName(String displayName) {
// this.displayName = displayName;
// }
//
// @JsonIgnore @Column
// public Integer getLoginCount() {
// return loginCount;
// }
//
// public void setLoginCount(Integer loginCount) {
// this.loginCount = loginCount;
// }
//
// @Column
// public Date getCurrentLoginAt() {
// return currentLoginAt;
// }
//
// public void setCurrentLoginAt(Date currentLoginAt) {
// this.currentLoginAt = currentLoginAt;
// }
//
// @Column
// public Date getLastLoginAt() {
// return lastLoginAt;
// }
//
// public void setLastLoginAt(Date lastLoginAt) {
// this.lastLoginAt = lastLoginAt;
// }
//
// @JsonIgnore @Column
// public String getCurrentLoginIp() {
// return currentLoginIp;
// }
//
// public void setCurrentLoginIp(String currentLoginIp) {
// this.currentLoginIp = currentLoginIp;
// }
//
// @JsonIgnore @Column
// public String getLastLoginIp() {
// return lastLoginIp;
// }
//
// public void setLastLoginIp(String lastLoginIp) {
// this.lastLoginIp = lastLoginIp;
// }
//
// /**
// * Method to create the hash of the password before storing
// *
// * @param pass
// *
// * @return SHA hash digest of the password
// */
// public static synchronized String hashPassword(String pass) {
// return passwordEncoder.encode(pass);
// }
//
// public static synchronized boolean doesPasswordMatch(String rawPass, String encodedPass) {
// return passwordEncoder.matches(rawPass, encodedPass);
// }
//
// @Override
// public String toString() {
// return "User{" +
// "email='" + email + '\'' +
// ", password='" + password + '\'' +
// ", enabled=" + enabled +
// ", role=" + role +
// ", displayName='" + displayName + '\'' +
// ", loginCount=" + loginCount +
// ", currentLoginAt=" + currentLoginAt +
// ", lastLoginAt=" + lastLoginAt +
// ", currentLoginIp='" + currentLoginIp + '\'' +
// ", lastLoginIp='" + lastLoginIp + '\'' +
// '}';
// }
// }
//
// Path: src/main/java/yourwebproject2/model/repository/UserRepository.java
// public interface UserRepository extends BaseJPARepository<User, Long> {
// /**
// * Finds a user with the given email
// *
// * @param email
// * @return
// */
// public User findByEmail(String email);
// }
// Path: src/main/java/yourwebproject2/unusedspringsecurity/UserDetailsServiceImpl.java
import yourwebproject2.framework.exception.EmailNotFoundException;
import yourwebproject2.model.entity.User;
import yourwebproject2.model.repository.UserRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.*;
package yourwebproject2.unusedspringsecurity;
/**
* @author: kameshr
*/
@Service
@Transactional
public class UserDetailsServiceImpl implements UserDetailsService { | private @Autowired UserRepository userRepository; |
ykameshrao/spring-mvc-angular-js-hibernate-bootstrap-java-single-page-jwt-auth-rest-api-webapp-framework | src/main/java/yourwebproject2/unusedspringsecurity/UserDetailsServiceImpl.java | // Path: src/main/java/yourwebproject2/framework/exception/EmailNotFoundException.java
// public class EmailNotFoundException extends AuthenticationException {
// public EmailNotFoundException(String message) {
// super(message);
// }
// }
//
// Path: src/main/java/yourwebproject2/model/entity/User.java
// @Entity
// @Inheritance(strategy = InheritanceType.SINGLE_TABLE)
// @Table(indexes = { @Index(name="email_idx", columnList = "email", unique = true),
// @Index(name="displayName_idx", columnList = "display_name") })
// public class User extends JPAEntity<Long> implements Serializable {
// public enum Role {
// USER,
// ADMIN
// }
//
// private String email;
// private @JsonIgnore String password;
// private boolean enabled;
// private Role role;
// private String displayName;
//
// private @JsonIgnore Integer loginCount;
// private Date currentLoginAt;
// private Date lastLoginAt;
// private @JsonIgnore String currentLoginIp;
// private @JsonIgnore String lastLoginIp;
//
// private static BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder();
//
// @Column @Email @NotNull @NotBlank
// public String getEmail() {
// return this.email;
// }
//
// public void setEmail(String email) {
// this.email = email;
// }
//
// @JsonIgnore @Column(nullable = false, length = 60)
// public String getPassword() {
// return this.password;
// }
//
// public void setPassword(String password) {
// this.password = password;
// }
//
// @Column(nullable = false)
// public boolean isEnabled() {
// return this.enabled;
// }
//
// public void setEnabled(boolean enabled) {
// this.enabled = enabled;
// }
//
// @Column(nullable = false)
// public Role getRole() {
// return this.role;
// }
//
// public void setRole(Role role) {
// this.role = role;
// }
//
// @Column(name="display_name")
// public String getDisplayName() {
// return displayName;
// }
//
// public void setDisplayName(String displayName) {
// this.displayName = displayName;
// }
//
// @JsonIgnore @Column
// public Integer getLoginCount() {
// return loginCount;
// }
//
// public void setLoginCount(Integer loginCount) {
// this.loginCount = loginCount;
// }
//
// @Column
// public Date getCurrentLoginAt() {
// return currentLoginAt;
// }
//
// public void setCurrentLoginAt(Date currentLoginAt) {
// this.currentLoginAt = currentLoginAt;
// }
//
// @Column
// public Date getLastLoginAt() {
// return lastLoginAt;
// }
//
// public void setLastLoginAt(Date lastLoginAt) {
// this.lastLoginAt = lastLoginAt;
// }
//
// @JsonIgnore @Column
// public String getCurrentLoginIp() {
// return currentLoginIp;
// }
//
// public void setCurrentLoginIp(String currentLoginIp) {
// this.currentLoginIp = currentLoginIp;
// }
//
// @JsonIgnore @Column
// public String getLastLoginIp() {
// return lastLoginIp;
// }
//
// public void setLastLoginIp(String lastLoginIp) {
// this.lastLoginIp = lastLoginIp;
// }
//
// /**
// * Method to create the hash of the password before storing
// *
// * @param pass
// *
// * @return SHA hash digest of the password
// */
// public static synchronized String hashPassword(String pass) {
// return passwordEncoder.encode(pass);
// }
//
// public static synchronized boolean doesPasswordMatch(String rawPass, String encodedPass) {
// return passwordEncoder.matches(rawPass, encodedPass);
// }
//
// @Override
// public String toString() {
// return "User{" +
// "email='" + email + '\'' +
// ", password='" + password + '\'' +
// ", enabled=" + enabled +
// ", role=" + role +
// ", displayName='" + displayName + '\'' +
// ", loginCount=" + loginCount +
// ", currentLoginAt=" + currentLoginAt +
// ", lastLoginAt=" + lastLoginAt +
// ", currentLoginIp='" + currentLoginIp + '\'' +
// ", lastLoginIp='" + lastLoginIp + '\'' +
// '}';
// }
// }
//
// Path: src/main/java/yourwebproject2/model/repository/UserRepository.java
// public interface UserRepository extends BaseJPARepository<User, Long> {
// /**
// * Finds a user with the given email
// *
// * @param email
// * @return
// */
// public User findByEmail(String email);
// }
| import yourwebproject2.framework.exception.EmailNotFoundException;
import yourwebproject2.model.entity.User;
import yourwebproject2.model.repository.UserRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.*; | package yourwebproject2.unusedspringsecurity;
/**
* @author: kameshr
*/
@Service
@Transactional
public class UserDetailsServiceImpl implements UserDetailsService {
private @Autowired UserRepository userRepository;
@Override
@Transactional(readOnly=true)
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
return loadUserByEmail(username);
}
private UserDetails loadUserByEmail(final String email) | // Path: src/main/java/yourwebproject2/framework/exception/EmailNotFoundException.java
// public class EmailNotFoundException extends AuthenticationException {
// public EmailNotFoundException(String message) {
// super(message);
// }
// }
//
// Path: src/main/java/yourwebproject2/model/entity/User.java
// @Entity
// @Inheritance(strategy = InheritanceType.SINGLE_TABLE)
// @Table(indexes = { @Index(name="email_idx", columnList = "email", unique = true),
// @Index(name="displayName_idx", columnList = "display_name") })
// public class User extends JPAEntity<Long> implements Serializable {
// public enum Role {
// USER,
// ADMIN
// }
//
// private String email;
// private @JsonIgnore String password;
// private boolean enabled;
// private Role role;
// private String displayName;
//
// private @JsonIgnore Integer loginCount;
// private Date currentLoginAt;
// private Date lastLoginAt;
// private @JsonIgnore String currentLoginIp;
// private @JsonIgnore String lastLoginIp;
//
// private static BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder();
//
// @Column @Email @NotNull @NotBlank
// public String getEmail() {
// return this.email;
// }
//
// public void setEmail(String email) {
// this.email = email;
// }
//
// @JsonIgnore @Column(nullable = false, length = 60)
// public String getPassword() {
// return this.password;
// }
//
// public void setPassword(String password) {
// this.password = password;
// }
//
// @Column(nullable = false)
// public boolean isEnabled() {
// return this.enabled;
// }
//
// public void setEnabled(boolean enabled) {
// this.enabled = enabled;
// }
//
// @Column(nullable = false)
// public Role getRole() {
// return this.role;
// }
//
// public void setRole(Role role) {
// this.role = role;
// }
//
// @Column(name="display_name")
// public String getDisplayName() {
// return displayName;
// }
//
// public void setDisplayName(String displayName) {
// this.displayName = displayName;
// }
//
// @JsonIgnore @Column
// public Integer getLoginCount() {
// return loginCount;
// }
//
// public void setLoginCount(Integer loginCount) {
// this.loginCount = loginCount;
// }
//
// @Column
// public Date getCurrentLoginAt() {
// return currentLoginAt;
// }
//
// public void setCurrentLoginAt(Date currentLoginAt) {
// this.currentLoginAt = currentLoginAt;
// }
//
// @Column
// public Date getLastLoginAt() {
// return lastLoginAt;
// }
//
// public void setLastLoginAt(Date lastLoginAt) {
// this.lastLoginAt = lastLoginAt;
// }
//
// @JsonIgnore @Column
// public String getCurrentLoginIp() {
// return currentLoginIp;
// }
//
// public void setCurrentLoginIp(String currentLoginIp) {
// this.currentLoginIp = currentLoginIp;
// }
//
// @JsonIgnore @Column
// public String getLastLoginIp() {
// return lastLoginIp;
// }
//
// public void setLastLoginIp(String lastLoginIp) {
// this.lastLoginIp = lastLoginIp;
// }
//
// /**
// * Method to create the hash of the password before storing
// *
// * @param pass
// *
// * @return SHA hash digest of the password
// */
// public static synchronized String hashPassword(String pass) {
// return passwordEncoder.encode(pass);
// }
//
// public static synchronized boolean doesPasswordMatch(String rawPass, String encodedPass) {
// return passwordEncoder.matches(rawPass, encodedPass);
// }
//
// @Override
// public String toString() {
// return "User{" +
// "email='" + email + '\'' +
// ", password='" + password + '\'' +
// ", enabled=" + enabled +
// ", role=" + role +
// ", displayName='" + displayName + '\'' +
// ", loginCount=" + loginCount +
// ", currentLoginAt=" + currentLoginAt +
// ", lastLoginAt=" + lastLoginAt +
// ", currentLoginIp='" + currentLoginIp + '\'' +
// ", lastLoginIp='" + lastLoginIp + '\'' +
// '}';
// }
// }
//
// Path: src/main/java/yourwebproject2/model/repository/UserRepository.java
// public interface UserRepository extends BaseJPARepository<User, Long> {
// /**
// * Finds a user with the given email
// *
// * @param email
// * @return
// */
// public User findByEmail(String email);
// }
// Path: src/main/java/yourwebproject2/unusedspringsecurity/UserDetailsServiceImpl.java
import yourwebproject2.framework.exception.EmailNotFoundException;
import yourwebproject2.model.entity.User;
import yourwebproject2.model.repository.UserRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.*;
package yourwebproject2.unusedspringsecurity;
/**
* @author: kameshr
*/
@Service
@Transactional
public class UserDetailsServiceImpl implements UserDetailsService {
private @Autowired UserRepository userRepository;
@Override
@Transactional(readOnly=true)
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
return loadUserByEmail(username);
}
private UserDetails loadUserByEmail(final String email) | throws EmailNotFoundException { |
ykameshrao/spring-mvc-angular-js-hibernate-bootstrap-java-single-page-jwt-auth-rest-api-webapp-framework | src/main/java/yourwebproject2/unusedspringsecurity/UserDetailsServiceImpl.java | // Path: src/main/java/yourwebproject2/framework/exception/EmailNotFoundException.java
// public class EmailNotFoundException extends AuthenticationException {
// public EmailNotFoundException(String message) {
// super(message);
// }
// }
//
// Path: src/main/java/yourwebproject2/model/entity/User.java
// @Entity
// @Inheritance(strategy = InheritanceType.SINGLE_TABLE)
// @Table(indexes = { @Index(name="email_idx", columnList = "email", unique = true),
// @Index(name="displayName_idx", columnList = "display_name") })
// public class User extends JPAEntity<Long> implements Serializable {
// public enum Role {
// USER,
// ADMIN
// }
//
// private String email;
// private @JsonIgnore String password;
// private boolean enabled;
// private Role role;
// private String displayName;
//
// private @JsonIgnore Integer loginCount;
// private Date currentLoginAt;
// private Date lastLoginAt;
// private @JsonIgnore String currentLoginIp;
// private @JsonIgnore String lastLoginIp;
//
// private static BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder();
//
// @Column @Email @NotNull @NotBlank
// public String getEmail() {
// return this.email;
// }
//
// public void setEmail(String email) {
// this.email = email;
// }
//
// @JsonIgnore @Column(nullable = false, length = 60)
// public String getPassword() {
// return this.password;
// }
//
// public void setPassword(String password) {
// this.password = password;
// }
//
// @Column(nullable = false)
// public boolean isEnabled() {
// return this.enabled;
// }
//
// public void setEnabled(boolean enabled) {
// this.enabled = enabled;
// }
//
// @Column(nullable = false)
// public Role getRole() {
// return this.role;
// }
//
// public void setRole(Role role) {
// this.role = role;
// }
//
// @Column(name="display_name")
// public String getDisplayName() {
// return displayName;
// }
//
// public void setDisplayName(String displayName) {
// this.displayName = displayName;
// }
//
// @JsonIgnore @Column
// public Integer getLoginCount() {
// return loginCount;
// }
//
// public void setLoginCount(Integer loginCount) {
// this.loginCount = loginCount;
// }
//
// @Column
// public Date getCurrentLoginAt() {
// return currentLoginAt;
// }
//
// public void setCurrentLoginAt(Date currentLoginAt) {
// this.currentLoginAt = currentLoginAt;
// }
//
// @Column
// public Date getLastLoginAt() {
// return lastLoginAt;
// }
//
// public void setLastLoginAt(Date lastLoginAt) {
// this.lastLoginAt = lastLoginAt;
// }
//
// @JsonIgnore @Column
// public String getCurrentLoginIp() {
// return currentLoginIp;
// }
//
// public void setCurrentLoginIp(String currentLoginIp) {
// this.currentLoginIp = currentLoginIp;
// }
//
// @JsonIgnore @Column
// public String getLastLoginIp() {
// return lastLoginIp;
// }
//
// public void setLastLoginIp(String lastLoginIp) {
// this.lastLoginIp = lastLoginIp;
// }
//
// /**
// * Method to create the hash of the password before storing
// *
// * @param pass
// *
// * @return SHA hash digest of the password
// */
// public static synchronized String hashPassword(String pass) {
// return passwordEncoder.encode(pass);
// }
//
// public static synchronized boolean doesPasswordMatch(String rawPass, String encodedPass) {
// return passwordEncoder.matches(rawPass, encodedPass);
// }
//
// @Override
// public String toString() {
// return "User{" +
// "email='" + email + '\'' +
// ", password='" + password + '\'' +
// ", enabled=" + enabled +
// ", role=" + role +
// ", displayName='" + displayName + '\'' +
// ", loginCount=" + loginCount +
// ", currentLoginAt=" + currentLoginAt +
// ", lastLoginAt=" + lastLoginAt +
// ", currentLoginIp='" + currentLoginIp + '\'' +
// ", lastLoginIp='" + lastLoginIp + '\'' +
// '}';
// }
// }
//
// Path: src/main/java/yourwebproject2/model/repository/UserRepository.java
// public interface UserRepository extends BaseJPARepository<User, Long> {
// /**
// * Finds a user with the given email
// *
// * @param email
// * @return
// */
// public User findByEmail(String email);
// }
| import yourwebproject2.framework.exception.EmailNotFoundException;
import yourwebproject2.model.entity.User;
import yourwebproject2.model.repository.UserRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.*; | }
@Override
public String getUsername() {
return null;
}
@Override
public boolean isAccountNonExpired() {
return false;
}
@Override
public boolean isAccountNonLocked() {
return false;
}
@Override
public boolean isCredentialsNonExpired() {
return false;
}
@Override
public boolean isEnabled() {
return false;
}
};
}
// Converts yourwebproject2.model.entity..User user to org.springframework.security.core.userdetails.User | // Path: src/main/java/yourwebproject2/framework/exception/EmailNotFoundException.java
// public class EmailNotFoundException extends AuthenticationException {
// public EmailNotFoundException(String message) {
// super(message);
// }
// }
//
// Path: src/main/java/yourwebproject2/model/entity/User.java
// @Entity
// @Inheritance(strategy = InheritanceType.SINGLE_TABLE)
// @Table(indexes = { @Index(name="email_idx", columnList = "email", unique = true),
// @Index(name="displayName_idx", columnList = "display_name") })
// public class User extends JPAEntity<Long> implements Serializable {
// public enum Role {
// USER,
// ADMIN
// }
//
// private String email;
// private @JsonIgnore String password;
// private boolean enabled;
// private Role role;
// private String displayName;
//
// private @JsonIgnore Integer loginCount;
// private Date currentLoginAt;
// private Date lastLoginAt;
// private @JsonIgnore String currentLoginIp;
// private @JsonIgnore String lastLoginIp;
//
// private static BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder();
//
// @Column @Email @NotNull @NotBlank
// public String getEmail() {
// return this.email;
// }
//
// public void setEmail(String email) {
// this.email = email;
// }
//
// @JsonIgnore @Column(nullable = false, length = 60)
// public String getPassword() {
// return this.password;
// }
//
// public void setPassword(String password) {
// this.password = password;
// }
//
// @Column(nullable = false)
// public boolean isEnabled() {
// return this.enabled;
// }
//
// public void setEnabled(boolean enabled) {
// this.enabled = enabled;
// }
//
// @Column(nullable = false)
// public Role getRole() {
// return this.role;
// }
//
// public void setRole(Role role) {
// this.role = role;
// }
//
// @Column(name="display_name")
// public String getDisplayName() {
// return displayName;
// }
//
// public void setDisplayName(String displayName) {
// this.displayName = displayName;
// }
//
// @JsonIgnore @Column
// public Integer getLoginCount() {
// return loginCount;
// }
//
// public void setLoginCount(Integer loginCount) {
// this.loginCount = loginCount;
// }
//
// @Column
// public Date getCurrentLoginAt() {
// return currentLoginAt;
// }
//
// public void setCurrentLoginAt(Date currentLoginAt) {
// this.currentLoginAt = currentLoginAt;
// }
//
// @Column
// public Date getLastLoginAt() {
// return lastLoginAt;
// }
//
// public void setLastLoginAt(Date lastLoginAt) {
// this.lastLoginAt = lastLoginAt;
// }
//
// @JsonIgnore @Column
// public String getCurrentLoginIp() {
// return currentLoginIp;
// }
//
// public void setCurrentLoginIp(String currentLoginIp) {
// this.currentLoginIp = currentLoginIp;
// }
//
// @JsonIgnore @Column
// public String getLastLoginIp() {
// return lastLoginIp;
// }
//
// public void setLastLoginIp(String lastLoginIp) {
// this.lastLoginIp = lastLoginIp;
// }
//
// /**
// * Method to create the hash of the password before storing
// *
// * @param pass
// *
// * @return SHA hash digest of the password
// */
// public static synchronized String hashPassword(String pass) {
// return passwordEncoder.encode(pass);
// }
//
// public static synchronized boolean doesPasswordMatch(String rawPass, String encodedPass) {
// return passwordEncoder.matches(rawPass, encodedPass);
// }
//
// @Override
// public String toString() {
// return "User{" +
// "email='" + email + '\'' +
// ", password='" + password + '\'' +
// ", enabled=" + enabled +
// ", role=" + role +
// ", displayName='" + displayName + '\'' +
// ", loginCount=" + loginCount +
// ", currentLoginAt=" + currentLoginAt +
// ", lastLoginAt=" + lastLoginAt +
// ", currentLoginIp='" + currentLoginIp + '\'' +
// ", lastLoginIp='" + lastLoginIp + '\'' +
// '}';
// }
// }
//
// Path: src/main/java/yourwebproject2/model/repository/UserRepository.java
// public interface UserRepository extends BaseJPARepository<User, Long> {
// /**
// * Finds a user with the given email
// *
// * @param email
// * @return
// */
// public User findByEmail(String email);
// }
// Path: src/main/java/yourwebproject2/unusedspringsecurity/UserDetailsServiceImpl.java
import yourwebproject2.framework.exception.EmailNotFoundException;
import yourwebproject2.model.entity.User;
import yourwebproject2.model.repository.UserRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.*;
}
@Override
public String getUsername() {
return null;
}
@Override
public boolean isAccountNonExpired() {
return false;
}
@Override
public boolean isAccountNonLocked() {
return false;
}
@Override
public boolean isCredentialsNonExpired() {
return false;
}
@Override
public boolean isEnabled() {
return false;
}
};
}
// Converts yourwebproject2.model.entity..User user to org.springframework.security.core.userdetails.User | private org.springframework.security.core.userdetails.User buildUserForAuthentication(User user, |
ykameshrao/spring-mvc-angular-js-hibernate-bootstrap-java-single-page-jwt-auth-rest-api-webapp-framework | src/main/java/yourwebproject2/unusedspringsecurity/RESTAuthFilter.java | // Path: src/main/java/yourwebproject2/service/UserService.java
// public interface UserService extends BaseService<User, Long> {
//
// /**
// * Register a new user into the system
// *
// * @param user
// * @param request
// *
// * @return
// */
// public User registerUser(User user, HttpServletRequest request);
//
//
// /**
// * Login a new user into the system
// *
// * @param user
// * @param request
// *
// * @return
// */
// public User loginUser(User user, HttpServletRequest request);
//
//
// /**
// * Method to validate whether the given password
// * is same as users password stored in the system
// *
// * @param user
// * @param pass
// *
// * @return
// */
// public boolean isValidPass(User user, String pass);
//
//
// /**
// * Validates whether the given email already
// * exists in the system.
// *
// * @param email
// *
// * @return
// */
// public boolean isEmailExists(String email);
//
//
// /**
// * Finds a user entity by the given email
// *
// * @param email
// * @return
// */
// public User findByEmail(String email) throws EmailNotFoundException;
// }
| import yourwebproject2.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.filter.OncePerRequestFilter;
import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException; | package yourwebproject2.unusedspringsecurity;
/**
* @author: kameshr
*/
public class RESTAuthFilter extends OncePerRequestFilter {
@Autowired | // Path: src/main/java/yourwebproject2/service/UserService.java
// public interface UserService extends BaseService<User, Long> {
//
// /**
// * Register a new user into the system
// *
// * @param user
// * @param request
// *
// * @return
// */
// public User registerUser(User user, HttpServletRequest request);
//
//
// /**
// * Login a new user into the system
// *
// * @param user
// * @param request
// *
// * @return
// */
// public User loginUser(User user, HttpServletRequest request);
//
//
// /**
// * Method to validate whether the given password
// * is same as users password stored in the system
// *
// * @param user
// * @param pass
// *
// * @return
// */
// public boolean isValidPass(User user, String pass);
//
//
// /**
// * Validates whether the given email already
// * exists in the system.
// *
// * @param email
// *
// * @return
// */
// public boolean isEmailExists(String email);
//
//
// /**
// * Finds a user entity by the given email
// *
// * @param email
// * @return
// */
// public User findByEmail(String email) throws EmailNotFoundException;
// }
// Path: src/main/java/yourwebproject2/unusedspringsecurity/RESTAuthFilter.java
import yourwebproject2.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.filter.OncePerRequestFilter;
import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
package yourwebproject2.unusedspringsecurity;
/**
* @author: kameshr
*/
public class RESTAuthFilter extends OncePerRequestFilter {
@Autowired | private UserService userService; |
ykameshrao/spring-mvc-angular-js-hibernate-bootstrap-java-single-page-jwt-auth-rest-api-webapp-framework | src/main/java/yourwebproject2/core/JobExecutionThread.java | // Path: src/main/java/yourwebproject2/model/entity/Job.java
// @Entity
// @Table(indexes = { @Index(name="name_idx", columnList = "name", unique = true),
// @Index(name="status_idx", columnList = "status"),
// @Index(name="category_idx", columnList = "category")})
// public class Job extends JPAEntity<Long> {
// public enum Status {
// NEW, EXECUTING, PRIORITIZED, FAILED, RETRYING, SUCCESSFUL
// }
//
// private String name;
// private String metadataJson;
// private String callbackUrl;
// private Date submitTime;
// private Status status;
// private Date scheduledTime;
// private Date completionTime;
// private Integer retryCount;
// private Category category;
//
// @NotNull @NotBlank
// @Column
// public String getName() {
// return name;
// }
//
// public void setName(String name) {
// this.name = name;
// }
//
// @Column
// public String getCallbackUrl() {
// return callbackUrl;
// }
//
// public void setCallbackUrl(String callbackUrl) {
// this.callbackUrl = callbackUrl;
// }
//
// @Column
// public String getMetadataJson() {
// return metadataJson;
// }
//
// public void setMetadataJson(String metadataJson) {
// this.metadataJson = metadataJson;
// }
//
// @NotNull
// @Column
// public Date getSubmitTime() {
// return submitTime;
// }
//
// public void setSubmitTime(Date submitTime) {
// this.submitTime = submitTime;
// }
//
// @OneToOne(fetch = FetchType.EAGER)
// public Category getCategory() {
// return category;
// }
//
// public void setCategory(Category category) {
// this.category = category;
// }
//
// @NotNull
// @Column
// public Status getStatus() {
// return status;
// }
//
// public void setStatus(Status status) {
// this.status = status;
// }
//
// @Column
// public Date getScheduledTime() {
// return scheduledTime;
// }
//
// public void setScheduledTime(Date scheduledTime) {
// this.scheduledTime = scheduledTime;
// }
//
// @Column
// public Date getCompletionTime() {
// return completionTime;
// }
//
// public void setCompletionTime(Date completionTime) {
// this.completionTime = completionTime;
// }
//
// @Column
// public Integer getRetryCount() {
// return retryCount;
// }
//
// public void setRetryCount(Integer retryCount) {
// this.retryCount = retryCount;
// }
//
// @Override
// public String toString() {
// return "Job{" +
// "name='" + name + '\'' +
// ", metadataJson='" + metadataJson + '\'' +
// ", callbackUrl='" + callbackUrl + '\'' +
// ", submitTime=" + submitTime +
// ", status=" + status +
// ", scheduledTime=" + scheduledTime +
// ", completionTime=" + completionTime +
// ", retryCount=" + retryCount +
// ", category=" + category +
// '}';
// }
// }
| import yourwebproject2.model.entity.Job;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.Date;
import java.util.concurrent.Callable; | package yourwebproject2.core;
/**
* Created by Y.Kamesh on 8/2/2015.
*/
public class JobExecutionThread implements Callable {
private static Logger LOG = LoggerFactory.getLogger(JobExecutionThread.class); | // Path: src/main/java/yourwebproject2/model/entity/Job.java
// @Entity
// @Table(indexes = { @Index(name="name_idx", columnList = "name", unique = true),
// @Index(name="status_idx", columnList = "status"),
// @Index(name="category_idx", columnList = "category")})
// public class Job extends JPAEntity<Long> {
// public enum Status {
// NEW, EXECUTING, PRIORITIZED, FAILED, RETRYING, SUCCESSFUL
// }
//
// private String name;
// private String metadataJson;
// private String callbackUrl;
// private Date submitTime;
// private Status status;
// private Date scheduledTime;
// private Date completionTime;
// private Integer retryCount;
// private Category category;
//
// @NotNull @NotBlank
// @Column
// public String getName() {
// return name;
// }
//
// public void setName(String name) {
// this.name = name;
// }
//
// @Column
// public String getCallbackUrl() {
// return callbackUrl;
// }
//
// public void setCallbackUrl(String callbackUrl) {
// this.callbackUrl = callbackUrl;
// }
//
// @Column
// public String getMetadataJson() {
// return metadataJson;
// }
//
// public void setMetadataJson(String metadataJson) {
// this.metadataJson = metadataJson;
// }
//
// @NotNull
// @Column
// public Date getSubmitTime() {
// return submitTime;
// }
//
// public void setSubmitTime(Date submitTime) {
// this.submitTime = submitTime;
// }
//
// @OneToOne(fetch = FetchType.EAGER)
// public Category getCategory() {
// return category;
// }
//
// public void setCategory(Category category) {
// this.category = category;
// }
//
// @NotNull
// @Column
// public Status getStatus() {
// return status;
// }
//
// public void setStatus(Status status) {
// this.status = status;
// }
//
// @Column
// public Date getScheduledTime() {
// return scheduledTime;
// }
//
// public void setScheduledTime(Date scheduledTime) {
// this.scheduledTime = scheduledTime;
// }
//
// @Column
// public Date getCompletionTime() {
// return completionTime;
// }
//
// public void setCompletionTime(Date completionTime) {
// this.completionTime = completionTime;
// }
//
// @Column
// public Integer getRetryCount() {
// return retryCount;
// }
//
// public void setRetryCount(Integer retryCount) {
// this.retryCount = retryCount;
// }
//
// @Override
// public String toString() {
// return "Job{" +
// "name='" + name + '\'' +
// ", metadataJson='" + metadataJson + '\'' +
// ", callbackUrl='" + callbackUrl + '\'' +
// ", submitTime=" + submitTime +
// ", status=" + status +
// ", scheduledTime=" + scheduledTime +
// ", completionTime=" + completionTime +
// ", retryCount=" + retryCount +
// ", category=" + category +
// '}';
// }
// }
// Path: src/main/java/yourwebproject2/core/JobExecutionThread.java
import yourwebproject2.model.entity.Job;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.Date;
import java.util.concurrent.Callable;
package yourwebproject2.core;
/**
* Created by Y.Kamesh on 8/2/2015.
*/
public class JobExecutionThread implements Callable {
private static Logger LOG = LoggerFactory.getLogger(JobExecutionThread.class); | private Job job; |
ykameshrao/spring-mvc-angular-js-hibernate-bootstrap-java-single-page-jwt-auth-rest-api-webapp-framework | src/main/java/yourwebproject2/service/CategoryService.java | // Path: src/main/java/yourwebproject2/framework/data/BaseService.java
// public interface BaseService<T extends Entity, ID extends Serializable> {
// /**
// * Method to setup the service with basic
// * required data. Called after Spring initialization.
// */
// public void setupService();
//
// /**
// * Service to insert the new object
// *
// * @param object
// * The newly object
// */
// public T insert(T object) throws Exception;
//
// /**
// * Service to update an existing object
// *
// * @param object
// * The existing object
// */
// public T update(T object) throws Exception;
//
// /**
// * Service to delete an existing object
// *
// * @param object
// * The existing object
// */
// public void delete(T object) throws Exception;
//
// /**
// * Service to find an existing object by its given id and query name
// *
// * @param id
// * Id of the resource
// */
// public T findById(ID id) throws Exception;
//
//
// /**
// * Service to find a collection of entities by pages
// *
// * @param pageNum
// * @param countPerPage
// * @param order
// *
// * @return
// *
// * @throws Exception
// */
// public Collection<T> findAllByPage(int pageNum, int countPerPage, Order order) throws Exception;
// }
//
// Path: src/main/java/yourwebproject2/framework/exception/NotFoundException.java
// public class NotFoundException extends Exception {
// public NotFoundException(String message) {
// super(message);
// }
// }
//
// Path: src/main/java/yourwebproject2/model/entity/Category.java
// @Entity
// @Table(indexes = { @Index(name="name_idx", columnList = "name", unique = true),
// @Index(name="priority_idx", columnList = "priority"),
// @Index(name="parentCategory_idx", columnList = "parent_category")})
// public class Category extends JPAEntity<Long> {
// private String name;
// private Integer priority;
// private Category parentCategory;
//
// @NotNull @NotBlank
// @Column
// public String getName() {
// return name;
// }
//
// public void setName(String name) {
// this.name = name;
// }
//
// @NotNull
// @Column
// public Integer getPriority() {
// return priority;
// }
//
// public void setPriority(Integer priority) {
// this.priority = priority;
// }
//
// @ManyToOne(fetch = FetchType.EAGER)
// public Category getParentCategory() {
// return parentCategory;
// }
//
// public void setParentCategory(Category parentCategory) {
// this.parentCategory = parentCategory;
// }
//
// @Override
// public String toString() {
// return "Category{" +
// "name='" + name + '\'' +
// ", priority=" + priority +
// ", parentCategory=" + parentCategory +
// '}';
// }
// }
| import yourwebproject2.framework.data.BaseService;
import yourwebproject2.framework.exception.NotFoundException;
import yourwebproject2.model.entity.Category;
import java.util.List; | package yourwebproject2.service;
/**
* Brings in the basic CRUD service ops from BaseService. Insert additional ops here.
*
* Created by Y.Kamesh on 8/2/2015.
*/
public interface CategoryService extends BaseService<Category, Long> {
/**
* Validates whether the given category already
* exists in the system.
*
* @param categoryName
*
* @return
*/
public boolean isCategoryPresent(String categoryName);
/**
* Validates whether the given category priority already
* exists in the system.
*
* @param priorityId
*
* @return
*/
public boolean isPriorityPresent(Integer priorityId);
/**
* Find category by name
*
* @param categoryName
* @return
*/ | // Path: src/main/java/yourwebproject2/framework/data/BaseService.java
// public interface BaseService<T extends Entity, ID extends Serializable> {
// /**
// * Method to setup the service with basic
// * required data. Called after Spring initialization.
// */
// public void setupService();
//
// /**
// * Service to insert the new object
// *
// * @param object
// * The newly object
// */
// public T insert(T object) throws Exception;
//
// /**
// * Service to update an existing object
// *
// * @param object
// * The existing object
// */
// public T update(T object) throws Exception;
//
// /**
// * Service to delete an existing object
// *
// * @param object
// * The existing object
// */
// public void delete(T object) throws Exception;
//
// /**
// * Service to find an existing object by its given id and query name
// *
// * @param id
// * Id of the resource
// */
// public T findById(ID id) throws Exception;
//
//
// /**
// * Service to find a collection of entities by pages
// *
// * @param pageNum
// * @param countPerPage
// * @param order
// *
// * @return
// *
// * @throws Exception
// */
// public Collection<T> findAllByPage(int pageNum, int countPerPage, Order order) throws Exception;
// }
//
// Path: src/main/java/yourwebproject2/framework/exception/NotFoundException.java
// public class NotFoundException extends Exception {
// public NotFoundException(String message) {
// super(message);
// }
// }
//
// Path: src/main/java/yourwebproject2/model/entity/Category.java
// @Entity
// @Table(indexes = { @Index(name="name_idx", columnList = "name", unique = true),
// @Index(name="priority_idx", columnList = "priority"),
// @Index(name="parentCategory_idx", columnList = "parent_category")})
// public class Category extends JPAEntity<Long> {
// private String name;
// private Integer priority;
// private Category parentCategory;
//
// @NotNull @NotBlank
// @Column
// public String getName() {
// return name;
// }
//
// public void setName(String name) {
// this.name = name;
// }
//
// @NotNull
// @Column
// public Integer getPriority() {
// return priority;
// }
//
// public void setPriority(Integer priority) {
// this.priority = priority;
// }
//
// @ManyToOne(fetch = FetchType.EAGER)
// public Category getParentCategory() {
// return parentCategory;
// }
//
// public void setParentCategory(Category parentCategory) {
// this.parentCategory = parentCategory;
// }
//
// @Override
// public String toString() {
// return "Category{" +
// "name='" + name + '\'' +
// ", priority=" + priority +
// ", parentCategory=" + parentCategory +
// '}';
// }
// }
// Path: src/main/java/yourwebproject2/service/CategoryService.java
import yourwebproject2.framework.data.BaseService;
import yourwebproject2.framework.exception.NotFoundException;
import yourwebproject2.model.entity.Category;
import java.util.List;
package yourwebproject2.service;
/**
* Brings in the basic CRUD service ops from BaseService. Insert additional ops here.
*
* Created by Y.Kamesh on 8/2/2015.
*/
public interface CategoryService extends BaseService<Category, Long> {
/**
* Validates whether the given category already
* exists in the system.
*
* @param categoryName
*
* @return
*/
public boolean isCategoryPresent(String categoryName);
/**
* Validates whether the given category priority already
* exists in the system.
*
* @param priorityId
*
* @return
*/
public boolean isPriorityPresent(Integer priorityId);
/**
* Find category by name
*
* @param categoryName
* @return
*/ | public Category findByCategoryName(String categoryName) throws NotFoundException; |
ykameshrao/spring-mvc-angular-js-hibernate-bootstrap-java-single-page-jwt-auth-rest-api-webapp-framework | src/main/java/yourwebproject2/auth/JWTTokenAuthFilter.java | // Path: src/main/java/yourwebproject2/service/UserService.java
// public interface UserService extends BaseService<User, Long> {
//
// /**
// * Register a new user into the system
// *
// * @param user
// * @param request
// *
// * @return
// */
// public User registerUser(User user, HttpServletRequest request);
//
//
// /**
// * Login a new user into the system
// *
// * @param user
// * @param request
// *
// * @return
// */
// public User loginUser(User user, HttpServletRequest request);
//
//
// /**
// * Method to validate whether the given password
// * is same as users password stored in the system
// *
// * @param user
// * @param pass
// *
// * @return
// */
// public boolean isValidPass(User user, String pass);
//
//
// /**
// * Validates whether the given email already
// * exists in the system.
// *
// * @param email
// *
// * @return
// */
// public boolean isEmailExists(String email);
//
//
// /**
// * Finds a user entity by the given email
// *
// * @param email
// * @return
// */
// public User findByEmail(String email) throws EmailNotFoundException;
// }
| import io.jsonwebtoken.Claims;
import io.jsonwebtoken.Jwts;
import yourwebproject2.service.UserService;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.filter.OncePerRequestFilter;
import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Pattern; | package yourwebproject2.auth;
/**
* @author: kameshr
*/
public class JWTTokenAuthFilter extends OncePerRequestFilter {
private static List<Pattern> AUTH_ROUTES = new ArrayList<>();
private static List<String> NO_AUTH_ROUTES = new ArrayList<>();
public static final String JWT_KEY = "JWT-TOKEN-SECRET";
static {
AUTH_ROUTES.add(Pattern.compile("/api/*"));
NO_AUTH_ROUTES.add("/api/user/authenticate");
NO_AUTH_ROUTES.add("/api/user/register");
}
private Logger LOG = LoggerFactory.getLogger(JWTTokenAuthFilter.class);
@Autowired | // Path: src/main/java/yourwebproject2/service/UserService.java
// public interface UserService extends BaseService<User, Long> {
//
// /**
// * Register a new user into the system
// *
// * @param user
// * @param request
// *
// * @return
// */
// public User registerUser(User user, HttpServletRequest request);
//
//
// /**
// * Login a new user into the system
// *
// * @param user
// * @param request
// *
// * @return
// */
// public User loginUser(User user, HttpServletRequest request);
//
//
// /**
// * Method to validate whether the given password
// * is same as users password stored in the system
// *
// * @param user
// * @param pass
// *
// * @return
// */
// public boolean isValidPass(User user, String pass);
//
//
// /**
// * Validates whether the given email already
// * exists in the system.
// *
// * @param email
// *
// * @return
// */
// public boolean isEmailExists(String email);
//
//
// /**
// * Finds a user entity by the given email
// *
// * @param email
// * @return
// */
// public User findByEmail(String email) throws EmailNotFoundException;
// }
// Path: src/main/java/yourwebproject2/auth/JWTTokenAuthFilter.java
import io.jsonwebtoken.Claims;
import io.jsonwebtoken.Jwts;
import yourwebproject2.service.UserService;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.filter.OncePerRequestFilter;
import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Pattern;
package yourwebproject2.auth;
/**
* @author: kameshr
*/
public class JWTTokenAuthFilter extends OncePerRequestFilter {
private static List<Pattern> AUTH_ROUTES = new ArrayList<>();
private static List<String> NO_AUTH_ROUTES = new ArrayList<>();
public static final String JWT_KEY = "JWT-TOKEN-SECRET";
static {
AUTH_ROUTES.add(Pattern.compile("/api/*"));
NO_AUTH_ROUTES.add("/api/user/authenticate");
NO_AUTH_ROUTES.add("/api/user/register");
}
private Logger LOG = LoggerFactory.getLogger(JWTTokenAuthFilter.class);
@Autowired | private UserService userService; |
ykameshrao/spring-mvc-angular-js-hibernate-bootstrap-java-single-page-jwt-auth-rest-api-webapp-framework | src/main/java/yourwebproject2/core/RetryJobSchedulingWorker.java | // Path: src/main/java/yourwebproject2/model/entity/Job.java
// @Entity
// @Table(indexes = { @Index(name="name_idx", columnList = "name", unique = true),
// @Index(name="status_idx", columnList = "status"),
// @Index(name="category_idx", columnList = "category")})
// public class Job extends JPAEntity<Long> {
// public enum Status {
// NEW, EXECUTING, PRIORITIZED, FAILED, RETRYING, SUCCESSFUL
// }
//
// private String name;
// private String metadataJson;
// private String callbackUrl;
// private Date submitTime;
// private Status status;
// private Date scheduledTime;
// private Date completionTime;
// private Integer retryCount;
// private Category category;
//
// @NotNull @NotBlank
// @Column
// public String getName() {
// return name;
// }
//
// public void setName(String name) {
// this.name = name;
// }
//
// @Column
// public String getCallbackUrl() {
// return callbackUrl;
// }
//
// public void setCallbackUrl(String callbackUrl) {
// this.callbackUrl = callbackUrl;
// }
//
// @Column
// public String getMetadataJson() {
// return metadataJson;
// }
//
// public void setMetadataJson(String metadataJson) {
// this.metadataJson = metadataJson;
// }
//
// @NotNull
// @Column
// public Date getSubmitTime() {
// return submitTime;
// }
//
// public void setSubmitTime(Date submitTime) {
// this.submitTime = submitTime;
// }
//
// @OneToOne(fetch = FetchType.EAGER)
// public Category getCategory() {
// return category;
// }
//
// public void setCategory(Category category) {
// this.category = category;
// }
//
// @NotNull
// @Column
// public Status getStatus() {
// return status;
// }
//
// public void setStatus(Status status) {
// this.status = status;
// }
//
// @Column
// public Date getScheduledTime() {
// return scheduledTime;
// }
//
// public void setScheduledTime(Date scheduledTime) {
// this.scheduledTime = scheduledTime;
// }
//
// @Column
// public Date getCompletionTime() {
// return completionTime;
// }
//
// public void setCompletionTime(Date completionTime) {
// this.completionTime = completionTime;
// }
//
// @Column
// public Integer getRetryCount() {
// return retryCount;
// }
//
// public void setRetryCount(Integer retryCount) {
// this.retryCount = retryCount;
// }
//
// @Override
// public String toString() {
// return "Job{" +
// "name='" + name + '\'' +
// ", metadataJson='" + metadataJson + '\'' +
// ", callbackUrl='" + callbackUrl + '\'' +
// ", submitTime=" + submitTime +
// ", status=" + status +
// ", scheduledTime=" + scheduledTime +
// ", completionTime=" + completionTime +
// ", retryCount=" + retryCount +
// ", category=" + category +
// '}';
// }
// }
//
// Path: src/main/java/yourwebproject2/model/entity/helper/CategoryPriorityComparator.java
// public class CategoryPriorityComparator implements Comparator<Job> {
//
// /**
// * Compares its two arguments for order. Returns a negative integer, zero, or a positive integer as
// * the first argument is less than, equal to, or greater than the second.
// *
// * @param o1
// * @param o2
// * @return
// */
// @Override
// public int compare(Job o1, Job o2) {
// // ordering of priority is 1... 2... 3.... N...., where 1 is higher
// if(o1.getCategory().getPriority() > o2.getCategory().getPriority()) {
// return 1;
// } else if(o1.getCategory().getPriority() < o2.getCategory().getPriority()) {
// return -1;
// } else {
// return 0;
// }
// }
// }
//
// Path: src/main/java/yourwebproject2/service/JobService.java
// public interface JobService extends BaseService<Job, Long> {
// /**
// *
// * @param count
// * @return
// */
// public List<Job> fetchNewJobsToBeScheduledForExecutionPerPriority(int count);
//
// /**
// *
// * @param count
// * @return
// */
// public List<Job> fetchFailedJobsToBeScheduledForExecutionPerPriority(int count);
//
// /**
// *
// * @param count
// * @return
// */
// public List<Job> fetchNewJobsToBeScheduledForExecutionPerSubmissionTimePriority(int count);
//
// /**
// *
// * @param count
// * @return
// */
// public List<Job> fetchFailedJobsToBeScheduledForExecutionPerSubmissionTimePriority(int count);
// }
| import yourwebproject2.model.entity.Job;
import yourwebproject2.model.entity.helper.CategoryPriorityComparator;
import yourwebproject2.service.JobService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import java.util.*;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future; | package yourwebproject2.core;
/**
* Created by Y.Kamesh on 8/5/2015.
*/
public class RetryJobSchedulingWorker extends AbstractJobSchedulingWorker {
private static Logger LOG = LoggerFactory.getLogger(RetryJobSchedulingWorker.class);
@Autowired | // Path: src/main/java/yourwebproject2/model/entity/Job.java
// @Entity
// @Table(indexes = { @Index(name="name_idx", columnList = "name", unique = true),
// @Index(name="status_idx", columnList = "status"),
// @Index(name="category_idx", columnList = "category")})
// public class Job extends JPAEntity<Long> {
// public enum Status {
// NEW, EXECUTING, PRIORITIZED, FAILED, RETRYING, SUCCESSFUL
// }
//
// private String name;
// private String metadataJson;
// private String callbackUrl;
// private Date submitTime;
// private Status status;
// private Date scheduledTime;
// private Date completionTime;
// private Integer retryCount;
// private Category category;
//
// @NotNull @NotBlank
// @Column
// public String getName() {
// return name;
// }
//
// public void setName(String name) {
// this.name = name;
// }
//
// @Column
// public String getCallbackUrl() {
// return callbackUrl;
// }
//
// public void setCallbackUrl(String callbackUrl) {
// this.callbackUrl = callbackUrl;
// }
//
// @Column
// public String getMetadataJson() {
// return metadataJson;
// }
//
// public void setMetadataJson(String metadataJson) {
// this.metadataJson = metadataJson;
// }
//
// @NotNull
// @Column
// public Date getSubmitTime() {
// return submitTime;
// }
//
// public void setSubmitTime(Date submitTime) {
// this.submitTime = submitTime;
// }
//
// @OneToOne(fetch = FetchType.EAGER)
// public Category getCategory() {
// return category;
// }
//
// public void setCategory(Category category) {
// this.category = category;
// }
//
// @NotNull
// @Column
// public Status getStatus() {
// return status;
// }
//
// public void setStatus(Status status) {
// this.status = status;
// }
//
// @Column
// public Date getScheduledTime() {
// return scheduledTime;
// }
//
// public void setScheduledTime(Date scheduledTime) {
// this.scheduledTime = scheduledTime;
// }
//
// @Column
// public Date getCompletionTime() {
// return completionTime;
// }
//
// public void setCompletionTime(Date completionTime) {
// this.completionTime = completionTime;
// }
//
// @Column
// public Integer getRetryCount() {
// return retryCount;
// }
//
// public void setRetryCount(Integer retryCount) {
// this.retryCount = retryCount;
// }
//
// @Override
// public String toString() {
// return "Job{" +
// "name='" + name + '\'' +
// ", metadataJson='" + metadataJson + '\'' +
// ", callbackUrl='" + callbackUrl + '\'' +
// ", submitTime=" + submitTime +
// ", status=" + status +
// ", scheduledTime=" + scheduledTime +
// ", completionTime=" + completionTime +
// ", retryCount=" + retryCount +
// ", category=" + category +
// '}';
// }
// }
//
// Path: src/main/java/yourwebproject2/model/entity/helper/CategoryPriorityComparator.java
// public class CategoryPriorityComparator implements Comparator<Job> {
//
// /**
// * Compares its two arguments for order. Returns a negative integer, zero, or a positive integer as
// * the first argument is less than, equal to, or greater than the second.
// *
// * @param o1
// * @param o2
// * @return
// */
// @Override
// public int compare(Job o1, Job o2) {
// // ordering of priority is 1... 2... 3.... N...., where 1 is higher
// if(o1.getCategory().getPriority() > o2.getCategory().getPriority()) {
// return 1;
// } else if(o1.getCategory().getPriority() < o2.getCategory().getPriority()) {
// return -1;
// } else {
// return 0;
// }
// }
// }
//
// Path: src/main/java/yourwebproject2/service/JobService.java
// public interface JobService extends BaseService<Job, Long> {
// /**
// *
// * @param count
// * @return
// */
// public List<Job> fetchNewJobsToBeScheduledForExecutionPerPriority(int count);
//
// /**
// *
// * @param count
// * @return
// */
// public List<Job> fetchFailedJobsToBeScheduledForExecutionPerPriority(int count);
//
// /**
// *
// * @param count
// * @return
// */
// public List<Job> fetchNewJobsToBeScheduledForExecutionPerSubmissionTimePriority(int count);
//
// /**
// *
// * @param count
// * @return
// */
// public List<Job> fetchFailedJobsToBeScheduledForExecutionPerSubmissionTimePriority(int count);
// }
// Path: src/main/java/yourwebproject2/core/RetryJobSchedulingWorker.java
import yourwebproject2.model.entity.Job;
import yourwebproject2.model.entity.helper.CategoryPriorityComparator;
import yourwebproject2.service.JobService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import java.util.*;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
package yourwebproject2.core;
/**
* Created by Y.Kamesh on 8/5/2015.
*/
public class RetryJobSchedulingWorker extends AbstractJobSchedulingWorker {
private static Logger LOG = LoggerFactory.getLogger(RetryJobSchedulingWorker.class);
@Autowired | private JobService jobService; |
ykameshrao/spring-mvc-angular-js-hibernate-bootstrap-java-single-page-jwt-auth-rest-api-webapp-framework | src/main/java/yourwebproject2/core/RetryJobSchedulingWorker.java | // Path: src/main/java/yourwebproject2/model/entity/Job.java
// @Entity
// @Table(indexes = { @Index(name="name_idx", columnList = "name", unique = true),
// @Index(name="status_idx", columnList = "status"),
// @Index(name="category_idx", columnList = "category")})
// public class Job extends JPAEntity<Long> {
// public enum Status {
// NEW, EXECUTING, PRIORITIZED, FAILED, RETRYING, SUCCESSFUL
// }
//
// private String name;
// private String metadataJson;
// private String callbackUrl;
// private Date submitTime;
// private Status status;
// private Date scheduledTime;
// private Date completionTime;
// private Integer retryCount;
// private Category category;
//
// @NotNull @NotBlank
// @Column
// public String getName() {
// return name;
// }
//
// public void setName(String name) {
// this.name = name;
// }
//
// @Column
// public String getCallbackUrl() {
// return callbackUrl;
// }
//
// public void setCallbackUrl(String callbackUrl) {
// this.callbackUrl = callbackUrl;
// }
//
// @Column
// public String getMetadataJson() {
// return metadataJson;
// }
//
// public void setMetadataJson(String metadataJson) {
// this.metadataJson = metadataJson;
// }
//
// @NotNull
// @Column
// public Date getSubmitTime() {
// return submitTime;
// }
//
// public void setSubmitTime(Date submitTime) {
// this.submitTime = submitTime;
// }
//
// @OneToOne(fetch = FetchType.EAGER)
// public Category getCategory() {
// return category;
// }
//
// public void setCategory(Category category) {
// this.category = category;
// }
//
// @NotNull
// @Column
// public Status getStatus() {
// return status;
// }
//
// public void setStatus(Status status) {
// this.status = status;
// }
//
// @Column
// public Date getScheduledTime() {
// return scheduledTime;
// }
//
// public void setScheduledTime(Date scheduledTime) {
// this.scheduledTime = scheduledTime;
// }
//
// @Column
// public Date getCompletionTime() {
// return completionTime;
// }
//
// public void setCompletionTime(Date completionTime) {
// this.completionTime = completionTime;
// }
//
// @Column
// public Integer getRetryCount() {
// return retryCount;
// }
//
// public void setRetryCount(Integer retryCount) {
// this.retryCount = retryCount;
// }
//
// @Override
// public String toString() {
// return "Job{" +
// "name='" + name + '\'' +
// ", metadataJson='" + metadataJson + '\'' +
// ", callbackUrl='" + callbackUrl + '\'' +
// ", submitTime=" + submitTime +
// ", status=" + status +
// ", scheduledTime=" + scheduledTime +
// ", completionTime=" + completionTime +
// ", retryCount=" + retryCount +
// ", category=" + category +
// '}';
// }
// }
//
// Path: src/main/java/yourwebproject2/model/entity/helper/CategoryPriorityComparator.java
// public class CategoryPriorityComparator implements Comparator<Job> {
//
// /**
// * Compares its two arguments for order. Returns a negative integer, zero, or a positive integer as
// * the first argument is less than, equal to, or greater than the second.
// *
// * @param o1
// * @param o2
// * @return
// */
// @Override
// public int compare(Job o1, Job o2) {
// // ordering of priority is 1... 2... 3.... N...., where 1 is higher
// if(o1.getCategory().getPriority() > o2.getCategory().getPriority()) {
// return 1;
// } else if(o1.getCategory().getPriority() < o2.getCategory().getPriority()) {
// return -1;
// } else {
// return 0;
// }
// }
// }
//
// Path: src/main/java/yourwebproject2/service/JobService.java
// public interface JobService extends BaseService<Job, Long> {
// /**
// *
// * @param count
// * @return
// */
// public List<Job> fetchNewJobsToBeScheduledForExecutionPerPriority(int count);
//
// /**
// *
// * @param count
// * @return
// */
// public List<Job> fetchFailedJobsToBeScheduledForExecutionPerPriority(int count);
//
// /**
// *
// * @param count
// * @return
// */
// public List<Job> fetchNewJobsToBeScheduledForExecutionPerSubmissionTimePriority(int count);
//
// /**
// *
// * @param count
// * @return
// */
// public List<Job> fetchFailedJobsToBeScheduledForExecutionPerSubmissionTimePriority(int count);
// }
| import yourwebproject2.model.entity.Job;
import yourwebproject2.model.entity.helper.CategoryPriorityComparator;
import yourwebproject2.service.JobService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import java.util.*;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future; | package yourwebproject2.core;
/**
* Created by Y.Kamesh on 8/5/2015.
*/
public class RetryJobSchedulingWorker extends AbstractJobSchedulingWorker {
private static Logger LOG = LoggerFactory.getLogger(RetryJobSchedulingWorker.class);
@Autowired
private JobService jobService;
private ExecutorService executorService = Executors.newFixedThreadPool(50);
/**
* Runs every fifteen minutes.
*/
@Scheduled(initialDelay = 5000L, fixedRate = 15 * 60 * 1000L)
public void scheduleRetryJobsForExecution() {
LOG.info("Fetching failed jobs as per category and submit time priority..."); | // Path: src/main/java/yourwebproject2/model/entity/Job.java
// @Entity
// @Table(indexes = { @Index(name="name_idx", columnList = "name", unique = true),
// @Index(name="status_idx", columnList = "status"),
// @Index(name="category_idx", columnList = "category")})
// public class Job extends JPAEntity<Long> {
// public enum Status {
// NEW, EXECUTING, PRIORITIZED, FAILED, RETRYING, SUCCESSFUL
// }
//
// private String name;
// private String metadataJson;
// private String callbackUrl;
// private Date submitTime;
// private Status status;
// private Date scheduledTime;
// private Date completionTime;
// private Integer retryCount;
// private Category category;
//
// @NotNull @NotBlank
// @Column
// public String getName() {
// return name;
// }
//
// public void setName(String name) {
// this.name = name;
// }
//
// @Column
// public String getCallbackUrl() {
// return callbackUrl;
// }
//
// public void setCallbackUrl(String callbackUrl) {
// this.callbackUrl = callbackUrl;
// }
//
// @Column
// public String getMetadataJson() {
// return metadataJson;
// }
//
// public void setMetadataJson(String metadataJson) {
// this.metadataJson = metadataJson;
// }
//
// @NotNull
// @Column
// public Date getSubmitTime() {
// return submitTime;
// }
//
// public void setSubmitTime(Date submitTime) {
// this.submitTime = submitTime;
// }
//
// @OneToOne(fetch = FetchType.EAGER)
// public Category getCategory() {
// return category;
// }
//
// public void setCategory(Category category) {
// this.category = category;
// }
//
// @NotNull
// @Column
// public Status getStatus() {
// return status;
// }
//
// public void setStatus(Status status) {
// this.status = status;
// }
//
// @Column
// public Date getScheduledTime() {
// return scheduledTime;
// }
//
// public void setScheduledTime(Date scheduledTime) {
// this.scheduledTime = scheduledTime;
// }
//
// @Column
// public Date getCompletionTime() {
// return completionTime;
// }
//
// public void setCompletionTime(Date completionTime) {
// this.completionTime = completionTime;
// }
//
// @Column
// public Integer getRetryCount() {
// return retryCount;
// }
//
// public void setRetryCount(Integer retryCount) {
// this.retryCount = retryCount;
// }
//
// @Override
// public String toString() {
// return "Job{" +
// "name='" + name + '\'' +
// ", metadataJson='" + metadataJson + '\'' +
// ", callbackUrl='" + callbackUrl + '\'' +
// ", submitTime=" + submitTime +
// ", status=" + status +
// ", scheduledTime=" + scheduledTime +
// ", completionTime=" + completionTime +
// ", retryCount=" + retryCount +
// ", category=" + category +
// '}';
// }
// }
//
// Path: src/main/java/yourwebproject2/model/entity/helper/CategoryPriorityComparator.java
// public class CategoryPriorityComparator implements Comparator<Job> {
//
// /**
// * Compares its two arguments for order. Returns a negative integer, zero, or a positive integer as
// * the first argument is less than, equal to, or greater than the second.
// *
// * @param o1
// * @param o2
// * @return
// */
// @Override
// public int compare(Job o1, Job o2) {
// // ordering of priority is 1... 2... 3.... N...., where 1 is higher
// if(o1.getCategory().getPriority() > o2.getCategory().getPriority()) {
// return 1;
// } else if(o1.getCategory().getPriority() < o2.getCategory().getPriority()) {
// return -1;
// } else {
// return 0;
// }
// }
// }
//
// Path: src/main/java/yourwebproject2/service/JobService.java
// public interface JobService extends BaseService<Job, Long> {
// /**
// *
// * @param count
// * @return
// */
// public List<Job> fetchNewJobsToBeScheduledForExecutionPerPriority(int count);
//
// /**
// *
// * @param count
// * @return
// */
// public List<Job> fetchFailedJobsToBeScheduledForExecutionPerPriority(int count);
//
// /**
// *
// * @param count
// * @return
// */
// public List<Job> fetchNewJobsToBeScheduledForExecutionPerSubmissionTimePriority(int count);
//
// /**
// *
// * @param count
// * @return
// */
// public List<Job> fetchFailedJobsToBeScheduledForExecutionPerSubmissionTimePriority(int count);
// }
// Path: src/main/java/yourwebproject2/core/RetryJobSchedulingWorker.java
import yourwebproject2.model.entity.Job;
import yourwebproject2.model.entity.helper.CategoryPriorityComparator;
import yourwebproject2.service.JobService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import java.util.*;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
package yourwebproject2.core;
/**
* Created by Y.Kamesh on 8/5/2015.
*/
public class RetryJobSchedulingWorker extends AbstractJobSchedulingWorker {
private static Logger LOG = LoggerFactory.getLogger(RetryJobSchedulingWorker.class);
@Autowired
private JobService jobService;
private ExecutorService executorService = Executors.newFixedThreadPool(50);
/**
* Runs every fifteen minutes.
*/
@Scheduled(initialDelay = 5000L, fixedRate = 15 * 60 * 1000L)
public void scheduleRetryJobsForExecution() {
LOG.info("Fetching failed jobs as per category and submit time priority..."); | List<Job> retryableJobs = jobService.fetchFailedJobsToBeScheduledForExecutionPerSubmissionTimePriority(10); |
ykameshrao/spring-mvc-angular-js-hibernate-bootstrap-java-single-page-jwt-auth-rest-api-webapp-framework | src/main/java/yourwebproject2/core/RetryJobSchedulingWorker.java | // Path: src/main/java/yourwebproject2/model/entity/Job.java
// @Entity
// @Table(indexes = { @Index(name="name_idx", columnList = "name", unique = true),
// @Index(name="status_idx", columnList = "status"),
// @Index(name="category_idx", columnList = "category")})
// public class Job extends JPAEntity<Long> {
// public enum Status {
// NEW, EXECUTING, PRIORITIZED, FAILED, RETRYING, SUCCESSFUL
// }
//
// private String name;
// private String metadataJson;
// private String callbackUrl;
// private Date submitTime;
// private Status status;
// private Date scheduledTime;
// private Date completionTime;
// private Integer retryCount;
// private Category category;
//
// @NotNull @NotBlank
// @Column
// public String getName() {
// return name;
// }
//
// public void setName(String name) {
// this.name = name;
// }
//
// @Column
// public String getCallbackUrl() {
// return callbackUrl;
// }
//
// public void setCallbackUrl(String callbackUrl) {
// this.callbackUrl = callbackUrl;
// }
//
// @Column
// public String getMetadataJson() {
// return metadataJson;
// }
//
// public void setMetadataJson(String metadataJson) {
// this.metadataJson = metadataJson;
// }
//
// @NotNull
// @Column
// public Date getSubmitTime() {
// return submitTime;
// }
//
// public void setSubmitTime(Date submitTime) {
// this.submitTime = submitTime;
// }
//
// @OneToOne(fetch = FetchType.EAGER)
// public Category getCategory() {
// return category;
// }
//
// public void setCategory(Category category) {
// this.category = category;
// }
//
// @NotNull
// @Column
// public Status getStatus() {
// return status;
// }
//
// public void setStatus(Status status) {
// this.status = status;
// }
//
// @Column
// public Date getScheduledTime() {
// return scheduledTime;
// }
//
// public void setScheduledTime(Date scheduledTime) {
// this.scheduledTime = scheduledTime;
// }
//
// @Column
// public Date getCompletionTime() {
// return completionTime;
// }
//
// public void setCompletionTime(Date completionTime) {
// this.completionTime = completionTime;
// }
//
// @Column
// public Integer getRetryCount() {
// return retryCount;
// }
//
// public void setRetryCount(Integer retryCount) {
// this.retryCount = retryCount;
// }
//
// @Override
// public String toString() {
// return "Job{" +
// "name='" + name + '\'' +
// ", metadataJson='" + metadataJson + '\'' +
// ", callbackUrl='" + callbackUrl + '\'' +
// ", submitTime=" + submitTime +
// ", status=" + status +
// ", scheduledTime=" + scheduledTime +
// ", completionTime=" + completionTime +
// ", retryCount=" + retryCount +
// ", category=" + category +
// '}';
// }
// }
//
// Path: src/main/java/yourwebproject2/model/entity/helper/CategoryPriorityComparator.java
// public class CategoryPriorityComparator implements Comparator<Job> {
//
// /**
// * Compares its two arguments for order. Returns a negative integer, zero, or a positive integer as
// * the first argument is less than, equal to, or greater than the second.
// *
// * @param o1
// * @param o2
// * @return
// */
// @Override
// public int compare(Job o1, Job o2) {
// // ordering of priority is 1... 2... 3.... N...., where 1 is higher
// if(o1.getCategory().getPriority() > o2.getCategory().getPriority()) {
// return 1;
// } else if(o1.getCategory().getPriority() < o2.getCategory().getPriority()) {
// return -1;
// } else {
// return 0;
// }
// }
// }
//
// Path: src/main/java/yourwebproject2/service/JobService.java
// public interface JobService extends BaseService<Job, Long> {
// /**
// *
// * @param count
// * @return
// */
// public List<Job> fetchNewJobsToBeScheduledForExecutionPerPriority(int count);
//
// /**
// *
// * @param count
// * @return
// */
// public List<Job> fetchFailedJobsToBeScheduledForExecutionPerPriority(int count);
//
// /**
// *
// * @param count
// * @return
// */
// public List<Job> fetchNewJobsToBeScheduledForExecutionPerSubmissionTimePriority(int count);
//
// /**
// *
// * @param count
// * @return
// */
// public List<Job> fetchFailedJobsToBeScheduledForExecutionPerSubmissionTimePriority(int count);
// }
| import yourwebproject2.model.entity.Job;
import yourwebproject2.model.entity.helper.CategoryPriorityComparator;
import yourwebproject2.service.JobService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import java.util.*;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future; | package yourwebproject2.core;
/**
* Created by Y.Kamesh on 8/5/2015.
*/
public class RetryJobSchedulingWorker extends AbstractJobSchedulingWorker {
private static Logger LOG = LoggerFactory.getLogger(RetryJobSchedulingWorker.class);
@Autowired
private JobService jobService;
private ExecutorService executorService = Executors.newFixedThreadPool(50);
/**
* Runs every fifteen minutes.
*/
@Scheduled(initialDelay = 5000L, fixedRate = 15 * 60 * 1000L)
public void scheduleRetryJobsForExecution() {
LOG.info("Fetching failed jobs as per category and submit time priority...");
List<Job> retryableJobs = jobService.fetchFailedJobsToBeScheduledForExecutionPerSubmissionTimePriority(10);
LOG.info("Fetched Jobs Count: "+retryableJobs.size()); | // Path: src/main/java/yourwebproject2/model/entity/Job.java
// @Entity
// @Table(indexes = { @Index(name="name_idx", columnList = "name", unique = true),
// @Index(name="status_idx", columnList = "status"),
// @Index(name="category_idx", columnList = "category")})
// public class Job extends JPAEntity<Long> {
// public enum Status {
// NEW, EXECUTING, PRIORITIZED, FAILED, RETRYING, SUCCESSFUL
// }
//
// private String name;
// private String metadataJson;
// private String callbackUrl;
// private Date submitTime;
// private Status status;
// private Date scheduledTime;
// private Date completionTime;
// private Integer retryCount;
// private Category category;
//
// @NotNull @NotBlank
// @Column
// public String getName() {
// return name;
// }
//
// public void setName(String name) {
// this.name = name;
// }
//
// @Column
// public String getCallbackUrl() {
// return callbackUrl;
// }
//
// public void setCallbackUrl(String callbackUrl) {
// this.callbackUrl = callbackUrl;
// }
//
// @Column
// public String getMetadataJson() {
// return metadataJson;
// }
//
// public void setMetadataJson(String metadataJson) {
// this.metadataJson = metadataJson;
// }
//
// @NotNull
// @Column
// public Date getSubmitTime() {
// return submitTime;
// }
//
// public void setSubmitTime(Date submitTime) {
// this.submitTime = submitTime;
// }
//
// @OneToOne(fetch = FetchType.EAGER)
// public Category getCategory() {
// return category;
// }
//
// public void setCategory(Category category) {
// this.category = category;
// }
//
// @NotNull
// @Column
// public Status getStatus() {
// return status;
// }
//
// public void setStatus(Status status) {
// this.status = status;
// }
//
// @Column
// public Date getScheduledTime() {
// return scheduledTime;
// }
//
// public void setScheduledTime(Date scheduledTime) {
// this.scheduledTime = scheduledTime;
// }
//
// @Column
// public Date getCompletionTime() {
// return completionTime;
// }
//
// public void setCompletionTime(Date completionTime) {
// this.completionTime = completionTime;
// }
//
// @Column
// public Integer getRetryCount() {
// return retryCount;
// }
//
// public void setRetryCount(Integer retryCount) {
// this.retryCount = retryCount;
// }
//
// @Override
// public String toString() {
// return "Job{" +
// "name='" + name + '\'' +
// ", metadataJson='" + metadataJson + '\'' +
// ", callbackUrl='" + callbackUrl + '\'' +
// ", submitTime=" + submitTime +
// ", status=" + status +
// ", scheduledTime=" + scheduledTime +
// ", completionTime=" + completionTime +
// ", retryCount=" + retryCount +
// ", category=" + category +
// '}';
// }
// }
//
// Path: src/main/java/yourwebproject2/model/entity/helper/CategoryPriorityComparator.java
// public class CategoryPriorityComparator implements Comparator<Job> {
//
// /**
// * Compares its two arguments for order. Returns a negative integer, zero, or a positive integer as
// * the first argument is less than, equal to, or greater than the second.
// *
// * @param o1
// * @param o2
// * @return
// */
// @Override
// public int compare(Job o1, Job o2) {
// // ordering of priority is 1... 2... 3.... N...., where 1 is higher
// if(o1.getCategory().getPriority() > o2.getCategory().getPriority()) {
// return 1;
// } else if(o1.getCategory().getPriority() < o2.getCategory().getPriority()) {
// return -1;
// } else {
// return 0;
// }
// }
// }
//
// Path: src/main/java/yourwebproject2/service/JobService.java
// public interface JobService extends BaseService<Job, Long> {
// /**
// *
// * @param count
// * @return
// */
// public List<Job> fetchNewJobsToBeScheduledForExecutionPerPriority(int count);
//
// /**
// *
// * @param count
// * @return
// */
// public List<Job> fetchFailedJobsToBeScheduledForExecutionPerPriority(int count);
//
// /**
// *
// * @param count
// * @return
// */
// public List<Job> fetchNewJobsToBeScheduledForExecutionPerSubmissionTimePriority(int count);
//
// /**
// *
// * @param count
// * @return
// */
// public List<Job> fetchFailedJobsToBeScheduledForExecutionPerSubmissionTimePriority(int count);
// }
// Path: src/main/java/yourwebproject2/core/RetryJobSchedulingWorker.java
import yourwebproject2.model.entity.Job;
import yourwebproject2.model.entity.helper.CategoryPriorityComparator;
import yourwebproject2.service.JobService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import java.util.*;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
package yourwebproject2.core;
/**
* Created by Y.Kamesh on 8/5/2015.
*/
public class RetryJobSchedulingWorker extends AbstractJobSchedulingWorker {
private static Logger LOG = LoggerFactory.getLogger(RetryJobSchedulingWorker.class);
@Autowired
private JobService jobService;
private ExecutorService executorService = Executors.newFixedThreadPool(50);
/**
* Runs every fifteen minutes.
*/
@Scheduled(initialDelay = 5000L, fixedRate = 15 * 60 * 1000L)
public void scheduleRetryJobsForExecution() {
LOG.info("Fetching failed jobs as per category and submit time priority...");
List<Job> retryableJobs = jobService.fetchFailedJobsToBeScheduledForExecutionPerSubmissionTimePriority(10);
LOG.info("Fetched Jobs Count: "+retryableJobs.size()); | Collections.sort(retryableJobs, new CategoryPriorityComparator()); |
ykameshrao/spring-mvc-angular-js-hibernate-bootstrap-java-single-page-jwt-auth-rest-api-webapp-framework | src/main/java/yourwebproject2/framework/controller/BaseController.java | // Path: src/main/java/yourwebproject2/model/dto/UserDTO.java
// public class UserDTO {
// String email;
// String password;
// String displayName;
// String encryptedPassword;
// String iv;
// String salt;
// int keySize;
// int iterations;
//
// public String getEmail() {
// return email;
// }
//
// public void setEmail(String email) {
// this.email = email;
// }
//
// public String getPassword() {
// return password;
// }
//
// public void setPassword(String password) {
// this.password = password;
// }
//
// public String getDisplayName() {
// return displayName;
// }
//
// public void setDisplayName(String displayName) {
// this.displayName = displayName;
// }
//
// public String getEncryptedPassword() {
// return encryptedPassword;
// }
//
// public void setEncryptedPassword(String encryptedPassword) {
// this.encryptedPassword = encryptedPassword;
// }
//
// public String getIv() {
// return iv;
// }
//
// public void setIv(String iv) {
// this.iv = iv;
// }
//
// public String getSalt() {
// return salt;
// }
//
// public void setSalt(String salt) {
// this.salt = salt;
// }
//
// public int getKeySize() {
// return keySize;
// }
//
// public void setKeySize(int keySize) {
// this.keySize = keySize;
// }
//
// public int getIterations() {
// return iterations;
// }
//
// public void setIterations(int iterations) {
// this.iterations = iterations;
// }
// }
| import yourwebproject2.model.dto.UserDTO;
import org.apache.commons.lang.Validate;
import org.json.JSONObject;
import org.springframework.security.crypto.codec.Base64;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.util.Scanner; | package yourwebproject2.framework.controller;
/**
* All controllers in spring should extend this controller so as to have
* centralize control for doing any sort of common functionality.
* e.g. extracting data from post request body
*
* @author : Y Kamesh Rao
*/
public abstract class BaseController {
protected static final String JSON_API_CONTENT_HEADER = "Content-type=application/json";
public String extractPostRequestBody(HttpServletRequest request) throws IOException {
if ("POST".equalsIgnoreCase(request.getMethod())) {
Scanner s = new Scanner(request.getInputStream(), "UTF-8").useDelimiter("\\A");
return s.hasNext() ? s.next() : "";
}
return "";
}
public JSONObject parseJSON(String object) {
return new JSONObject(object);
}
| // Path: src/main/java/yourwebproject2/model/dto/UserDTO.java
// public class UserDTO {
// String email;
// String password;
// String displayName;
// String encryptedPassword;
// String iv;
// String salt;
// int keySize;
// int iterations;
//
// public String getEmail() {
// return email;
// }
//
// public void setEmail(String email) {
// this.email = email;
// }
//
// public String getPassword() {
// return password;
// }
//
// public void setPassword(String password) {
// this.password = password;
// }
//
// public String getDisplayName() {
// return displayName;
// }
//
// public void setDisplayName(String displayName) {
// this.displayName = displayName;
// }
//
// public String getEncryptedPassword() {
// return encryptedPassword;
// }
//
// public void setEncryptedPassword(String encryptedPassword) {
// this.encryptedPassword = encryptedPassword;
// }
//
// public String getIv() {
// return iv;
// }
//
// public void setIv(String iv) {
// this.iv = iv;
// }
//
// public String getSalt() {
// return salt;
// }
//
// public void setSalt(String salt) {
// this.salt = salt;
// }
//
// public int getKeySize() {
// return keySize;
// }
//
// public void setKeySize(int keySize) {
// this.keySize = keySize;
// }
//
// public int getIterations() {
// return iterations;
// }
//
// public void setIterations(int iterations) {
// this.iterations = iterations;
// }
// }
// Path: src/main/java/yourwebproject2/framework/controller/BaseController.java
import yourwebproject2.model.dto.UserDTO;
import org.apache.commons.lang.Validate;
import org.json.JSONObject;
import org.springframework.security.crypto.codec.Base64;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.util.Scanner;
package yourwebproject2.framework.controller;
/**
* All controllers in spring should extend this controller so as to have
* centralize control for doing any sort of common functionality.
* e.g. extracting data from post request body
*
* @author : Y Kamesh Rao
*/
public abstract class BaseController {
protected static final String JSON_API_CONTENT_HEADER = "Content-type=application/json";
public String extractPostRequestBody(HttpServletRequest request) throws IOException {
if ("POST".equalsIgnoreCase(request.getMethod())) {
Scanner s = new Scanner(request.getInputStream(), "UTF-8").useDelimiter("\\A");
return s.hasNext() ? s.next() : "";
}
return "";
}
public JSONObject parseJSON(String object) {
return new JSONObject(object);
}
| public void decorateUserDTOWithCredsFromAuthHeader(String authHeader, UserDTO userDTO) { |
ykameshrao/spring-mvc-angular-js-hibernate-bootstrap-java-single-page-jwt-auth-rest-api-webapp-framework | src/main/java/yourwebproject2/model/entity/Category.java | // Path: src/main/java/yourwebproject2/framework/data/JPAEntity.java
// @MappedSuperclass
// public abstract class JPAEntity<T extends Serializable> implements Entity {
// protected T id;
// protected Date createdAt;
// protected Date updatedAt;
//
//
// public JPAEntity() {
// createdAt = new Date();
// updatedAt = new Date();
// }
//
//
// /**
// * To make XStream deserialization assign values to
// * base class fields of createdAt and updatedAt
// *
// * @return
// */
// public Object readResolve() {
// if (this.createdAt == null) {
// this.createdAt = new Date();
// this.updatedAt = createdAt;
// }
//
// return this;
// }
//
//
// @XmlElement(type = Object.class) @Id @GeneratedValue
// public T getId() {
// return id;
// }
//
//
// public void setId(T id) {
// this.id = id;
// }
//
//
// @JsonIgnore @Temporal(TemporalType.DATE) @Column
// public Date getCreatedAt() {
// return createdAt;
// }
//
//
// public void setCreatedAt(Date createdAt) {
// this.createdAt = createdAt;
// }
//
//
// @JsonIgnore @Temporal(TemporalType.TIMESTAMP) @Column
// public Date getUpdatedAt() {
// return updatedAt;
// }
//
//
// public void setUpdatedAt(Date updatedAt) {
// this.updatedAt = updatedAt;
// }
// }
| import yourwebproject2.framework.data.JPAEntity;
import org.hibernate.validator.constraints.NotBlank;
import javax.persistence.*;
import javax.validation.constraints.NotNull; | package yourwebproject2.model.entity;
/**
* Category Entity
*
* Created by Y.Kamesh on 8/2/2015.
*/
@Entity
@Table(indexes = { @Index(name="name_idx", columnList = "name", unique = true),
@Index(name="priority_idx", columnList = "priority"),
@Index(name="parentCategory_idx", columnList = "parent_category")}) | // Path: src/main/java/yourwebproject2/framework/data/JPAEntity.java
// @MappedSuperclass
// public abstract class JPAEntity<T extends Serializable> implements Entity {
// protected T id;
// protected Date createdAt;
// protected Date updatedAt;
//
//
// public JPAEntity() {
// createdAt = new Date();
// updatedAt = new Date();
// }
//
//
// /**
// * To make XStream deserialization assign values to
// * base class fields of createdAt and updatedAt
// *
// * @return
// */
// public Object readResolve() {
// if (this.createdAt == null) {
// this.createdAt = new Date();
// this.updatedAt = createdAt;
// }
//
// return this;
// }
//
//
// @XmlElement(type = Object.class) @Id @GeneratedValue
// public T getId() {
// return id;
// }
//
//
// public void setId(T id) {
// this.id = id;
// }
//
//
// @JsonIgnore @Temporal(TemporalType.DATE) @Column
// public Date getCreatedAt() {
// return createdAt;
// }
//
//
// public void setCreatedAt(Date createdAt) {
// this.createdAt = createdAt;
// }
//
//
// @JsonIgnore @Temporal(TemporalType.TIMESTAMP) @Column
// public Date getUpdatedAt() {
// return updatedAt;
// }
//
//
// public void setUpdatedAt(Date updatedAt) {
// this.updatedAt = updatedAt;
// }
// }
// Path: src/main/java/yourwebproject2/model/entity/Category.java
import yourwebproject2.framework.data.JPAEntity;
import org.hibernate.validator.constraints.NotBlank;
import javax.persistence.*;
import javax.validation.constraints.NotNull;
package yourwebproject2.model.entity;
/**
* Category Entity
*
* Created by Y.Kamesh on 8/2/2015.
*/
@Entity
@Table(indexes = { @Index(name="name_idx", columnList = "name", unique = true),
@Index(name="priority_idx", columnList = "priority"),
@Index(name="parentCategory_idx", columnList = "parent_category")}) | public class Category extends JPAEntity<Long> { |
ykameshrao/spring-mvc-angular-js-hibernate-bootstrap-java-single-page-jwt-auth-rest-api-webapp-framework | src/main/java/yourwebproject2/core/tool/CategoryTool.java | // Path: src/main/java/yourwebproject2/model/entity/Category.java
// @Entity
// @Table(indexes = { @Index(name="name_idx", columnList = "name", unique = true),
// @Index(name="priority_idx", columnList = "priority"),
// @Index(name="parentCategory_idx", columnList = "parent_category")})
// public class Category extends JPAEntity<Long> {
// private String name;
// private Integer priority;
// private Category parentCategory;
//
// @NotNull @NotBlank
// @Column
// public String getName() {
// return name;
// }
//
// public void setName(String name) {
// this.name = name;
// }
//
// @NotNull
// @Column
// public Integer getPriority() {
// return priority;
// }
//
// public void setPriority(Integer priority) {
// this.priority = priority;
// }
//
// @ManyToOne(fetch = FetchType.EAGER)
// public Category getParentCategory() {
// return parentCategory;
// }
//
// public void setParentCategory(Category parentCategory) {
// this.parentCategory = parentCategory;
// }
//
// @Override
// public String toString() {
// return "Category{" +
// "name='" + name + '\'' +
// ", priority=" + priority +
// ", parentCategory=" + parentCategory +
// '}';
// }
// }
//
// Path: src/main/java/yourwebproject2/service/CategoryService.java
// public interface CategoryService extends BaseService<Category, Long> {
// /**
// * Validates whether the given category already
// * exists in the system.
// *
// * @param categoryName
// *
// * @return
// */
// public boolean isCategoryPresent(String categoryName);
//
// /**
// * Validates whether the given category priority already
// * exists in the system.
// *
// * @param priorityId
// *
// * @return
// */
// public boolean isPriorityPresent(Integer priorityId);
//
// /**
// * Find category by name
// *
// * @param categoryName
// * @return
// */
// public Category findByCategoryName(String categoryName) throws NotFoundException;
//
// /**
// * Find sub categories by parent category
// *
// * @param parentCategory
// * @return
// */
// public List<Category> findSubCategories(Category parentCategory) throws NotFoundException;
// }
| import yourwebproject2.model.entity.Category;
import yourwebproject2.service.CategoryService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import java.util.HashMap; | break;
case "parent":
params.put("parent", p[1]);
break;
}
}
Integer priority = null;
if(params.containsKey("name") && (params.containsKey("priority") || params.containsKey("parent"))) {
if(params.containsKey("priority")) {
try {
priority = Integer.parseInt(params.get("priority"));
} catch (NumberFormatException nfe) {
System.out.println("Priority not a number");
System.exit(1);
}
}
} else {
printUsage();
}
LOG.info("Params: "+params);
System.out.println("Params: "+params);
ApplicationContext ctx = new ClassPathXmlApplicationContext(new String[]{"classpath:/config/spring/appContext-jdbc.xml",
"classpath:/config/spring/appContext-repository.xml",
"classpath:/config/spring/appContext-service.xml",
"classpath:/config/spring/appContext-interceptor.xml"}, true);
LOG.info("Loaded the context: " + ctx.getBeanDefinitionNames());
| // Path: src/main/java/yourwebproject2/model/entity/Category.java
// @Entity
// @Table(indexes = { @Index(name="name_idx", columnList = "name", unique = true),
// @Index(name="priority_idx", columnList = "priority"),
// @Index(name="parentCategory_idx", columnList = "parent_category")})
// public class Category extends JPAEntity<Long> {
// private String name;
// private Integer priority;
// private Category parentCategory;
//
// @NotNull @NotBlank
// @Column
// public String getName() {
// return name;
// }
//
// public void setName(String name) {
// this.name = name;
// }
//
// @NotNull
// @Column
// public Integer getPriority() {
// return priority;
// }
//
// public void setPriority(Integer priority) {
// this.priority = priority;
// }
//
// @ManyToOne(fetch = FetchType.EAGER)
// public Category getParentCategory() {
// return parentCategory;
// }
//
// public void setParentCategory(Category parentCategory) {
// this.parentCategory = parentCategory;
// }
//
// @Override
// public String toString() {
// return "Category{" +
// "name='" + name + '\'' +
// ", priority=" + priority +
// ", parentCategory=" + parentCategory +
// '}';
// }
// }
//
// Path: src/main/java/yourwebproject2/service/CategoryService.java
// public interface CategoryService extends BaseService<Category, Long> {
// /**
// * Validates whether the given category already
// * exists in the system.
// *
// * @param categoryName
// *
// * @return
// */
// public boolean isCategoryPresent(String categoryName);
//
// /**
// * Validates whether the given category priority already
// * exists in the system.
// *
// * @param priorityId
// *
// * @return
// */
// public boolean isPriorityPresent(Integer priorityId);
//
// /**
// * Find category by name
// *
// * @param categoryName
// * @return
// */
// public Category findByCategoryName(String categoryName) throws NotFoundException;
//
// /**
// * Find sub categories by parent category
// *
// * @param parentCategory
// * @return
// */
// public List<Category> findSubCategories(Category parentCategory) throws NotFoundException;
// }
// Path: src/main/java/yourwebproject2/core/tool/CategoryTool.java
import yourwebproject2.model.entity.Category;
import yourwebproject2.service.CategoryService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import java.util.HashMap;
break;
case "parent":
params.put("parent", p[1]);
break;
}
}
Integer priority = null;
if(params.containsKey("name") && (params.containsKey("priority") || params.containsKey("parent"))) {
if(params.containsKey("priority")) {
try {
priority = Integer.parseInt(params.get("priority"));
} catch (NumberFormatException nfe) {
System.out.println("Priority not a number");
System.exit(1);
}
}
} else {
printUsage();
}
LOG.info("Params: "+params);
System.out.println("Params: "+params);
ApplicationContext ctx = new ClassPathXmlApplicationContext(new String[]{"classpath:/config/spring/appContext-jdbc.xml",
"classpath:/config/spring/appContext-repository.xml",
"classpath:/config/spring/appContext-service.xml",
"classpath:/config/spring/appContext-interceptor.xml"}, true);
LOG.info("Loaded the context: " + ctx.getBeanDefinitionNames());
| CategoryService categoryService = (CategoryService) ctx.getBean("categoryServiceImpl"); |
ykameshrao/spring-mvc-angular-js-hibernate-bootstrap-java-single-page-jwt-auth-rest-api-webapp-framework | src/main/java/yourwebproject2/core/tool/CategoryTool.java | // Path: src/main/java/yourwebproject2/model/entity/Category.java
// @Entity
// @Table(indexes = { @Index(name="name_idx", columnList = "name", unique = true),
// @Index(name="priority_idx", columnList = "priority"),
// @Index(name="parentCategory_idx", columnList = "parent_category")})
// public class Category extends JPAEntity<Long> {
// private String name;
// private Integer priority;
// private Category parentCategory;
//
// @NotNull @NotBlank
// @Column
// public String getName() {
// return name;
// }
//
// public void setName(String name) {
// this.name = name;
// }
//
// @NotNull
// @Column
// public Integer getPriority() {
// return priority;
// }
//
// public void setPriority(Integer priority) {
// this.priority = priority;
// }
//
// @ManyToOne(fetch = FetchType.EAGER)
// public Category getParentCategory() {
// return parentCategory;
// }
//
// public void setParentCategory(Category parentCategory) {
// this.parentCategory = parentCategory;
// }
//
// @Override
// public String toString() {
// return "Category{" +
// "name='" + name + '\'' +
// ", priority=" + priority +
// ", parentCategory=" + parentCategory +
// '}';
// }
// }
//
// Path: src/main/java/yourwebproject2/service/CategoryService.java
// public interface CategoryService extends BaseService<Category, Long> {
// /**
// * Validates whether the given category already
// * exists in the system.
// *
// * @param categoryName
// *
// * @return
// */
// public boolean isCategoryPresent(String categoryName);
//
// /**
// * Validates whether the given category priority already
// * exists in the system.
// *
// * @param priorityId
// *
// * @return
// */
// public boolean isPriorityPresent(Integer priorityId);
//
// /**
// * Find category by name
// *
// * @param categoryName
// * @return
// */
// public Category findByCategoryName(String categoryName) throws NotFoundException;
//
// /**
// * Find sub categories by parent category
// *
// * @param parentCategory
// * @return
// */
// public List<Category> findSubCategories(Category parentCategory) throws NotFoundException;
// }
| import yourwebproject2.model.entity.Category;
import yourwebproject2.service.CategoryService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import java.util.HashMap; | Integer priority = null;
if(params.containsKey("name") && (params.containsKey("priority") || params.containsKey("parent"))) {
if(params.containsKey("priority")) {
try {
priority = Integer.parseInt(params.get("priority"));
} catch (NumberFormatException nfe) {
System.out.println("Priority not a number");
System.exit(1);
}
}
} else {
printUsage();
}
LOG.info("Params: "+params);
System.out.println("Params: "+params);
ApplicationContext ctx = new ClassPathXmlApplicationContext(new String[]{"classpath:/config/spring/appContext-jdbc.xml",
"classpath:/config/spring/appContext-repository.xml",
"classpath:/config/spring/appContext-service.xml",
"classpath:/config/spring/appContext-interceptor.xml"}, true);
LOG.info("Loaded the context: " + ctx.getBeanDefinitionNames());
CategoryService categoryService = (CategoryService) ctx.getBean("categoryServiceImpl");
if(categoryService.isCategoryPresent(params.get("name"))) {
System.out.println("Category taken");
System.exit(1);
}
| // Path: src/main/java/yourwebproject2/model/entity/Category.java
// @Entity
// @Table(indexes = { @Index(name="name_idx", columnList = "name", unique = true),
// @Index(name="priority_idx", columnList = "priority"),
// @Index(name="parentCategory_idx", columnList = "parent_category")})
// public class Category extends JPAEntity<Long> {
// private String name;
// private Integer priority;
// private Category parentCategory;
//
// @NotNull @NotBlank
// @Column
// public String getName() {
// return name;
// }
//
// public void setName(String name) {
// this.name = name;
// }
//
// @NotNull
// @Column
// public Integer getPriority() {
// return priority;
// }
//
// public void setPriority(Integer priority) {
// this.priority = priority;
// }
//
// @ManyToOne(fetch = FetchType.EAGER)
// public Category getParentCategory() {
// return parentCategory;
// }
//
// public void setParentCategory(Category parentCategory) {
// this.parentCategory = parentCategory;
// }
//
// @Override
// public String toString() {
// return "Category{" +
// "name='" + name + '\'' +
// ", priority=" + priority +
// ", parentCategory=" + parentCategory +
// '}';
// }
// }
//
// Path: src/main/java/yourwebproject2/service/CategoryService.java
// public interface CategoryService extends BaseService<Category, Long> {
// /**
// * Validates whether the given category already
// * exists in the system.
// *
// * @param categoryName
// *
// * @return
// */
// public boolean isCategoryPresent(String categoryName);
//
// /**
// * Validates whether the given category priority already
// * exists in the system.
// *
// * @param priorityId
// *
// * @return
// */
// public boolean isPriorityPresent(Integer priorityId);
//
// /**
// * Find category by name
// *
// * @param categoryName
// * @return
// */
// public Category findByCategoryName(String categoryName) throws NotFoundException;
//
// /**
// * Find sub categories by parent category
// *
// * @param parentCategory
// * @return
// */
// public List<Category> findSubCategories(Category parentCategory) throws NotFoundException;
// }
// Path: src/main/java/yourwebproject2/core/tool/CategoryTool.java
import yourwebproject2.model.entity.Category;
import yourwebproject2.service.CategoryService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import java.util.HashMap;
Integer priority = null;
if(params.containsKey("name") && (params.containsKey("priority") || params.containsKey("parent"))) {
if(params.containsKey("priority")) {
try {
priority = Integer.parseInt(params.get("priority"));
} catch (NumberFormatException nfe) {
System.out.println("Priority not a number");
System.exit(1);
}
}
} else {
printUsage();
}
LOG.info("Params: "+params);
System.out.println("Params: "+params);
ApplicationContext ctx = new ClassPathXmlApplicationContext(new String[]{"classpath:/config/spring/appContext-jdbc.xml",
"classpath:/config/spring/appContext-repository.xml",
"classpath:/config/spring/appContext-service.xml",
"classpath:/config/spring/appContext-interceptor.xml"}, true);
LOG.info("Loaded the context: " + ctx.getBeanDefinitionNames());
CategoryService categoryService = (CategoryService) ctx.getBean("categoryServiceImpl");
if(categoryService.isCategoryPresent(params.get("name"))) {
System.out.println("Category taken");
System.exit(1);
}
| Category parentCategory = null; |
ykameshrao/spring-mvc-angular-js-hibernate-bootstrap-java-single-page-jwt-auth-rest-api-webapp-framework | src/main/java/yourwebproject2/core/NewJobSchedulingWorker.java | // Path: src/main/java/yourwebproject2/model/entity/Job.java
// @Entity
// @Table(indexes = { @Index(name="name_idx", columnList = "name", unique = true),
// @Index(name="status_idx", columnList = "status"),
// @Index(name="category_idx", columnList = "category")})
// public class Job extends JPAEntity<Long> {
// public enum Status {
// NEW, EXECUTING, PRIORITIZED, FAILED, RETRYING, SUCCESSFUL
// }
//
// private String name;
// private String metadataJson;
// private String callbackUrl;
// private Date submitTime;
// private Status status;
// private Date scheduledTime;
// private Date completionTime;
// private Integer retryCount;
// private Category category;
//
// @NotNull @NotBlank
// @Column
// public String getName() {
// return name;
// }
//
// public void setName(String name) {
// this.name = name;
// }
//
// @Column
// public String getCallbackUrl() {
// return callbackUrl;
// }
//
// public void setCallbackUrl(String callbackUrl) {
// this.callbackUrl = callbackUrl;
// }
//
// @Column
// public String getMetadataJson() {
// return metadataJson;
// }
//
// public void setMetadataJson(String metadataJson) {
// this.metadataJson = metadataJson;
// }
//
// @NotNull
// @Column
// public Date getSubmitTime() {
// return submitTime;
// }
//
// public void setSubmitTime(Date submitTime) {
// this.submitTime = submitTime;
// }
//
// @OneToOne(fetch = FetchType.EAGER)
// public Category getCategory() {
// return category;
// }
//
// public void setCategory(Category category) {
// this.category = category;
// }
//
// @NotNull
// @Column
// public Status getStatus() {
// return status;
// }
//
// public void setStatus(Status status) {
// this.status = status;
// }
//
// @Column
// public Date getScheduledTime() {
// return scheduledTime;
// }
//
// public void setScheduledTime(Date scheduledTime) {
// this.scheduledTime = scheduledTime;
// }
//
// @Column
// public Date getCompletionTime() {
// return completionTime;
// }
//
// public void setCompletionTime(Date completionTime) {
// this.completionTime = completionTime;
// }
//
// @Column
// public Integer getRetryCount() {
// return retryCount;
// }
//
// public void setRetryCount(Integer retryCount) {
// this.retryCount = retryCount;
// }
//
// @Override
// public String toString() {
// return "Job{" +
// "name='" + name + '\'' +
// ", metadataJson='" + metadataJson + '\'' +
// ", callbackUrl='" + callbackUrl + '\'' +
// ", submitTime=" + submitTime +
// ", status=" + status +
// ", scheduledTime=" + scheduledTime +
// ", completionTime=" + completionTime +
// ", retryCount=" + retryCount +
// ", category=" + category +
// '}';
// }
// }
//
// Path: src/main/java/yourwebproject2/model/entity/helper/CategoryPriorityComparator.java
// public class CategoryPriorityComparator implements Comparator<Job> {
//
// /**
// * Compares its two arguments for order. Returns a negative integer, zero, or a positive integer as
// * the first argument is less than, equal to, or greater than the second.
// *
// * @param o1
// * @param o2
// * @return
// */
// @Override
// public int compare(Job o1, Job o2) {
// // ordering of priority is 1... 2... 3.... N...., where 1 is higher
// if(o1.getCategory().getPriority() > o2.getCategory().getPriority()) {
// return 1;
// } else if(o1.getCategory().getPriority() < o2.getCategory().getPriority()) {
// return -1;
// } else {
// return 0;
// }
// }
// }
//
// Path: src/main/java/yourwebproject2/service/JobService.java
// public interface JobService extends BaseService<Job, Long> {
// /**
// *
// * @param count
// * @return
// */
// public List<Job> fetchNewJobsToBeScheduledForExecutionPerPriority(int count);
//
// /**
// *
// * @param count
// * @return
// */
// public List<Job> fetchFailedJobsToBeScheduledForExecutionPerPriority(int count);
//
// /**
// *
// * @param count
// * @return
// */
// public List<Job> fetchNewJobsToBeScheduledForExecutionPerSubmissionTimePriority(int count);
//
// /**
// *
// * @param count
// * @return
// */
// public List<Job> fetchFailedJobsToBeScheduledForExecutionPerSubmissionTimePriority(int count);
// }
| import yourwebproject2.model.entity.Job;
import yourwebproject2.model.entity.helper.CategoryPriorityComparator;
import yourwebproject2.service.JobService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import java.util.*;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future; | package yourwebproject2.core;
/**
* Created by Y.Kamesh on 8/5/2015.
*/
public class NewJobSchedulingWorker extends AbstractJobSchedulingWorker {
private static Logger LOG = LoggerFactory.getLogger(NewJobSchedulingWorker.class);
@Autowired | // Path: src/main/java/yourwebproject2/model/entity/Job.java
// @Entity
// @Table(indexes = { @Index(name="name_idx", columnList = "name", unique = true),
// @Index(name="status_idx", columnList = "status"),
// @Index(name="category_idx", columnList = "category")})
// public class Job extends JPAEntity<Long> {
// public enum Status {
// NEW, EXECUTING, PRIORITIZED, FAILED, RETRYING, SUCCESSFUL
// }
//
// private String name;
// private String metadataJson;
// private String callbackUrl;
// private Date submitTime;
// private Status status;
// private Date scheduledTime;
// private Date completionTime;
// private Integer retryCount;
// private Category category;
//
// @NotNull @NotBlank
// @Column
// public String getName() {
// return name;
// }
//
// public void setName(String name) {
// this.name = name;
// }
//
// @Column
// public String getCallbackUrl() {
// return callbackUrl;
// }
//
// public void setCallbackUrl(String callbackUrl) {
// this.callbackUrl = callbackUrl;
// }
//
// @Column
// public String getMetadataJson() {
// return metadataJson;
// }
//
// public void setMetadataJson(String metadataJson) {
// this.metadataJson = metadataJson;
// }
//
// @NotNull
// @Column
// public Date getSubmitTime() {
// return submitTime;
// }
//
// public void setSubmitTime(Date submitTime) {
// this.submitTime = submitTime;
// }
//
// @OneToOne(fetch = FetchType.EAGER)
// public Category getCategory() {
// return category;
// }
//
// public void setCategory(Category category) {
// this.category = category;
// }
//
// @NotNull
// @Column
// public Status getStatus() {
// return status;
// }
//
// public void setStatus(Status status) {
// this.status = status;
// }
//
// @Column
// public Date getScheduledTime() {
// return scheduledTime;
// }
//
// public void setScheduledTime(Date scheduledTime) {
// this.scheduledTime = scheduledTime;
// }
//
// @Column
// public Date getCompletionTime() {
// return completionTime;
// }
//
// public void setCompletionTime(Date completionTime) {
// this.completionTime = completionTime;
// }
//
// @Column
// public Integer getRetryCount() {
// return retryCount;
// }
//
// public void setRetryCount(Integer retryCount) {
// this.retryCount = retryCount;
// }
//
// @Override
// public String toString() {
// return "Job{" +
// "name='" + name + '\'' +
// ", metadataJson='" + metadataJson + '\'' +
// ", callbackUrl='" + callbackUrl + '\'' +
// ", submitTime=" + submitTime +
// ", status=" + status +
// ", scheduledTime=" + scheduledTime +
// ", completionTime=" + completionTime +
// ", retryCount=" + retryCount +
// ", category=" + category +
// '}';
// }
// }
//
// Path: src/main/java/yourwebproject2/model/entity/helper/CategoryPriorityComparator.java
// public class CategoryPriorityComparator implements Comparator<Job> {
//
// /**
// * Compares its two arguments for order. Returns a negative integer, zero, or a positive integer as
// * the first argument is less than, equal to, or greater than the second.
// *
// * @param o1
// * @param o2
// * @return
// */
// @Override
// public int compare(Job o1, Job o2) {
// // ordering of priority is 1... 2... 3.... N...., where 1 is higher
// if(o1.getCategory().getPriority() > o2.getCategory().getPriority()) {
// return 1;
// } else if(o1.getCategory().getPriority() < o2.getCategory().getPriority()) {
// return -1;
// } else {
// return 0;
// }
// }
// }
//
// Path: src/main/java/yourwebproject2/service/JobService.java
// public interface JobService extends BaseService<Job, Long> {
// /**
// *
// * @param count
// * @return
// */
// public List<Job> fetchNewJobsToBeScheduledForExecutionPerPriority(int count);
//
// /**
// *
// * @param count
// * @return
// */
// public List<Job> fetchFailedJobsToBeScheduledForExecutionPerPriority(int count);
//
// /**
// *
// * @param count
// * @return
// */
// public List<Job> fetchNewJobsToBeScheduledForExecutionPerSubmissionTimePriority(int count);
//
// /**
// *
// * @param count
// * @return
// */
// public List<Job> fetchFailedJobsToBeScheduledForExecutionPerSubmissionTimePriority(int count);
// }
// Path: src/main/java/yourwebproject2/core/NewJobSchedulingWorker.java
import yourwebproject2.model.entity.Job;
import yourwebproject2.model.entity.helper.CategoryPriorityComparator;
import yourwebproject2.service.JobService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import java.util.*;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
package yourwebproject2.core;
/**
* Created by Y.Kamesh on 8/5/2015.
*/
public class NewJobSchedulingWorker extends AbstractJobSchedulingWorker {
private static Logger LOG = LoggerFactory.getLogger(NewJobSchedulingWorker.class);
@Autowired | private JobService jobService; |
ykameshrao/spring-mvc-angular-js-hibernate-bootstrap-java-single-page-jwt-auth-rest-api-webapp-framework | src/main/java/yourwebproject2/core/NewJobSchedulingWorker.java | // Path: src/main/java/yourwebproject2/model/entity/Job.java
// @Entity
// @Table(indexes = { @Index(name="name_idx", columnList = "name", unique = true),
// @Index(name="status_idx", columnList = "status"),
// @Index(name="category_idx", columnList = "category")})
// public class Job extends JPAEntity<Long> {
// public enum Status {
// NEW, EXECUTING, PRIORITIZED, FAILED, RETRYING, SUCCESSFUL
// }
//
// private String name;
// private String metadataJson;
// private String callbackUrl;
// private Date submitTime;
// private Status status;
// private Date scheduledTime;
// private Date completionTime;
// private Integer retryCount;
// private Category category;
//
// @NotNull @NotBlank
// @Column
// public String getName() {
// return name;
// }
//
// public void setName(String name) {
// this.name = name;
// }
//
// @Column
// public String getCallbackUrl() {
// return callbackUrl;
// }
//
// public void setCallbackUrl(String callbackUrl) {
// this.callbackUrl = callbackUrl;
// }
//
// @Column
// public String getMetadataJson() {
// return metadataJson;
// }
//
// public void setMetadataJson(String metadataJson) {
// this.metadataJson = metadataJson;
// }
//
// @NotNull
// @Column
// public Date getSubmitTime() {
// return submitTime;
// }
//
// public void setSubmitTime(Date submitTime) {
// this.submitTime = submitTime;
// }
//
// @OneToOne(fetch = FetchType.EAGER)
// public Category getCategory() {
// return category;
// }
//
// public void setCategory(Category category) {
// this.category = category;
// }
//
// @NotNull
// @Column
// public Status getStatus() {
// return status;
// }
//
// public void setStatus(Status status) {
// this.status = status;
// }
//
// @Column
// public Date getScheduledTime() {
// return scheduledTime;
// }
//
// public void setScheduledTime(Date scheduledTime) {
// this.scheduledTime = scheduledTime;
// }
//
// @Column
// public Date getCompletionTime() {
// return completionTime;
// }
//
// public void setCompletionTime(Date completionTime) {
// this.completionTime = completionTime;
// }
//
// @Column
// public Integer getRetryCount() {
// return retryCount;
// }
//
// public void setRetryCount(Integer retryCount) {
// this.retryCount = retryCount;
// }
//
// @Override
// public String toString() {
// return "Job{" +
// "name='" + name + '\'' +
// ", metadataJson='" + metadataJson + '\'' +
// ", callbackUrl='" + callbackUrl + '\'' +
// ", submitTime=" + submitTime +
// ", status=" + status +
// ", scheduledTime=" + scheduledTime +
// ", completionTime=" + completionTime +
// ", retryCount=" + retryCount +
// ", category=" + category +
// '}';
// }
// }
//
// Path: src/main/java/yourwebproject2/model/entity/helper/CategoryPriorityComparator.java
// public class CategoryPriorityComparator implements Comparator<Job> {
//
// /**
// * Compares its two arguments for order. Returns a negative integer, zero, or a positive integer as
// * the first argument is less than, equal to, or greater than the second.
// *
// * @param o1
// * @param o2
// * @return
// */
// @Override
// public int compare(Job o1, Job o2) {
// // ordering of priority is 1... 2... 3.... N...., where 1 is higher
// if(o1.getCategory().getPriority() > o2.getCategory().getPriority()) {
// return 1;
// } else if(o1.getCategory().getPriority() < o2.getCategory().getPriority()) {
// return -1;
// } else {
// return 0;
// }
// }
// }
//
// Path: src/main/java/yourwebproject2/service/JobService.java
// public interface JobService extends BaseService<Job, Long> {
// /**
// *
// * @param count
// * @return
// */
// public List<Job> fetchNewJobsToBeScheduledForExecutionPerPriority(int count);
//
// /**
// *
// * @param count
// * @return
// */
// public List<Job> fetchFailedJobsToBeScheduledForExecutionPerPriority(int count);
//
// /**
// *
// * @param count
// * @return
// */
// public List<Job> fetchNewJobsToBeScheduledForExecutionPerSubmissionTimePriority(int count);
//
// /**
// *
// * @param count
// * @return
// */
// public List<Job> fetchFailedJobsToBeScheduledForExecutionPerSubmissionTimePriority(int count);
// }
| import yourwebproject2.model.entity.Job;
import yourwebproject2.model.entity.helper.CategoryPriorityComparator;
import yourwebproject2.service.JobService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import java.util.*;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future; | package yourwebproject2.core;
/**
* Created by Y.Kamesh on 8/5/2015.
*/
public class NewJobSchedulingWorker extends AbstractJobSchedulingWorker {
private static Logger LOG = LoggerFactory.getLogger(NewJobSchedulingWorker.class);
@Autowired
private JobService jobService;
private ExecutorService executorService = Executors.newFixedThreadPool(50);
/**
* Runs every five minutes.
*/
@Scheduled(initialDelay = 5000L, fixedRate = 5 * 60 * 1000L)
public void scheduleNewJobsForExecution() {
LOG.info("Fetching new jobs as per category and submit time priority..."); | // Path: src/main/java/yourwebproject2/model/entity/Job.java
// @Entity
// @Table(indexes = { @Index(name="name_idx", columnList = "name", unique = true),
// @Index(name="status_idx", columnList = "status"),
// @Index(name="category_idx", columnList = "category")})
// public class Job extends JPAEntity<Long> {
// public enum Status {
// NEW, EXECUTING, PRIORITIZED, FAILED, RETRYING, SUCCESSFUL
// }
//
// private String name;
// private String metadataJson;
// private String callbackUrl;
// private Date submitTime;
// private Status status;
// private Date scheduledTime;
// private Date completionTime;
// private Integer retryCount;
// private Category category;
//
// @NotNull @NotBlank
// @Column
// public String getName() {
// return name;
// }
//
// public void setName(String name) {
// this.name = name;
// }
//
// @Column
// public String getCallbackUrl() {
// return callbackUrl;
// }
//
// public void setCallbackUrl(String callbackUrl) {
// this.callbackUrl = callbackUrl;
// }
//
// @Column
// public String getMetadataJson() {
// return metadataJson;
// }
//
// public void setMetadataJson(String metadataJson) {
// this.metadataJson = metadataJson;
// }
//
// @NotNull
// @Column
// public Date getSubmitTime() {
// return submitTime;
// }
//
// public void setSubmitTime(Date submitTime) {
// this.submitTime = submitTime;
// }
//
// @OneToOne(fetch = FetchType.EAGER)
// public Category getCategory() {
// return category;
// }
//
// public void setCategory(Category category) {
// this.category = category;
// }
//
// @NotNull
// @Column
// public Status getStatus() {
// return status;
// }
//
// public void setStatus(Status status) {
// this.status = status;
// }
//
// @Column
// public Date getScheduledTime() {
// return scheduledTime;
// }
//
// public void setScheduledTime(Date scheduledTime) {
// this.scheduledTime = scheduledTime;
// }
//
// @Column
// public Date getCompletionTime() {
// return completionTime;
// }
//
// public void setCompletionTime(Date completionTime) {
// this.completionTime = completionTime;
// }
//
// @Column
// public Integer getRetryCount() {
// return retryCount;
// }
//
// public void setRetryCount(Integer retryCount) {
// this.retryCount = retryCount;
// }
//
// @Override
// public String toString() {
// return "Job{" +
// "name='" + name + '\'' +
// ", metadataJson='" + metadataJson + '\'' +
// ", callbackUrl='" + callbackUrl + '\'' +
// ", submitTime=" + submitTime +
// ", status=" + status +
// ", scheduledTime=" + scheduledTime +
// ", completionTime=" + completionTime +
// ", retryCount=" + retryCount +
// ", category=" + category +
// '}';
// }
// }
//
// Path: src/main/java/yourwebproject2/model/entity/helper/CategoryPriorityComparator.java
// public class CategoryPriorityComparator implements Comparator<Job> {
//
// /**
// * Compares its two arguments for order. Returns a negative integer, zero, or a positive integer as
// * the first argument is less than, equal to, or greater than the second.
// *
// * @param o1
// * @param o2
// * @return
// */
// @Override
// public int compare(Job o1, Job o2) {
// // ordering of priority is 1... 2... 3.... N...., where 1 is higher
// if(o1.getCategory().getPriority() > o2.getCategory().getPriority()) {
// return 1;
// } else if(o1.getCategory().getPriority() < o2.getCategory().getPriority()) {
// return -1;
// } else {
// return 0;
// }
// }
// }
//
// Path: src/main/java/yourwebproject2/service/JobService.java
// public interface JobService extends BaseService<Job, Long> {
// /**
// *
// * @param count
// * @return
// */
// public List<Job> fetchNewJobsToBeScheduledForExecutionPerPriority(int count);
//
// /**
// *
// * @param count
// * @return
// */
// public List<Job> fetchFailedJobsToBeScheduledForExecutionPerPriority(int count);
//
// /**
// *
// * @param count
// * @return
// */
// public List<Job> fetchNewJobsToBeScheduledForExecutionPerSubmissionTimePriority(int count);
//
// /**
// *
// * @param count
// * @return
// */
// public List<Job> fetchFailedJobsToBeScheduledForExecutionPerSubmissionTimePriority(int count);
// }
// Path: src/main/java/yourwebproject2/core/NewJobSchedulingWorker.java
import yourwebproject2.model.entity.Job;
import yourwebproject2.model.entity.helper.CategoryPriorityComparator;
import yourwebproject2.service.JobService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import java.util.*;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
package yourwebproject2.core;
/**
* Created by Y.Kamesh on 8/5/2015.
*/
public class NewJobSchedulingWorker extends AbstractJobSchedulingWorker {
private static Logger LOG = LoggerFactory.getLogger(NewJobSchedulingWorker.class);
@Autowired
private JobService jobService;
private ExecutorService executorService = Executors.newFixedThreadPool(50);
/**
* Runs every five minutes.
*/
@Scheduled(initialDelay = 5000L, fixedRate = 5 * 60 * 1000L)
public void scheduleNewJobsForExecution() {
LOG.info("Fetching new jobs as per category and submit time priority..."); | List<Job> newJobs = jobService.fetchNewJobsToBeScheduledForExecutionPerSubmissionTimePriority(10); |
ykameshrao/spring-mvc-angular-js-hibernate-bootstrap-java-single-page-jwt-auth-rest-api-webapp-framework | src/main/java/yourwebproject2/core/NewJobSchedulingWorker.java | // Path: src/main/java/yourwebproject2/model/entity/Job.java
// @Entity
// @Table(indexes = { @Index(name="name_idx", columnList = "name", unique = true),
// @Index(name="status_idx", columnList = "status"),
// @Index(name="category_idx", columnList = "category")})
// public class Job extends JPAEntity<Long> {
// public enum Status {
// NEW, EXECUTING, PRIORITIZED, FAILED, RETRYING, SUCCESSFUL
// }
//
// private String name;
// private String metadataJson;
// private String callbackUrl;
// private Date submitTime;
// private Status status;
// private Date scheduledTime;
// private Date completionTime;
// private Integer retryCount;
// private Category category;
//
// @NotNull @NotBlank
// @Column
// public String getName() {
// return name;
// }
//
// public void setName(String name) {
// this.name = name;
// }
//
// @Column
// public String getCallbackUrl() {
// return callbackUrl;
// }
//
// public void setCallbackUrl(String callbackUrl) {
// this.callbackUrl = callbackUrl;
// }
//
// @Column
// public String getMetadataJson() {
// return metadataJson;
// }
//
// public void setMetadataJson(String metadataJson) {
// this.metadataJson = metadataJson;
// }
//
// @NotNull
// @Column
// public Date getSubmitTime() {
// return submitTime;
// }
//
// public void setSubmitTime(Date submitTime) {
// this.submitTime = submitTime;
// }
//
// @OneToOne(fetch = FetchType.EAGER)
// public Category getCategory() {
// return category;
// }
//
// public void setCategory(Category category) {
// this.category = category;
// }
//
// @NotNull
// @Column
// public Status getStatus() {
// return status;
// }
//
// public void setStatus(Status status) {
// this.status = status;
// }
//
// @Column
// public Date getScheduledTime() {
// return scheduledTime;
// }
//
// public void setScheduledTime(Date scheduledTime) {
// this.scheduledTime = scheduledTime;
// }
//
// @Column
// public Date getCompletionTime() {
// return completionTime;
// }
//
// public void setCompletionTime(Date completionTime) {
// this.completionTime = completionTime;
// }
//
// @Column
// public Integer getRetryCount() {
// return retryCount;
// }
//
// public void setRetryCount(Integer retryCount) {
// this.retryCount = retryCount;
// }
//
// @Override
// public String toString() {
// return "Job{" +
// "name='" + name + '\'' +
// ", metadataJson='" + metadataJson + '\'' +
// ", callbackUrl='" + callbackUrl + '\'' +
// ", submitTime=" + submitTime +
// ", status=" + status +
// ", scheduledTime=" + scheduledTime +
// ", completionTime=" + completionTime +
// ", retryCount=" + retryCount +
// ", category=" + category +
// '}';
// }
// }
//
// Path: src/main/java/yourwebproject2/model/entity/helper/CategoryPriorityComparator.java
// public class CategoryPriorityComparator implements Comparator<Job> {
//
// /**
// * Compares its two arguments for order. Returns a negative integer, zero, or a positive integer as
// * the first argument is less than, equal to, or greater than the second.
// *
// * @param o1
// * @param o2
// * @return
// */
// @Override
// public int compare(Job o1, Job o2) {
// // ordering of priority is 1... 2... 3.... N...., where 1 is higher
// if(o1.getCategory().getPriority() > o2.getCategory().getPriority()) {
// return 1;
// } else if(o1.getCategory().getPriority() < o2.getCategory().getPriority()) {
// return -1;
// } else {
// return 0;
// }
// }
// }
//
// Path: src/main/java/yourwebproject2/service/JobService.java
// public interface JobService extends BaseService<Job, Long> {
// /**
// *
// * @param count
// * @return
// */
// public List<Job> fetchNewJobsToBeScheduledForExecutionPerPriority(int count);
//
// /**
// *
// * @param count
// * @return
// */
// public List<Job> fetchFailedJobsToBeScheduledForExecutionPerPriority(int count);
//
// /**
// *
// * @param count
// * @return
// */
// public List<Job> fetchNewJobsToBeScheduledForExecutionPerSubmissionTimePriority(int count);
//
// /**
// *
// * @param count
// * @return
// */
// public List<Job> fetchFailedJobsToBeScheduledForExecutionPerSubmissionTimePriority(int count);
// }
| import yourwebproject2.model.entity.Job;
import yourwebproject2.model.entity.helper.CategoryPriorityComparator;
import yourwebproject2.service.JobService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import java.util.*;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future; | package yourwebproject2.core;
/**
* Created by Y.Kamesh on 8/5/2015.
*/
public class NewJobSchedulingWorker extends AbstractJobSchedulingWorker {
private static Logger LOG = LoggerFactory.getLogger(NewJobSchedulingWorker.class);
@Autowired
private JobService jobService;
private ExecutorService executorService = Executors.newFixedThreadPool(50);
/**
* Runs every five minutes.
*/
@Scheduled(initialDelay = 5000L, fixedRate = 5 * 60 * 1000L)
public void scheduleNewJobsForExecution() {
LOG.info("Fetching new jobs as per category and submit time priority...");
List<Job> newJobs = jobService.fetchNewJobsToBeScheduledForExecutionPerSubmissionTimePriority(10);
LOG.info("Fetched Jobs Count: "+newJobs.size()); | // Path: src/main/java/yourwebproject2/model/entity/Job.java
// @Entity
// @Table(indexes = { @Index(name="name_idx", columnList = "name", unique = true),
// @Index(name="status_idx", columnList = "status"),
// @Index(name="category_idx", columnList = "category")})
// public class Job extends JPAEntity<Long> {
// public enum Status {
// NEW, EXECUTING, PRIORITIZED, FAILED, RETRYING, SUCCESSFUL
// }
//
// private String name;
// private String metadataJson;
// private String callbackUrl;
// private Date submitTime;
// private Status status;
// private Date scheduledTime;
// private Date completionTime;
// private Integer retryCount;
// private Category category;
//
// @NotNull @NotBlank
// @Column
// public String getName() {
// return name;
// }
//
// public void setName(String name) {
// this.name = name;
// }
//
// @Column
// public String getCallbackUrl() {
// return callbackUrl;
// }
//
// public void setCallbackUrl(String callbackUrl) {
// this.callbackUrl = callbackUrl;
// }
//
// @Column
// public String getMetadataJson() {
// return metadataJson;
// }
//
// public void setMetadataJson(String metadataJson) {
// this.metadataJson = metadataJson;
// }
//
// @NotNull
// @Column
// public Date getSubmitTime() {
// return submitTime;
// }
//
// public void setSubmitTime(Date submitTime) {
// this.submitTime = submitTime;
// }
//
// @OneToOne(fetch = FetchType.EAGER)
// public Category getCategory() {
// return category;
// }
//
// public void setCategory(Category category) {
// this.category = category;
// }
//
// @NotNull
// @Column
// public Status getStatus() {
// return status;
// }
//
// public void setStatus(Status status) {
// this.status = status;
// }
//
// @Column
// public Date getScheduledTime() {
// return scheduledTime;
// }
//
// public void setScheduledTime(Date scheduledTime) {
// this.scheduledTime = scheduledTime;
// }
//
// @Column
// public Date getCompletionTime() {
// return completionTime;
// }
//
// public void setCompletionTime(Date completionTime) {
// this.completionTime = completionTime;
// }
//
// @Column
// public Integer getRetryCount() {
// return retryCount;
// }
//
// public void setRetryCount(Integer retryCount) {
// this.retryCount = retryCount;
// }
//
// @Override
// public String toString() {
// return "Job{" +
// "name='" + name + '\'' +
// ", metadataJson='" + metadataJson + '\'' +
// ", callbackUrl='" + callbackUrl + '\'' +
// ", submitTime=" + submitTime +
// ", status=" + status +
// ", scheduledTime=" + scheduledTime +
// ", completionTime=" + completionTime +
// ", retryCount=" + retryCount +
// ", category=" + category +
// '}';
// }
// }
//
// Path: src/main/java/yourwebproject2/model/entity/helper/CategoryPriorityComparator.java
// public class CategoryPriorityComparator implements Comparator<Job> {
//
// /**
// * Compares its two arguments for order. Returns a negative integer, zero, or a positive integer as
// * the first argument is less than, equal to, or greater than the second.
// *
// * @param o1
// * @param o2
// * @return
// */
// @Override
// public int compare(Job o1, Job o2) {
// // ordering of priority is 1... 2... 3.... N...., where 1 is higher
// if(o1.getCategory().getPriority() > o2.getCategory().getPriority()) {
// return 1;
// } else if(o1.getCategory().getPriority() < o2.getCategory().getPriority()) {
// return -1;
// } else {
// return 0;
// }
// }
// }
//
// Path: src/main/java/yourwebproject2/service/JobService.java
// public interface JobService extends BaseService<Job, Long> {
// /**
// *
// * @param count
// * @return
// */
// public List<Job> fetchNewJobsToBeScheduledForExecutionPerPriority(int count);
//
// /**
// *
// * @param count
// * @return
// */
// public List<Job> fetchFailedJobsToBeScheduledForExecutionPerPriority(int count);
//
// /**
// *
// * @param count
// * @return
// */
// public List<Job> fetchNewJobsToBeScheduledForExecutionPerSubmissionTimePriority(int count);
//
// /**
// *
// * @param count
// * @return
// */
// public List<Job> fetchFailedJobsToBeScheduledForExecutionPerSubmissionTimePriority(int count);
// }
// Path: src/main/java/yourwebproject2/core/NewJobSchedulingWorker.java
import yourwebproject2.model.entity.Job;
import yourwebproject2.model.entity.helper.CategoryPriorityComparator;
import yourwebproject2.service.JobService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import java.util.*;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
package yourwebproject2.core;
/**
* Created by Y.Kamesh on 8/5/2015.
*/
public class NewJobSchedulingWorker extends AbstractJobSchedulingWorker {
private static Logger LOG = LoggerFactory.getLogger(NewJobSchedulingWorker.class);
@Autowired
private JobService jobService;
private ExecutorService executorService = Executors.newFixedThreadPool(50);
/**
* Runs every five minutes.
*/
@Scheduled(initialDelay = 5000L, fixedRate = 5 * 60 * 1000L)
public void scheduleNewJobsForExecution() {
LOG.info("Fetching new jobs as per category and submit time priority...");
List<Job> newJobs = jobService.fetchNewJobsToBeScheduledForExecutionPerSubmissionTimePriority(10);
LOG.info("Fetched Jobs Count: "+newJobs.size()); | Collections.sort(newJobs, new CategoryPriorityComparator()); |
ykameshrao/spring-mvc-angular-js-hibernate-bootstrap-java-single-page-jwt-auth-rest-api-webapp-framework | src/main/java/yourwebproject2/unusedspringsecurity/UserRole.java | // Path: src/main/java/yourwebproject2/model/entity/User.java
// @Entity
// @Inheritance(strategy = InheritanceType.SINGLE_TABLE)
// @Table(indexes = { @Index(name="email_idx", columnList = "email", unique = true),
// @Index(name="displayName_idx", columnList = "display_name") })
// public class User extends JPAEntity<Long> implements Serializable {
// public enum Role {
// USER,
// ADMIN
// }
//
// private String email;
// private @JsonIgnore String password;
// private boolean enabled;
// private Role role;
// private String displayName;
//
// private @JsonIgnore Integer loginCount;
// private Date currentLoginAt;
// private Date lastLoginAt;
// private @JsonIgnore String currentLoginIp;
// private @JsonIgnore String lastLoginIp;
//
// private static BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder();
//
// @Column @Email @NotNull @NotBlank
// public String getEmail() {
// return this.email;
// }
//
// public void setEmail(String email) {
// this.email = email;
// }
//
// @JsonIgnore @Column(nullable = false, length = 60)
// public String getPassword() {
// return this.password;
// }
//
// public void setPassword(String password) {
// this.password = password;
// }
//
// @Column(nullable = false)
// public boolean isEnabled() {
// return this.enabled;
// }
//
// public void setEnabled(boolean enabled) {
// this.enabled = enabled;
// }
//
// @Column(nullable = false)
// public Role getRole() {
// return this.role;
// }
//
// public void setRole(Role role) {
// this.role = role;
// }
//
// @Column(name="display_name")
// public String getDisplayName() {
// return displayName;
// }
//
// public void setDisplayName(String displayName) {
// this.displayName = displayName;
// }
//
// @JsonIgnore @Column
// public Integer getLoginCount() {
// return loginCount;
// }
//
// public void setLoginCount(Integer loginCount) {
// this.loginCount = loginCount;
// }
//
// @Column
// public Date getCurrentLoginAt() {
// return currentLoginAt;
// }
//
// public void setCurrentLoginAt(Date currentLoginAt) {
// this.currentLoginAt = currentLoginAt;
// }
//
// @Column
// public Date getLastLoginAt() {
// return lastLoginAt;
// }
//
// public void setLastLoginAt(Date lastLoginAt) {
// this.lastLoginAt = lastLoginAt;
// }
//
// @JsonIgnore @Column
// public String getCurrentLoginIp() {
// return currentLoginIp;
// }
//
// public void setCurrentLoginIp(String currentLoginIp) {
// this.currentLoginIp = currentLoginIp;
// }
//
// @JsonIgnore @Column
// public String getLastLoginIp() {
// return lastLoginIp;
// }
//
// public void setLastLoginIp(String lastLoginIp) {
// this.lastLoginIp = lastLoginIp;
// }
//
// /**
// * Method to create the hash of the password before storing
// *
// * @param pass
// *
// * @return SHA hash digest of the password
// */
// public static synchronized String hashPassword(String pass) {
// return passwordEncoder.encode(pass);
// }
//
// public static synchronized boolean doesPasswordMatch(String rawPass, String encodedPass) {
// return passwordEncoder.matches(rawPass, encodedPass);
// }
//
// @Override
// public String toString() {
// return "User{" +
// "email='" + email + '\'' +
// ", password='" + password + '\'' +
// ", enabled=" + enabled +
// ", role=" + role +
// ", displayName='" + displayName + '\'' +
// ", loginCount=" + loginCount +
// ", currentLoginAt=" + currentLoginAt +
// ", lastLoginAt=" + lastLoginAt +
// ", currentLoginIp='" + currentLoginIp + '\'' +
// ", lastLoginIp='" + lastLoginIp + '\'' +
// '}';
// }
// }
| import yourwebproject2.model.entity.User;
import javax.persistence.*;
import java.io.Serializable; | package yourwebproject2.unusedspringsecurity;
/**
* @author: kameshr
*/
//@Entity
//@Table(indexes = { @Index(name="email_fk_idx", columnList = "email", unique = true) })
public class UserRole implements Serializable {
private Integer userRoleId; | // Path: src/main/java/yourwebproject2/model/entity/User.java
// @Entity
// @Inheritance(strategy = InheritanceType.SINGLE_TABLE)
// @Table(indexes = { @Index(name="email_idx", columnList = "email", unique = true),
// @Index(name="displayName_idx", columnList = "display_name") })
// public class User extends JPAEntity<Long> implements Serializable {
// public enum Role {
// USER,
// ADMIN
// }
//
// private String email;
// private @JsonIgnore String password;
// private boolean enabled;
// private Role role;
// private String displayName;
//
// private @JsonIgnore Integer loginCount;
// private Date currentLoginAt;
// private Date lastLoginAt;
// private @JsonIgnore String currentLoginIp;
// private @JsonIgnore String lastLoginIp;
//
// private static BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder();
//
// @Column @Email @NotNull @NotBlank
// public String getEmail() {
// return this.email;
// }
//
// public void setEmail(String email) {
// this.email = email;
// }
//
// @JsonIgnore @Column(nullable = false, length = 60)
// public String getPassword() {
// return this.password;
// }
//
// public void setPassword(String password) {
// this.password = password;
// }
//
// @Column(nullable = false)
// public boolean isEnabled() {
// return this.enabled;
// }
//
// public void setEnabled(boolean enabled) {
// this.enabled = enabled;
// }
//
// @Column(nullable = false)
// public Role getRole() {
// return this.role;
// }
//
// public void setRole(Role role) {
// this.role = role;
// }
//
// @Column(name="display_name")
// public String getDisplayName() {
// return displayName;
// }
//
// public void setDisplayName(String displayName) {
// this.displayName = displayName;
// }
//
// @JsonIgnore @Column
// public Integer getLoginCount() {
// return loginCount;
// }
//
// public void setLoginCount(Integer loginCount) {
// this.loginCount = loginCount;
// }
//
// @Column
// public Date getCurrentLoginAt() {
// return currentLoginAt;
// }
//
// public void setCurrentLoginAt(Date currentLoginAt) {
// this.currentLoginAt = currentLoginAt;
// }
//
// @Column
// public Date getLastLoginAt() {
// return lastLoginAt;
// }
//
// public void setLastLoginAt(Date lastLoginAt) {
// this.lastLoginAt = lastLoginAt;
// }
//
// @JsonIgnore @Column
// public String getCurrentLoginIp() {
// return currentLoginIp;
// }
//
// public void setCurrentLoginIp(String currentLoginIp) {
// this.currentLoginIp = currentLoginIp;
// }
//
// @JsonIgnore @Column
// public String getLastLoginIp() {
// return lastLoginIp;
// }
//
// public void setLastLoginIp(String lastLoginIp) {
// this.lastLoginIp = lastLoginIp;
// }
//
// /**
// * Method to create the hash of the password before storing
// *
// * @param pass
// *
// * @return SHA hash digest of the password
// */
// public static synchronized String hashPassword(String pass) {
// return passwordEncoder.encode(pass);
// }
//
// public static synchronized boolean doesPasswordMatch(String rawPass, String encodedPass) {
// return passwordEncoder.matches(rawPass, encodedPass);
// }
//
// @Override
// public String toString() {
// return "User{" +
// "email='" + email + '\'' +
// ", password='" + password + '\'' +
// ", enabled=" + enabled +
// ", role=" + role +
// ", displayName='" + displayName + '\'' +
// ", loginCount=" + loginCount +
// ", currentLoginAt=" + currentLoginAt +
// ", lastLoginAt=" + lastLoginAt +
// ", currentLoginIp='" + currentLoginIp + '\'' +
// ", lastLoginIp='" + lastLoginIp + '\'' +
// '}';
// }
// }
// Path: src/main/java/yourwebproject2/unusedspringsecurity/UserRole.java
import yourwebproject2.model.entity.User;
import javax.persistence.*;
import java.io.Serializable;
package yourwebproject2.unusedspringsecurity;
/**
* @author: kameshr
*/
//@Entity
//@Table(indexes = { @Index(name="email_fk_idx", columnList = "email", unique = true) })
public class UserRole implements Serializable {
private Integer userRoleId; | private User user; |
ykameshrao/spring-mvc-angular-js-hibernate-bootstrap-java-single-page-jwt-auth-rest-api-webapp-framework | src/main/java/yourwebproject2/model/entity/User.java | // Path: src/main/java/yourwebproject2/framework/data/JPAEntity.java
// @MappedSuperclass
// public abstract class JPAEntity<T extends Serializable> implements Entity {
// protected T id;
// protected Date createdAt;
// protected Date updatedAt;
//
//
// public JPAEntity() {
// createdAt = new Date();
// updatedAt = new Date();
// }
//
//
// /**
// * To make XStream deserialization assign values to
// * base class fields of createdAt and updatedAt
// *
// * @return
// */
// public Object readResolve() {
// if (this.createdAt == null) {
// this.createdAt = new Date();
// this.updatedAt = createdAt;
// }
//
// return this;
// }
//
//
// @XmlElement(type = Object.class) @Id @GeneratedValue
// public T getId() {
// return id;
// }
//
//
// public void setId(T id) {
// this.id = id;
// }
//
//
// @JsonIgnore @Temporal(TemporalType.DATE) @Column
// public Date getCreatedAt() {
// return createdAt;
// }
//
//
// public void setCreatedAt(Date createdAt) {
// this.createdAt = createdAt;
// }
//
//
// @JsonIgnore @Temporal(TemporalType.TIMESTAMP) @Column
// public Date getUpdatedAt() {
// return updatedAt;
// }
//
//
// public void setUpdatedAt(Date updatedAt) {
// this.updatedAt = updatedAt;
// }
// }
| import com.fasterxml.jackson.annotation.JsonIgnore;
import yourwebproject2.framework.data.JPAEntity;
import org.hibernate.validator.constraints.Email;
import org.hibernate.validator.constraints.NotBlank;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import javax.persistence.*;
import javax.validation.constraints.NotNull;
import java.io.Serializable;
import java.util.Date; | package yourwebproject2.model.entity;
/**
* Created by Y.Kamesh on 10/9/2015.
*/
@Entity
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@Table(indexes = { @Index(name="email_idx", columnList = "email", unique = true),
@Index(name="displayName_idx", columnList = "display_name") }) | // Path: src/main/java/yourwebproject2/framework/data/JPAEntity.java
// @MappedSuperclass
// public abstract class JPAEntity<T extends Serializable> implements Entity {
// protected T id;
// protected Date createdAt;
// protected Date updatedAt;
//
//
// public JPAEntity() {
// createdAt = new Date();
// updatedAt = new Date();
// }
//
//
// /**
// * To make XStream deserialization assign values to
// * base class fields of createdAt and updatedAt
// *
// * @return
// */
// public Object readResolve() {
// if (this.createdAt == null) {
// this.createdAt = new Date();
// this.updatedAt = createdAt;
// }
//
// return this;
// }
//
//
// @XmlElement(type = Object.class) @Id @GeneratedValue
// public T getId() {
// return id;
// }
//
//
// public void setId(T id) {
// this.id = id;
// }
//
//
// @JsonIgnore @Temporal(TemporalType.DATE) @Column
// public Date getCreatedAt() {
// return createdAt;
// }
//
//
// public void setCreatedAt(Date createdAt) {
// this.createdAt = createdAt;
// }
//
//
// @JsonIgnore @Temporal(TemporalType.TIMESTAMP) @Column
// public Date getUpdatedAt() {
// return updatedAt;
// }
//
//
// public void setUpdatedAt(Date updatedAt) {
// this.updatedAt = updatedAt;
// }
// }
// Path: src/main/java/yourwebproject2/model/entity/User.java
import com.fasterxml.jackson.annotation.JsonIgnore;
import yourwebproject2.framework.data.JPAEntity;
import org.hibernate.validator.constraints.Email;
import org.hibernate.validator.constraints.NotBlank;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import javax.persistence.*;
import javax.validation.constraints.NotNull;
import java.io.Serializable;
import java.util.Date;
package yourwebproject2.model.entity;
/**
* Created by Y.Kamesh on 10/9/2015.
*/
@Entity
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@Table(indexes = { @Index(name="email_idx", columnList = "email", unique = true),
@Index(name="displayName_idx", columnList = "display_name") }) | public class User extends JPAEntity<Long> implements Serializable { |
ykameshrao/spring-mvc-angular-js-hibernate-bootstrap-java-single-page-jwt-auth-rest-api-webapp-framework | src/main/java/yourwebproject2/interceptor/WebAppExceptionAdvice.java | // Path: src/main/java/yourwebproject2/framework/api/APIResponse.java
// @JsonInclude(JsonInclude.Include.NON_NULL)
// public class APIResponse {
// public static final String API_RESPONSE = "apiResponse";
// Object result;
// String time;
// long code;
//
// public static class ExceptionAPIResponse extends APIResponse {
// Object details;
//
// public Object getDetails() {
// return details;
// }
//
// public void setDetails(Object details) {
// this.details = details;
// }
// }
//
// public Object getResult() {
// return result;
// }
//
// public void setResult(Object result) {
// this.result = result;
// }
//
// public String getTime() {
// return time;
// }
//
// public void setTime(String time) {
// this.time = time;
// }
//
// public long getCode() {
// return code;
// }
//
// public void setCode(long code) {
// this.code = code;
// }
//
// public static APIResponse toOkResponse(Object data) {
// return toAPIResponse(data, 200);
// }
//
// public static APIResponse toErrorResponse(Object data) {
// return toAPIResponse(data, 2001);
// }
//
// public static ExceptionAPIResponse toExceptionResponse(String result, Object details) {
// ExceptionAPIResponse response = new ExceptionAPIResponse();
// response.setResult(result);
// response.setDetails(details);
// response.setCode(2001);
// return response;
// }
//
// public APIResponse withModelAndView(ModelAndView modelAndView) {
// modelAndView.addObject(API_RESPONSE, this);
// return this;
// }
//
// public static APIResponse toAPIResponse(Object data, long code) {
// APIResponse response = new APIResponse();
// response.setResult(data);
// response.setCode(code);
// return response;
// }
// }
| import yourwebproject2.framework.api.APIResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody; | package yourwebproject2.interceptor;
/**
* Exception Handler Controller Advice to catch all controller exceptions and respond gracefully to
* the caller
*
* Created by Y.Kamesh on 8/2/2015.
*/
@ControllerAdvice
public class WebAppExceptionAdvice {
private static Logger LOG = LoggerFactory.getLogger(WebAppExceptionAdvice.class);
@ExceptionHandler(Exception.class)
@ResponseBody | // Path: src/main/java/yourwebproject2/framework/api/APIResponse.java
// @JsonInclude(JsonInclude.Include.NON_NULL)
// public class APIResponse {
// public static final String API_RESPONSE = "apiResponse";
// Object result;
// String time;
// long code;
//
// public static class ExceptionAPIResponse extends APIResponse {
// Object details;
//
// public Object getDetails() {
// return details;
// }
//
// public void setDetails(Object details) {
// this.details = details;
// }
// }
//
// public Object getResult() {
// return result;
// }
//
// public void setResult(Object result) {
// this.result = result;
// }
//
// public String getTime() {
// return time;
// }
//
// public void setTime(String time) {
// this.time = time;
// }
//
// public long getCode() {
// return code;
// }
//
// public void setCode(long code) {
// this.code = code;
// }
//
// public static APIResponse toOkResponse(Object data) {
// return toAPIResponse(data, 200);
// }
//
// public static APIResponse toErrorResponse(Object data) {
// return toAPIResponse(data, 2001);
// }
//
// public static ExceptionAPIResponse toExceptionResponse(String result, Object details) {
// ExceptionAPIResponse response = new ExceptionAPIResponse();
// response.setResult(result);
// response.setDetails(details);
// response.setCode(2001);
// return response;
// }
//
// public APIResponse withModelAndView(ModelAndView modelAndView) {
// modelAndView.addObject(API_RESPONSE, this);
// return this;
// }
//
// public static APIResponse toAPIResponse(Object data, long code) {
// APIResponse response = new APIResponse();
// response.setResult(data);
// response.setCode(code);
// return response;
// }
// }
// Path: src/main/java/yourwebproject2/interceptor/WebAppExceptionAdvice.java
import yourwebproject2.framework.api.APIResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
package yourwebproject2.interceptor;
/**
* Exception Handler Controller Advice to catch all controller exceptions and respond gracefully to
* the caller
*
* Created by Y.Kamesh on 8/2/2015.
*/
@ControllerAdvice
public class WebAppExceptionAdvice {
private static Logger LOG = LoggerFactory.getLogger(WebAppExceptionAdvice.class);
@ExceptionHandler(Exception.class)
@ResponseBody | public APIResponse handleAnyException(Exception e) { |
wesleyegberto/java-new-features | java-8/src/main/java/com/github/wesleyegberto/map/StreamFilterTest.java | // Path: java-8/src/main/java/com/github/wesleyegberto/model/Person.java
// public class Person {
// private String name;
// private int age;
//
// public Person(String name, int age) {
// this.name = name;
// this.age = age;
// }
//
// public String getName() {
// return name;
// }
//
// public int getAge() {
// return age;
// }
//
// public String toString() {
// return name + " " + age;
// }
//
// public static List<Person> getList() {
// List<Person> persons = new ArrayList<Person>();
// persons.add(new Person("Tony", 10));
// persons.add(new Person("Logan", 18));
// persons.add(new Person("Peter", 21));
// persons.add(new Person("Bruce", 30));
// persons.add(new Person("Rachel", 11));
// persons.add(new Person("Joey", 14));
// persons.add(new Person("Lucas", 22));
// persons.add(new Person("Neo", 24));
// persons.add(new Person("Jorge", 22));
// persons.add(new Person("Matheus", 24));
// persons.add(new Person("Francis", 19));
// persons.add(new Person("Trinity", 23));
// persons.add(new Person("Morpheu", 42));
// persons.add(new Person("Jorge", 17));
//
// return persons;
// }
// }
| import com.github.wesleyegberto.model.Person;
import java.util.*;
import java.util.stream.Stream; | package com.github.wesleyegberto.map;
public class StreamFilterTest {
public static void main(String[] args) { | // Path: java-8/src/main/java/com/github/wesleyegberto/model/Person.java
// public class Person {
// private String name;
// private int age;
//
// public Person(String name, int age) {
// this.name = name;
// this.age = age;
// }
//
// public String getName() {
// return name;
// }
//
// public int getAge() {
// return age;
// }
//
// public String toString() {
// return name + " " + age;
// }
//
// public static List<Person> getList() {
// List<Person> persons = new ArrayList<Person>();
// persons.add(new Person("Tony", 10));
// persons.add(new Person("Logan", 18));
// persons.add(new Person("Peter", 21));
// persons.add(new Person("Bruce", 30));
// persons.add(new Person("Rachel", 11));
// persons.add(new Person("Joey", 14));
// persons.add(new Person("Lucas", 22));
// persons.add(new Person("Neo", 24));
// persons.add(new Person("Jorge", 22));
// persons.add(new Person("Matheus", 24));
// persons.add(new Person("Francis", 19));
// persons.add(new Person("Trinity", 23));
// persons.add(new Person("Morpheu", 42));
// persons.add(new Person("Jorge", 17));
//
// return persons;
// }
// }
// Path: java-8/src/main/java/com/github/wesleyegberto/map/StreamFilterTest.java
import com.github.wesleyegberto.model.Person;
import java.util.*;
import java.util.stream.Stream;
package com.github.wesleyegberto.map;
public class StreamFilterTest {
public static void main(String[] args) { | List<Person> persons = Person.getList(); |
wesleyegberto/java-new-features | java-8/src/main/java/com/github/wesleyegberto/map/StreamMapTest.java | // Path: java-8/src/main/java/com/github/wesleyegberto/model/Person.java
// public class Person {
// private String name;
// private int age;
//
// public Person(String name, int age) {
// this.name = name;
// this.age = age;
// }
//
// public String getName() {
// return name;
// }
//
// public int getAge() {
// return age;
// }
//
// public String toString() {
// return name + " " + age;
// }
//
// public static List<Person> getList() {
// List<Person> persons = new ArrayList<Person>();
// persons.add(new Person("Tony", 10));
// persons.add(new Person("Logan", 18));
// persons.add(new Person("Peter", 21));
// persons.add(new Person("Bruce", 30));
// persons.add(new Person("Rachel", 11));
// persons.add(new Person("Joey", 14));
// persons.add(new Person("Lucas", 22));
// persons.add(new Person("Neo", 24));
// persons.add(new Person("Jorge", 22));
// persons.add(new Person("Matheus", 24));
// persons.add(new Person("Francis", 19));
// persons.add(new Person("Trinity", 23));
// persons.add(new Person("Morpheu", 42));
// persons.add(new Person("Jorge", 17));
//
// return persons;
// }
// }
//
// Path: java-8/src/main/java/com/github/wesleyegberto/model/Warrior.java
// public class Warrior {
// private Person person;
// private String type;
//
// public Warrior(Person person) {
// this.person = person;
// type = "Warrior " + person.getAge();
// }
//
// public String getType() {
// return type;
// }
//
// public String toString() {
// return type;
// }
//
// }
| import java.util.*;
import java.util.stream.Stream;
import java.util.function.Function; // map operations -> transformations
import com.github.wesleyegberto.model.Person;
import com.github.wesleyegberto.model.Warrior; | package com.github.wesleyegberto.map;
public class StreamMapTest {
public static void main(String[] args) { | // Path: java-8/src/main/java/com/github/wesleyegberto/model/Person.java
// public class Person {
// private String name;
// private int age;
//
// public Person(String name, int age) {
// this.name = name;
// this.age = age;
// }
//
// public String getName() {
// return name;
// }
//
// public int getAge() {
// return age;
// }
//
// public String toString() {
// return name + " " + age;
// }
//
// public static List<Person> getList() {
// List<Person> persons = new ArrayList<Person>();
// persons.add(new Person("Tony", 10));
// persons.add(new Person("Logan", 18));
// persons.add(new Person("Peter", 21));
// persons.add(new Person("Bruce", 30));
// persons.add(new Person("Rachel", 11));
// persons.add(new Person("Joey", 14));
// persons.add(new Person("Lucas", 22));
// persons.add(new Person("Neo", 24));
// persons.add(new Person("Jorge", 22));
// persons.add(new Person("Matheus", 24));
// persons.add(new Person("Francis", 19));
// persons.add(new Person("Trinity", 23));
// persons.add(new Person("Morpheu", 42));
// persons.add(new Person("Jorge", 17));
//
// return persons;
// }
// }
//
// Path: java-8/src/main/java/com/github/wesleyegberto/model/Warrior.java
// public class Warrior {
// private Person person;
// private String type;
//
// public Warrior(Person person) {
// this.person = person;
// type = "Warrior " + person.getAge();
// }
//
// public String getType() {
// return type;
// }
//
// public String toString() {
// return type;
// }
//
// }
// Path: java-8/src/main/java/com/github/wesleyegberto/map/StreamMapTest.java
import java.util.*;
import java.util.stream.Stream;
import java.util.function.Function; // map operations -> transformations
import com.github.wesleyegberto.model.Person;
import com.github.wesleyegberto.model.Warrior;
package com.github.wesleyegberto.map;
public class StreamMapTest {
public static void main(String[] args) { | List<Person> persons = Person.getList(); |
wesleyegberto/java-new-features | java-8/src/main/java/com/github/wesleyegberto/map/StreamMapTest.java | // Path: java-8/src/main/java/com/github/wesleyegberto/model/Person.java
// public class Person {
// private String name;
// private int age;
//
// public Person(String name, int age) {
// this.name = name;
// this.age = age;
// }
//
// public String getName() {
// return name;
// }
//
// public int getAge() {
// return age;
// }
//
// public String toString() {
// return name + " " + age;
// }
//
// public static List<Person> getList() {
// List<Person> persons = new ArrayList<Person>();
// persons.add(new Person("Tony", 10));
// persons.add(new Person("Logan", 18));
// persons.add(new Person("Peter", 21));
// persons.add(new Person("Bruce", 30));
// persons.add(new Person("Rachel", 11));
// persons.add(new Person("Joey", 14));
// persons.add(new Person("Lucas", 22));
// persons.add(new Person("Neo", 24));
// persons.add(new Person("Jorge", 22));
// persons.add(new Person("Matheus", 24));
// persons.add(new Person("Francis", 19));
// persons.add(new Person("Trinity", 23));
// persons.add(new Person("Morpheu", 42));
// persons.add(new Person("Jorge", 17));
//
// return persons;
// }
// }
//
// Path: java-8/src/main/java/com/github/wesleyegberto/model/Warrior.java
// public class Warrior {
// private Person person;
// private String type;
//
// public Warrior(Person person) {
// this.person = person;
// type = "Warrior " + person.getAge();
// }
//
// public String getType() {
// return type;
// }
//
// public String toString() {
// return type;
// }
//
// }
| import java.util.*;
import java.util.stream.Stream;
import java.util.function.Function; // map operations -> transformations
import com.github.wesleyegberto.model.Person;
import com.github.wesleyegberto.model.Warrior; | package com.github.wesleyegberto.map;
public class StreamMapTest {
public static void main(String[] args) {
List<Person> persons = Person.getList();
System.out.println("Map operation using anonymous inner class: "); | // Path: java-8/src/main/java/com/github/wesleyegberto/model/Person.java
// public class Person {
// private String name;
// private int age;
//
// public Person(String name, int age) {
// this.name = name;
// this.age = age;
// }
//
// public String getName() {
// return name;
// }
//
// public int getAge() {
// return age;
// }
//
// public String toString() {
// return name + " " + age;
// }
//
// public static List<Person> getList() {
// List<Person> persons = new ArrayList<Person>();
// persons.add(new Person("Tony", 10));
// persons.add(new Person("Logan", 18));
// persons.add(new Person("Peter", 21));
// persons.add(new Person("Bruce", 30));
// persons.add(new Person("Rachel", 11));
// persons.add(new Person("Joey", 14));
// persons.add(new Person("Lucas", 22));
// persons.add(new Person("Neo", 24));
// persons.add(new Person("Jorge", 22));
// persons.add(new Person("Matheus", 24));
// persons.add(new Person("Francis", 19));
// persons.add(new Person("Trinity", 23));
// persons.add(new Person("Morpheu", 42));
// persons.add(new Person("Jorge", 17));
//
// return persons;
// }
// }
//
// Path: java-8/src/main/java/com/github/wesleyegberto/model/Warrior.java
// public class Warrior {
// private Person person;
// private String type;
//
// public Warrior(Person person) {
// this.person = person;
// type = "Warrior " + person.getAge();
// }
//
// public String getType() {
// return type;
// }
//
// public String toString() {
// return type;
// }
//
// }
// Path: java-8/src/main/java/com/github/wesleyegberto/map/StreamMapTest.java
import java.util.*;
import java.util.stream.Stream;
import java.util.function.Function; // map operations -> transformations
import com.github.wesleyegberto.model.Person;
import com.github.wesleyegberto.model.Warrior;
package com.github.wesleyegberto.map;
public class StreamMapTest {
public static void main(String[] args) {
List<Person> persons = Person.getList();
System.out.println("Map operation using anonymous inner class: "); | Stream<Warrior> warriors = persons.stream() |
jameskennard/mockito-collections | mockito-collections-core/src/main/java/uk/co/webamoeba/mockito/collections/inject/InjectionDetails.java | // Path: mockito-collections-core/src/main/java/uk/co/webamoeba/mockito/collections/util/OrderedSet.java
// public class OrderedSet<E> implements Set<E> {
//
// private LinkedHashSet<E> set;
//
// public OrderedSet() {
// this.set = new LinkedHashSet<E>();
// }
//
// public OrderedSet(Collection<E> set) {
// this.set = new LinkedHashSet<E>(set);
// }
//
// public OrderedSet(int initialCapacity) {
// this.set = new LinkedHashSet<E>(initialCapacity);
// }
//
// public Object[] toArray() {
// return set.toArray();
// }
//
// public boolean removeAll(Collection<?> c) {
// return set.removeAll(c);
// }
//
// public <T> T[] toArray(T[] a) {
// return set.toArray(a);
// }
//
// public Iterator<E> iterator() {
// return set.iterator();
// }
//
// public int size() {
// return set.size();
// }
//
// public boolean isEmpty() {
// return set.isEmpty();
// }
//
// public boolean contains(Object o) {
// return set.contains(o);
// }
//
// public boolean add(E o) {
// return set.add(o);
// }
//
// public boolean remove(Object o) {
// return set.remove(o);
// }
//
// public void clear() {
// set.clear();
// }
//
// @Override
// public Object clone() {
// return set.clone();
// }
//
// public boolean containsAll(Collection<?> c) {
// return set.containsAll(c);
// }
//
// public boolean addAll(Collection<? extends E> c) {
// return set.addAll(c);
// }
//
// public boolean retainAll(Collection<?> c) {
// return set.retainAll(c);
// }
//
// @Override
// public String toString() {
// return set.toString();
// }
//
// @Override
// public boolean equals(Object obj) {
// if (this == obj) {
// return true;
// }
// if (obj == null || !getClass().equals(obj.getClass())) {
// return false;
// }
// return set.equals(obj);
// }
//
// @Override
// public int hashCode() {
// return 31 * 1 + ((set == null) ? 0 : set.hashCode());
// }
// }
| import java.util.Collection;
import java.util.Collections;
import java.util.Set;
import org.mockito.Mock;
import uk.co.webamoeba.mockito.collections.util.OrderedSet; | package uk.co.webamoeba.mockito.collections.inject;
/**
* Describes {@link Object}s that we want to inject into and be injected with {@link Collection}s of {@link Mock Mocks}.
*
* @author James Kennard
*/
public class InjectionDetails {
private Set<Object> injectCollections;
| // Path: mockito-collections-core/src/main/java/uk/co/webamoeba/mockito/collections/util/OrderedSet.java
// public class OrderedSet<E> implements Set<E> {
//
// private LinkedHashSet<E> set;
//
// public OrderedSet() {
// this.set = new LinkedHashSet<E>();
// }
//
// public OrderedSet(Collection<E> set) {
// this.set = new LinkedHashSet<E>(set);
// }
//
// public OrderedSet(int initialCapacity) {
// this.set = new LinkedHashSet<E>(initialCapacity);
// }
//
// public Object[] toArray() {
// return set.toArray();
// }
//
// public boolean removeAll(Collection<?> c) {
// return set.removeAll(c);
// }
//
// public <T> T[] toArray(T[] a) {
// return set.toArray(a);
// }
//
// public Iterator<E> iterator() {
// return set.iterator();
// }
//
// public int size() {
// return set.size();
// }
//
// public boolean isEmpty() {
// return set.isEmpty();
// }
//
// public boolean contains(Object o) {
// return set.contains(o);
// }
//
// public boolean add(E o) {
// return set.add(o);
// }
//
// public boolean remove(Object o) {
// return set.remove(o);
// }
//
// public void clear() {
// set.clear();
// }
//
// @Override
// public Object clone() {
// return set.clone();
// }
//
// public boolean containsAll(Collection<?> c) {
// return set.containsAll(c);
// }
//
// public boolean addAll(Collection<? extends E> c) {
// return set.addAll(c);
// }
//
// public boolean retainAll(Collection<?> c) {
// return set.retainAll(c);
// }
//
// @Override
// public String toString() {
// return set.toString();
// }
//
// @Override
// public boolean equals(Object obj) {
// if (this == obj) {
// return true;
// }
// if (obj == null || !getClass().equals(obj.getClass())) {
// return false;
// }
// return set.equals(obj);
// }
//
// @Override
// public int hashCode() {
// return 31 * 1 + ((set == null) ? 0 : set.hashCode());
// }
// }
// Path: mockito-collections-core/src/main/java/uk/co/webamoeba/mockito/collections/inject/InjectionDetails.java
import java.util.Collection;
import java.util.Collections;
import java.util.Set;
import org.mockito.Mock;
import uk.co.webamoeba.mockito.collections.util.OrderedSet;
package uk.co.webamoeba.mockito.collections.inject;
/**
* Describes {@link Object}s that we want to inject into and be injected with {@link Collection}s of {@link Mock Mocks}.
*
* @author James Kennard
*/
public class InjectionDetails {
private Set<Object> injectCollections;
| private OrderedSet<Object> mocks; |
jameskennard/mockito-collections | mockito-collections-core-integration-tests/src/test/java/uk/co/webamoeba/mockito/collections/core/integrationtests/InjectCollectionsOfMocksIntoInheritedCollectionsStoryIntegrationTest.java | // Path: mockito-collections-core/src/main/java/uk/co/webamoeba/mockito/collections/MockitoCollections.java
// public class MockitoCollections {
//
// private static Initialiser INITIALISER = new Initialiser();
//
// private static Verifier VERIFIER = new Verifier();
//
// /**
// * {@link Initialiser#initialise(Object)}
// *
// * @param object
// */
// public static void initialise(Object object) {
// INITIALISER.initialise(object);
// }
//
// /**
// * {@link Verifier#collectiveVerify(Class, Collection)}
// *
// * @param mockClass
// * @param collection
// * @return Object used for verification of all the mocks in the supplied collection
// */
// public static <T> T collectiveVerify(Class<T> mockClass, Collection<T> collection) {
// return VERIFIER.collectiveVerify(mockClass, collection);
// }
//
// /**
// * {@link Verifier#collectiveVerify(Class, Collection, VerificationMode)}
// *
// * @param mockClass
// * @param collection
// * @param mode
// * @return Object used for verification of all the mocks in the supplied collection
// */
// public static <T> T collectiveVerify(Class<T> mockClass, Collection<T> collection, VerificationMode mode) {
// return VERIFIER.collectiveVerify(mockClass, collection, mode);
// }
//
// /**
// * {@link Verifier#collectiveVerifyZeroInteractions(Collection...)}
// *
// * @param mocks
// */
// public static <T> void collectiveVerifyZeroInteractions(Collection<T>... mocks) {
// VERIFIER.collectiveVerifyZeroInteractions(mocks);
// }
//
// /**
// * {@link Verifier#collectiveVerifyNoMoreInteractions(Collection...)}
// *
// * @param mocks
// */
// public static <T> void collectiveVerifyNoMoreInteractions(Collection<T>... mocks) {
// VERIFIER.collectiveVerifyNoMoreInteractions(mocks);
// }
// }
//
// Path: mockito-collections-core-integration-tests/src/main/java/uk/co/webamoeba/mockito/collections/core/integrationtests/support/ClassWithInheritedCollectionOfCollaborators.java
// public class ClassWithInheritedCollectionOfCollaborators extends ClassWithCollectionOfCollaborators {
//
// }
| import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertSame;
import static org.mockito.Mockito.mock;
import java.util.EventListener;
import java.util.Iterator;
import org.junit.Test;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import uk.co.webamoeba.mockito.collections.MockitoCollections;
import uk.co.webamoeba.mockito.collections.core.integrationtests.support.ClassWithInheritedCollectionOfCollaborators; | package uk.co.webamoeba.mockito.collections.core.integrationtests;
public class InjectCollectionsOfMocksIntoInheritedCollectionsStoryIntegrationTest implements
InjectCollectionsOfMocksIntoInheritedCollectionsStory {
@Test
public void objectUnderTestInheritsCollectionOfCollaborators() {
// Given | // Path: mockito-collections-core/src/main/java/uk/co/webamoeba/mockito/collections/MockitoCollections.java
// public class MockitoCollections {
//
// private static Initialiser INITIALISER = new Initialiser();
//
// private static Verifier VERIFIER = new Verifier();
//
// /**
// * {@link Initialiser#initialise(Object)}
// *
// * @param object
// */
// public static void initialise(Object object) {
// INITIALISER.initialise(object);
// }
//
// /**
// * {@link Verifier#collectiveVerify(Class, Collection)}
// *
// * @param mockClass
// * @param collection
// * @return Object used for verification of all the mocks in the supplied collection
// */
// public static <T> T collectiveVerify(Class<T> mockClass, Collection<T> collection) {
// return VERIFIER.collectiveVerify(mockClass, collection);
// }
//
// /**
// * {@link Verifier#collectiveVerify(Class, Collection, VerificationMode)}
// *
// * @param mockClass
// * @param collection
// * @param mode
// * @return Object used for verification of all the mocks in the supplied collection
// */
// public static <T> T collectiveVerify(Class<T> mockClass, Collection<T> collection, VerificationMode mode) {
// return VERIFIER.collectiveVerify(mockClass, collection, mode);
// }
//
// /**
// * {@link Verifier#collectiveVerifyZeroInteractions(Collection...)}
// *
// * @param mocks
// */
// public static <T> void collectiveVerifyZeroInteractions(Collection<T>... mocks) {
// VERIFIER.collectiveVerifyZeroInteractions(mocks);
// }
//
// /**
// * {@link Verifier#collectiveVerifyNoMoreInteractions(Collection...)}
// *
// * @param mocks
// */
// public static <T> void collectiveVerifyNoMoreInteractions(Collection<T>... mocks) {
// VERIFIER.collectiveVerifyNoMoreInteractions(mocks);
// }
// }
//
// Path: mockito-collections-core-integration-tests/src/main/java/uk/co/webamoeba/mockito/collections/core/integrationtests/support/ClassWithInheritedCollectionOfCollaborators.java
// public class ClassWithInheritedCollectionOfCollaborators extends ClassWithCollectionOfCollaborators {
//
// }
// Path: mockito-collections-core-integration-tests/src/test/java/uk/co/webamoeba/mockito/collections/core/integrationtests/InjectCollectionsOfMocksIntoInheritedCollectionsStoryIntegrationTest.java
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertSame;
import static org.mockito.Mockito.mock;
import java.util.EventListener;
import java.util.Iterator;
import org.junit.Test;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import uk.co.webamoeba.mockito.collections.MockitoCollections;
import uk.co.webamoeba.mockito.collections.core.integrationtests.support.ClassWithInheritedCollectionOfCollaborators;
package uk.co.webamoeba.mockito.collections.core.integrationtests;
public class InjectCollectionsOfMocksIntoInheritedCollectionsStoryIntegrationTest implements
InjectCollectionsOfMocksIntoInheritedCollectionsStory {
@Test
public void objectUnderTestInheritsCollectionOfCollaborators() {
// Given | final ClassWithInheritedCollectionOfCollaborators outerObjectUnderTest = new ClassWithInheritedCollectionOfCollaborators(); |
jameskennard/mockito-collections | mockito-collections-core-integration-tests/src/test/java/uk/co/webamoeba/mockito/collections/core/integrationtests/InjectCollectionsOfMocksIntoInheritedCollectionsStoryIntegrationTest.java | // Path: mockito-collections-core/src/main/java/uk/co/webamoeba/mockito/collections/MockitoCollections.java
// public class MockitoCollections {
//
// private static Initialiser INITIALISER = new Initialiser();
//
// private static Verifier VERIFIER = new Verifier();
//
// /**
// * {@link Initialiser#initialise(Object)}
// *
// * @param object
// */
// public static void initialise(Object object) {
// INITIALISER.initialise(object);
// }
//
// /**
// * {@link Verifier#collectiveVerify(Class, Collection)}
// *
// * @param mockClass
// * @param collection
// * @return Object used for verification of all the mocks in the supplied collection
// */
// public static <T> T collectiveVerify(Class<T> mockClass, Collection<T> collection) {
// return VERIFIER.collectiveVerify(mockClass, collection);
// }
//
// /**
// * {@link Verifier#collectiveVerify(Class, Collection, VerificationMode)}
// *
// * @param mockClass
// * @param collection
// * @param mode
// * @return Object used for verification of all the mocks in the supplied collection
// */
// public static <T> T collectiveVerify(Class<T> mockClass, Collection<T> collection, VerificationMode mode) {
// return VERIFIER.collectiveVerify(mockClass, collection, mode);
// }
//
// /**
// * {@link Verifier#collectiveVerifyZeroInteractions(Collection...)}
// *
// * @param mocks
// */
// public static <T> void collectiveVerifyZeroInteractions(Collection<T>... mocks) {
// VERIFIER.collectiveVerifyZeroInteractions(mocks);
// }
//
// /**
// * {@link Verifier#collectiveVerifyNoMoreInteractions(Collection...)}
// *
// * @param mocks
// */
// public static <T> void collectiveVerifyNoMoreInteractions(Collection<T>... mocks) {
// VERIFIER.collectiveVerifyNoMoreInteractions(mocks);
// }
// }
//
// Path: mockito-collections-core-integration-tests/src/main/java/uk/co/webamoeba/mockito/collections/core/integrationtests/support/ClassWithInheritedCollectionOfCollaborators.java
// public class ClassWithInheritedCollectionOfCollaborators extends ClassWithCollectionOfCollaborators {
//
// }
| import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertSame;
import static org.mockito.Mockito.mock;
import java.util.EventListener;
import java.util.Iterator;
import org.junit.Test;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import uk.co.webamoeba.mockito.collections.MockitoCollections;
import uk.co.webamoeba.mockito.collections.core.integrationtests.support.ClassWithInheritedCollectionOfCollaborators; | package uk.co.webamoeba.mockito.collections.core.integrationtests;
public class InjectCollectionsOfMocksIntoInheritedCollectionsStoryIntegrationTest implements
InjectCollectionsOfMocksIntoInheritedCollectionsStory {
@Test
public void objectUnderTestInheritsCollectionOfCollaborators() {
// Given
final ClassWithInheritedCollectionOfCollaborators outerObjectUnderTest = new ClassWithInheritedCollectionOfCollaborators();
final EventListener outerCollaborator1 = mock(EventListener.class);
final EventListener outerCollaborator2 = mock(EventListener.class);
@SuppressWarnings("unused")
Object exampleTest = new Object() {
@InjectMocks
private ClassWithInheritedCollectionOfCollaborators objectUnderTest = outerObjectUnderTest;
@Mock
private EventListener collaborator1 = outerCollaborator1;
@Mock
private EventListener collaborator2 = outerCollaborator2;
};
// When | // Path: mockito-collections-core/src/main/java/uk/co/webamoeba/mockito/collections/MockitoCollections.java
// public class MockitoCollections {
//
// private static Initialiser INITIALISER = new Initialiser();
//
// private static Verifier VERIFIER = new Verifier();
//
// /**
// * {@link Initialiser#initialise(Object)}
// *
// * @param object
// */
// public static void initialise(Object object) {
// INITIALISER.initialise(object);
// }
//
// /**
// * {@link Verifier#collectiveVerify(Class, Collection)}
// *
// * @param mockClass
// * @param collection
// * @return Object used for verification of all the mocks in the supplied collection
// */
// public static <T> T collectiveVerify(Class<T> mockClass, Collection<T> collection) {
// return VERIFIER.collectiveVerify(mockClass, collection);
// }
//
// /**
// * {@link Verifier#collectiveVerify(Class, Collection, VerificationMode)}
// *
// * @param mockClass
// * @param collection
// * @param mode
// * @return Object used for verification of all the mocks in the supplied collection
// */
// public static <T> T collectiveVerify(Class<T> mockClass, Collection<T> collection, VerificationMode mode) {
// return VERIFIER.collectiveVerify(mockClass, collection, mode);
// }
//
// /**
// * {@link Verifier#collectiveVerifyZeroInteractions(Collection...)}
// *
// * @param mocks
// */
// public static <T> void collectiveVerifyZeroInteractions(Collection<T>... mocks) {
// VERIFIER.collectiveVerifyZeroInteractions(mocks);
// }
//
// /**
// * {@link Verifier#collectiveVerifyNoMoreInteractions(Collection...)}
// *
// * @param mocks
// */
// public static <T> void collectiveVerifyNoMoreInteractions(Collection<T>... mocks) {
// VERIFIER.collectiveVerifyNoMoreInteractions(mocks);
// }
// }
//
// Path: mockito-collections-core-integration-tests/src/main/java/uk/co/webamoeba/mockito/collections/core/integrationtests/support/ClassWithInheritedCollectionOfCollaborators.java
// public class ClassWithInheritedCollectionOfCollaborators extends ClassWithCollectionOfCollaborators {
//
// }
// Path: mockito-collections-core-integration-tests/src/test/java/uk/co/webamoeba/mockito/collections/core/integrationtests/InjectCollectionsOfMocksIntoInheritedCollectionsStoryIntegrationTest.java
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertSame;
import static org.mockito.Mockito.mock;
import java.util.EventListener;
import java.util.Iterator;
import org.junit.Test;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import uk.co.webamoeba.mockito.collections.MockitoCollections;
import uk.co.webamoeba.mockito.collections.core.integrationtests.support.ClassWithInheritedCollectionOfCollaborators;
package uk.co.webamoeba.mockito.collections.core.integrationtests;
public class InjectCollectionsOfMocksIntoInheritedCollectionsStoryIntegrationTest implements
InjectCollectionsOfMocksIntoInheritedCollectionsStory {
@Test
public void objectUnderTestInheritsCollectionOfCollaborators() {
// Given
final ClassWithInheritedCollectionOfCollaborators outerObjectUnderTest = new ClassWithInheritedCollectionOfCollaborators();
final EventListener outerCollaborator1 = mock(EventListener.class);
final EventListener outerCollaborator2 = mock(EventListener.class);
@SuppressWarnings("unused")
Object exampleTest = new Object() {
@InjectMocks
private ClassWithInheritedCollectionOfCollaborators objectUnderTest = outerObjectUnderTest;
@Mock
private EventListener collaborator1 = outerCollaborator1;
@Mock
private EventListener collaborator2 = outerCollaborator2;
};
// When | MockitoCollections.initialise(exampleTest); |
jameskennard/mockito-collections | mockito-collections-core/src/test/java/uk/co/webamoeba/mockito/collections/internal/VerifierTest.java | // Path: mockito-collections-core/src/test/java/uk/co/webamoeba/mockito/collections/support/ThrowableCausedByMatcher.java
// public class ThrowableCausedByMatcher extends BaseMatcher<Throwable> {
//
// private Class<? extends Throwable> causedByClass;
//
// public ThrowableCausedByMatcher(Class<? extends Throwable> causedByClass) {
// super();
// this.causedByClass = causedByClass;
// }
//
// public boolean matches(Object object) {
// if (object == null) {
// return false;
// }
// if (!Throwable.class.isAssignableFrom(object.getClass())) {
// return false;
// }
// Throwable causedBy = ((Throwable) object).getCause();
// while (causedBy != null) {
// if (causedBy.getClass().equals(causedByClass)) {
// return true;
// }
// causedBy = causedBy.getCause();
// }
// return false;
// }
//
// public void describeTo(Description description) {
// description.appendText("throwable caused by " + causedByClass);
// }
//
// }
| import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.mockito.Mockito.mock;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.mockito.exceptions.verification.NoInteractionsWanted;
import org.mockito.exceptions.verification.WantedButNotInvoked;
import uk.co.webamoeba.mockito.collections.support.ThrowableCausedByMatcher; | package uk.co.webamoeba.mockito.collections.internal;
/**
* @author James Kennard
*/
public class VerifierTest {
private Verifier verification = new Verifier();
@Rule
public ExpectedException thrown = ExpectedException.none();
@Test
public void shouldCollectiveVerifyGivenWantedButNotInvoked() throws IOException {
// Given
Closeable mock = mock(Closeable.class);
Collection<Closeable> collection = Collections.singleton(mock);
| // Path: mockito-collections-core/src/test/java/uk/co/webamoeba/mockito/collections/support/ThrowableCausedByMatcher.java
// public class ThrowableCausedByMatcher extends BaseMatcher<Throwable> {
//
// private Class<? extends Throwable> causedByClass;
//
// public ThrowableCausedByMatcher(Class<? extends Throwable> causedByClass) {
// super();
// this.causedByClass = causedByClass;
// }
//
// public boolean matches(Object object) {
// if (object == null) {
// return false;
// }
// if (!Throwable.class.isAssignableFrom(object.getClass())) {
// return false;
// }
// Throwable causedBy = ((Throwable) object).getCause();
// while (causedBy != null) {
// if (causedBy.getClass().equals(causedByClass)) {
// return true;
// }
// causedBy = causedBy.getCause();
// }
// return false;
// }
//
// public void describeTo(Description description) {
// description.appendText("throwable caused by " + causedByClass);
// }
//
// }
// Path: mockito-collections-core/src/test/java/uk/co/webamoeba/mockito/collections/internal/VerifierTest.java
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.mockito.Mockito.mock;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.mockito.exceptions.verification.NoInteractionsWanted;
import org.mockito.exceptions.verification.WantedButNotInvoked;
import uk.co.webamoeba.mockito.collections.support.ThrowableCausedByMatcher;
package uk.co.webamoeba.mockito.collections.internal;
/**
* @author James Kennard
*/
public class VerifierTest {
private Verifier verification = new Verifier();
@Rule
public ExpectedException thrown = ExpectedException.none();
@Test
public void shouldCollectiveVerifyGivenWantedButNotInvoked() throws IOException {
// Given
Closeable mock = mock(Closeable.class);
Collection<Closeable> collection = Collections.singleton(mock);
| thrown.expect(new ThrowableCausedByMatcher(WantedButNotInvoked.class)); |
jameskennard/mockito-collections | mockito-collections-core/src/main/java/uk/co/webamoeba/mockito/collections/inject/DefaultMockSelectionStrategy.java | // Path: mockito-collections-core/src/main/java/uk/co/webamoeba/mockito/collections/util/OrderedSet.java
// public class OrderedSet<E> implements Set<E> {
//
// private LinkedHashSet<E> set;
//
// public OrderedSet() {
// this.set = new LinkedHashSet<E>();
// }
//
// public OrderedSet(Collection<E> set) {
// this.set = new LinkedHashSet<E>(set);
// }
//
// public OrderedSet(int initialCapacity) {
// this.set = new LinkedHashSet<E>(initialCapacity);
// }
//
// public Object[] toArray() {
// return set.toArray();
// }
//
// public boolean removeAll(Collection<?> c) {
// return set.removeAll(c);
// }
//
// public <T> T[] toArray(T[] a) {
// return set.toArray(a);
// }
//
// public Iterator<E> iterator() {
// return set.iterator();
// }
//
// public int size() {
// return set.size();
// }
//
// public boolean isEmpty() {
// return set.isEmpty();
// }
//
// public boolean contains(Object o) {
// return set.contains(o);
// }
//
// public boolean add(E o) {
// return set.add(o);
// }
//
// public boolean remove(Object o) {
// return set.remove(o);
// }
//
// public void clear() {
// set.clear();
// }
//
// @Override
// public Object clone() {
// return set.clone();
// }
//
// public boolean containsAll(Collection<?> c) {
// return set.containsAll(c);
// }
//
// public boolean addAll(Collection<? extends E> c) {
// return set.addAll(c);
// }
//
// public boolean retainAll(Collection<?> c) {
// return set.retainAll(c);
// }
//
// @Override
// public String toString() {
// return set.toString();
// }
//
// @Override
// public boolean equals(Object obj) {
// if (this == obj) {
// return true;
// }
// if (obj == null || !getClass().equals(obj.getClass())) {
// return false;
// }
// return set.equals(obj);
// }
//
// @Override
// public int hashCode() {
// return 31 * 1 + ((set == null) ? 0 : set.hashCode());
// }
// }
| import java.util.Collection;
import uk.co.webamoeba.mockito.collections.util.OrderedSet; | package uk.co.webamoeba.mockito.collections.inject;
/**
* The default implementation of {@link MockSelectionStrategy}.
*
* @author James Kennard
*/
public class DefaultMockSelectionStrategy implements MockSelectionStrategy {
@SuppressWarnings("unchecked") | // Path: mockito-collections-core/src/main/java/uk/co/webamoeba/mockito/collections/util/OrderedSet.java
// public class OrderedSet<E> implements Set<E> {
//
// private LinkedHashSet<E> set;
//
// public OrderedSet() {
// this.set = new LinkedHashSet<E>();
// }
//
// public OrderedSet(Collection<E> set) {
// this.set = new LinkedHashSet<E>(set);
// }
//
// public OrderedSet(int initialCapacity) {
// this.set = new LinkedHashSet<E>(initialCapacity);
// }
//
// public Object[] toArray() {
// return set.toArray();
// }
//
// public boolean removeAll(Collection<?> c) {
// return set.removeAll(c);
// }
//
// public <T> T[] toArray(T[] a) {
// return set.toArray(a);
// }
//
// public Iterator<E> iterator() {
// return set.iterator();
// }
//
// public int size() {
// return set.size();
// }
//
// public boolean isEmpty() {
// return set.isEmpty();
// }
//
// public boolean contains(Object o) {
// return set.contains(o);
// }
//
// public boolean add(E o) {
// return set.add(o);
// }
//
// public boolean remove(Object o) {
// return set.remove(o);
// }
//
// public void clear() {
// set.clear();
// }
//
// @Override
// public Object clone() {
// return set.clone();
// }
//
// public boolean containsAll(Collection<?> c) {
// return set.containsAll(c);
// }
//
// public boolean addAll(Collection<? extends E> c) {
// return set.addAll(c);
// }
//
// public boolean retainAll(Collection<?> c) {
// return set.retainAll(c);
// }
//
// @Override
// public String toString() {
// return set.toString();
// }
//
// @Override
// public boolean equals(Object obj) {
// if (this == obj) {
// return true;
// }
// if (obj == null || !getClass().equals(obj.getClass())) {
// return false;
// }
// return set.equals(obj);
// }
//
// @Override
// public int hashCode() {
// return 31 * 1 + ((set == null) ? 0 : set.hashCode());
// }
// }
// Path: mockito-collections-core/src/main/java/uk/co/webamoeba/mockito/collections/inject/DefaultMockSelectionStrategy.java
import java.util.Collection;
import uk.co.webamoeba.mockito.collections.util.OrderedSet;
package uk.co.webamoeba.mockito.collections.inject;
/**
* The default implementation of {@link MockSelectionStrategy}.
*
* @author James Kennard
*/
public class DefaultMockSelectionStrategy implements MockSelectionStrategy {
@SuppressWarnings("unchecked") | public <T> OrderedSet<T> selectMocks(OrderedSet<Object> mocks, Class<T> mockClass) { |
jameskennard/mockito-collections | mockito-collections-core-integration-tests/src/test/java/uk/co/webamoeba/mockito/collections/core/integrationtests/InjectCollectionOfInheritedMocksStoryIntegrationTest.java | // Path: mockito-collections-core/src/main/java/uk/co/webamoeba/mockito/collections/MockitoCollections.java
// public class MockitoCollections {
//
// private static Initialiser INITIALISER = new Initialiser();
//
// private static Verifier VERIFIER = new Verifier();
//
// /**
// * {@link Initialiser#initialise(Object)}
// *
// * @param object
// */
// public static void initialise(Object object) {
// INITIALISER.initialise(object);
// }
//
// /**
// * {@link Verifier#collectiveVerify(Class, Collection)}
// *
// * @param mockClass
// * @param collection
// * @return Object used for verification of all the mocks in the supplied collection
// */
// public static <T> T collectiveVerify(Class<T> mockClass, Collection<T> collection) {
// return VERIFIER.collectiveVerify(mockClass, collection);
// }
//
// /**
// * {@link Verifier#collectiveVerify(Class, Collection, VerificationMode)}
// *
// * @param mockClass
// * @param collection
// * @param mode
// * @return Object used for verification of all the mocks in the supplied collection
// */
// public static <T> T collectiveVerify(Class<T> mockClass, Collection<T> collection, VerificationMode mode) {
// return VERIFIER.collectiveVerify(mockClass, collection, mode);
// }
//
// /**
// * {@link Verifier#collectiveVerifyZeroInteractions(Collection...)}
// *
// * @param mocks
// */
// public static <T> void collectiveVerifyZeroInteractions(Collection<T>... mocks) {
// VERIFIER.collectiveVerifyZeroInteractions(mocks);
// }
//
// /**
// * {@link Verifier#collectiveVerifyNoMoreInteractions(Collection...)}
// *
// * @param mocks
// */
// public static <T> void collectiveVerifyNoMoreInteractions(Collection<T>... mocks) {
// VERIFIER.collectiveVerifyNoMoreInteractions(mocks);
// }
// }
//
// Path: mockito-collections-core-integration-tests/src/main/java/uk/co/webamoeba/mockito/collections/core/integrationtests/support/ClassWithCollectionOfCollaborators.java
// public class ClassWithCollectionOfCollaborators implements HasCollaborators<EventListener> {
//
// private Collection<EventListener> collaborators;
//
// public Collection<EventListener> getCollaborators() {
// return collaborators;
// }
// }
| import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertSame;
import static org.mockito.Mockito.mock;
import java.util.EventListener;
import java.util.Iterator;
import org.junit.Test;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import uk.co.webamoeba.mockito.collections.MockitoCollections;
import uk.co.webamoeba.mockito.collections.core.integrationtests.support.ClassWithCollectionOfCollaborators; | package uk.co.webamoeba.mockito.collections.core.integrationtests;
public class InjectCollectionOfInheritedMocksStoryIntegrationTest implements
InjectCollectionOfInheritedMocksStory {
@Test
public void testClassInheritsSomeMocksFromAParentTestClass() {
// Given | // Path: mockito-collections-core/src/main/java/uk/co/webamoeba/mockito/collections/MockitoCollections.java
// public class MockitoCollections {
//
// private static Initialiser INITIALISER = new Initialiser();
//
// private static Verifier VERIFIER = new Verifier();
//
// /**
// * {@link Initialiser#initialise(Object)}
// *
// * @param object
// */
// public static void initialise(Object object) {
// INITIALISER.initialise(object);
// }
//
// /**
// * {@link Verifier#collectiveVerify(Class, Collection)}
// *
// * @param mockClass
// * @param collection
// * @return Object used for verification of all the mocks in the supplied collection
// */
// public static <T> T collectiveVerify(Class<T> mockClass, Collection<T> collection) {
// return VERIFIER.collectiveVerify(mockClass, collection);
// }
//
// /**
// * {@link Verifier#collectiveVerify(Class, Collection, VerificationMode)}
// *
// * @param mockClass
// * @param collection
// * @param mode
// * @return Object used for verification of all the mocks in the supplied collection
// */
// public static <T> T collectiveVerify(Class<T> mockClass, Collection<T> collection, VerificationMode mode) {
// return VERIFIER.collectiveVerify(mockClass, collection, mode);
// }
//
// /**
// * {@link Verifier#collectiveVerifyZeroInteractions(Collection...)}
// *
// * @param mocks
// */
// public static <T> void collectiveVerifyZeroInteractions(Collection<T>... mocks) {
// VERIFIER.collectiveVerifyZeroInteractions(mocks);
// }
//
// /**
// * {@link Verifier#collectiveVerifyNoMoreInteractions(Collection...)}
// *
// * @param mocks
// */
// public static <T> void collectiveVerifyNoMoreInteractions(Collection<T>... mocks) {
// VERIFIER.collectiveVerifyNoMoreInteractions(mocks);
// }
// }
//
// Path: mockito-collections-core-integration-tests/src/main/java/uk/co/webamoeba/mockito/collections/core/integrationtests/support/ClassWithCollectionOfCollaborators.java
// public class ClassWithCollectionOfCollaborators implements HasCollaborators<EventListener> {
//
// private Collection<EventListener> collaborators;
//
// public Collection<EventListener> getCollaborators() {
// return collaborators;
// }
// }
// Path: mockito-collections-core-integration-tests/src/test/java/uk/co/webamoeba/mockito/collections/core/integrationtests/InjectCollectionOfInheritedMocksStoryIntegrationTest.java
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertSame;
import static org.mockito.Mockito.mock;
import java.util.EventListener;
import java.util.Iterator;
import org.junit.Test;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import uk.co.webamoeba.mockito.collections.MockitoCollections;
import uk.co.webamoeba.mockito.collections.core.integrationtests.support.ClassWithCollectionOfCollaborators;
package uk.co.webamoeba.mockito.collections.core.integrationtests;
public class InjectCollectionOfInheritedMocksStoryIntegrationTest implements
InjectCollectionOfInheritedMocksStory {
@Test
public void testClassInheritsSomeMocksFromAParentTestClass() {
// Given | final ClassWithCollectionOfCollaborators outerCUT = new ClassWithCollectionOfCollaborators(); |
jameskennard/mockito-collections | mockito-collections-core-integration-tests/src/test/java/uk/co/webamoeba/mockito/collections/core/integrationtests/InjectCollectionOfInheritedMocksStoryIntegrationTest.java | // Path: mockito-collections-core/src/main/java/uk/co/webamoeba/mockito/collections/MockitoCollections.java
// public class MockitoCollections {
//
// private static Initialiser INITIALISER = new Initialiser();
//
// private static Verifier VERIFIER = new Verifier();
//
// /**
// * {@link Initialiser#initialise(Object)}
// *
// * @param object
// */
// public static void initialise(Object object) {
// INITIALISER.initialise(object);
// }
//
// /**
// * {@link Verifier#collectiveVerify(Class, Collection)}
// *
// * @param mockClass
// * @param collection
// * @return Object used for verification of all the mocks in the supplied collection
// */
// public static <T> T collectiveVerify(Class<T> mockClass, Collection<T> collection) {
// return VERIFIER.collectiveVerify(mockClass, collection);
// }
//
// /**
// * {@link Verifier#collectiveVerify(Class, Collection, VerificationMode)}
// *
// * @param mockClass
// * @param collection
// * @param mode
// * @return Object used for verification of all the mocks in the supplied collection
// */
// public static <T> T collectiveVerify(Class<T> mockClass, Collection<T> collection, VerificationMode mode) {
// return VERIFIER.collectiveVerify(mockClass, collection, mode);
// }
//
// /**
// * {@link Verifier#collectiveVerifyZeroInteractions(Collection...)}
// *
// * @param mocks
// */
// public static <T> void collectiveVerifyZeroInteractions(Collection<T>... mocks) {
// VERIFIER.collectiveVerifyZeroInteractions(mocks);
// }
//
// /**
// * {@link Verifier#collectiveVerifyNoMoreInteractions(Collection...)}
// *
// * @param mocks
// */
// public static <T> void collectiveVerifyNoMoreInteractions(Collection<T>... mocks) {
// VERIFIER.collectiveVerifyNoMoreInteractions(mocks);
// }
// }
//
// Path: mockito-collections-core-integration-tests/src/main/java/uk/co/webamoeba/mockito/collections/core/integrationtests/support/ClassWithCollectionOfCollaborators.java
// public class ClassWithCollectionOfCollaborators implements HasCollaborators<EventListener> {
//
// private Collection<EventListener> collaborators;
//
// public Collection<EventListener> getCollaborators() {
// return collaborators;
// }
// }
| import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertSame;
import static org.mockito.Mockito.mock;
import java.util.EventListener;
import java.util.Iterator;
import org.junit.Test;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import uk.co.webamoeba.mockito.collections.MockitoCollections;
import uk.co.webamoeba.mockito.collections.core.integrationtests.support.ClassWithCollectionOfCollaborators; | package uk.co.webamoeba.mockito.collections.core.integrationtests;
public class InjectCollectionOfInheritedMocksStoryIntegrationTest implements
InjectCollectionOfInheritedMocksStory {
@Test
public void testClassInheritsSomeMocksFromAParentTestClass() {
// Given
final ClassWithCollectionOfCollaborators outerCUT = new ClassWithCollectionOfCollaborators();
final EventListener outerCollaborator2 = mock(EventListener.class);
final EventListener outerCollaborator4 = mock(EventListener.class);
@SuppressWarnings("unused")
BaseExampleTest exampleTest = new BaseExampleTest() {
@InjectMocks
private ClassWithCollectionOfCollaborators cut = outerCUT;
@Mock
private EventListener collaborator2 = outerCollaborator2;
@Mock
private EventListener collaborator4 = outerCollaborator4;
};
// When | // Path: mockito-collections-core/src/main/java/uk/co/webamoeba/mockito/collections/MockitoCollections.java
// public class MockitoCollections {
//
// private static Initialiser INITIALISER = new Initialiser();
//
// private static Verifier VERIFIER = new Verifier();
//
// /**
// * {@link Initialiser#initialise(Object)}
// *
// * @param object
// */
// public static void initialise(Object object) {
// INITIALISER.initialise(object);
// }
//
// /**
// * {@link Verifier#collectiveVerify(Class, Collection)}
// *
// * @param mockClass
// * @param collection
// * @return Object used for verification of all the mocks in the supplied collection
// */
// public static <T> T collectiveVerify(Class<T> mockClass, Collection<T> collection) {
// return VERIFIER.collectiveVerify(mockClass, collection);
// }
//
// /**
// * {@link Verifier#collectiveVerify(Class, Collection, VerificationMode)}
// *
// * @param mockClass
// * @param collection
// * @param mode
// * @return Object used for verification of all the mocks in the supplied collection
// */
// public static <T> T collectiveVerify(Class<T> mockClass, Collection<T> collection, VerificationMode mode) {
// return VERIFIER.collectiveVerify(mockClass, collection, mode);
// }
//
// /**
// * {@link Verifier#collectiveVerifyZeroInteractions(Collection...)}
// *
// * @param mocks
// */
// public static <T> void collectiveVerifyZeroInteractions(Collection<T>... mocks) {
// VERIFIER.collectiveVerifyZeroInteractions(mocks);
// }
//
// /**
// * {@link Verifier#collectiveVerifyNoMoreInteractions(Collection...)}
// *
// * @param mocks
// */
// public static <T> void collectiveVerifyNoMoreInteractions(Collection<T>... mocks) {
// VERIFIER.collectiveVerifyNoMoreInteractions(mocks);
// }
// }
//
// Path: mockito-collections-core-integration-tests/src/main/java/uk/co/webamoeba/mockito/collections/core/integrationtests/support/ClassWithCollectionOfCollaborators.java
// public class ClassWithCollectionOfCollaborators implements HasCollaborators<EventListener> {
//
// private Collection<EventListener> collaborators;
//
// public Collection<EventListener> getCollaborators() {
// return collaborators;
// }
// }
// Path: mockito-collections-core-integration-tests/src/test/java/uk/co/webamoeba/mockito/collections/core/integrationtests/InjectCollectionOfInheritedMocksStoryIntegrationTest.java
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertSame;
import static org.mockito.Mockito.mock;
import java.util.EventListener;
import java.util.Iterator;
import org.junit.Test;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import uk.co.webamoeba.mockito.collections.MockitoCollections;
import uk.co.webamoeba.mockito.collections.core.integrationtests.support.ClassWithCollectionOfCollaborators;
package uk.co.webamoeba.mockito.collections.core.integrationtests;
public class InjectCollectionOfInheritedMocksStoryIntegrationTest implements
InjectCollectionOfInheritedMocksStory {
@Test
public void testClassInheritsSomeMocksFromAParentTestClass() {
// Given
final ClassWithCollectionOfCollaborators outerCUT = new ClassWithCollectionOfCollaborators();
final EventListener outerCollaborator2 = mock(EventListener.class);
final EventListener outerCollaborator4 = mock(EventListener.class);
@SuppressWarnings("unused")
BaseExampleTest exampleTest = new BaseExampleTest() {
@InjectMocks
private ClassWithCollectionOfCollaborators cut = outerCUT;
@Mock
private EventListener collaborator2 = outerCollaborator2;
@Mock
private EventListener collaborator4 = outerCollaborator4;
};
// When | MockitoCollections.initialise(exampleTest); |
jameskennard/mockito-collections | mockito-collections-samples/src/test/java/uk/co/webamoeba/mockito/collections/sample/ListenerManagerAlternativeTest.java | // Path: mockito-collections-core/src/main/java/uk/co/webamoeba/mockito/collections/MockitoCollections.java
// public class MockitoCollections {
//
// private static Initialiser INITIALISER = new Initialiser();
//
// private static Verifier VERIFIER = new Verifier();
//
// /**
// * {@link Initialiser#initialise(Object)}
// *
// * @param object
// */
// public static void initialise(Object object) {
// INITIALISER.initialise(object);
// }
//
// /**
// * {@link Verifier#collectiveVerify(Class, Collection)}
// *
// * @param mockClass
// * @param collection
// * @return Object used for verification of all the mocks in the supplied collection
// */
// public static <T> T collectiveVerify(Class<T> mockClass, Collection<T> collection) {
// return VERIFIER.collectiveVerify(mockClass, collection);
// }
//
// /**
// * {@link Verifier#collectiveVerify(Class, Collection, VerificationMode)}
// *
// * @param mockClass
// * @param collection
// * @param mode
// * @return Object used for verification of all the mocks in the supplied collection
// */
// public static <T> T collectiveVerify(Class<T> mockClass, Collection<T> collection, VerificationMode mode) {
// return VERIFIER.collectiveVerify(mockClass, collection, mode);
// }
//
// /**
// * {@link Verifier#collectiveVerifyZeroInteractions(Collection...)}
// *
// * @param mocks
// */
// public static <T> void collectiveVerifyZeroInteractions(Collection<T>... mocks) {
// VERIFIER.collectiveVerifyZeroInteractions(mocks);
// }
//
// /**
// * {@link Verifier#collectiveVerifyNoMoreInteractions(Collection...)}
// *
// * @param mocks
// */
// public static <T> void collectiveVerifyNoMoreInteractions(Collection<T>... mocks) {
// VERIFIER.collectiveVerifyNoMoreInteractions(mocks);
// }
// }
| import java.util.Collection;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.runners.MockitoJUnitRunner;
import uk.co.webamoeba.mockito.collections.MockitoCollections;
import uk.co.webamoeba.mockito.collections.annotation.CollectionOfMocks; | package uk.co.webamoeba.mockito.collections.sample;
/**
* This test shows how you can use Mockito Collections to test where there is a {@link Collection} of delegates that do
* not return values. Comments are included throughout the file to hellp clarify what's going on.
*
* @author James Kennard
*/
@RunWith(MockitoJUnitRunner.class)
public class ListenerManagerAlternativeTest {
// ListenerManager containing a Collection of SampleListeners
@InjectMocks
private ListenerManager manager;
// A Collection of two Mocks
@CollectionOfMocks(numberOfMocks = 2)
private Collection<Listener> listeners;
// Setup making use of Mockito Collections for injection of handlers
@Before
public void before() { | // Path: mockito-collections-core/src/main/java/uk/co/webamoeba/mockito/collections/MockitoCollections.java
// public class MockitoCollections {
//
// private static Initialiser INITIALISER = new Initialiser();
//
// private static Verifier VERIFIER = new Verifier();
//
// /**
// * {@link Initialiser#initialise(Object)}
// *
// * @param object
// */
// public static void initialise(Object object) {
// INITIALISER.initialise(object);
// }
//
// /**
// * {@link Verifier#collectiveVerify(Class, Collection)}
// *
// * @param mockClass
// * @param collection
// * @return Object used for verification of all the mocks in the supplied collection
// */
// public static <T> T collectiveVerify(Class<T> mockClass, Collection<T> collection) {
// return VERIFIER.collectiveVerify(mockClass, collection);
// }
//
// /**
// * {@link Verifier#collectiveVerify(Class, Collection, VerificationMode)}
// *
// * @param mockClass
// * @param collection
// * @param mode
// * @return Object used for verification of all the mocks in the supplied collection
// */
// public static <T> T collectiveVerify(Class<T> mockClass, Collection<T> collection, VerificationMode mode) {
// return VERIFIER.collectiveVerify(mockClass, collection, mode);
// }
//
// /**
// * {@link Verifier#collectiveVerifyZeroInteractions(Collection...)}
// *
// * @param mocks
// */
// public static <T> void collectiveVerifyZeroInteractions(Collection<T>... mocks) {
// VERIFIER.collectiveVerifyZeroInteractions(mocks);
// }
//
// /**
// * {@link Verifier#collectiveVerifyNoMoreInteractions(Collection...)}
// *
// * @param mocks
// */
// public static <T> void collectiveVerifyNoMoreInteractions(Collection<T>... mocks) {
// VERIFIER.collectiveVerifyNoMoreInteractions(mocks);
// }
// }
// Path: mockito-collections-samples/src/test/java/uk/co/webamoeba/mockito/collections/sample/ListenerManagerAlternativeTest.java
import java.util.Collection;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.runners.MockitoJUnitRunner;
import uk.co.webamoeba.mockito.collections.MockitoCollections;
import uk.co.webamoeba.mockito.collections.annotation.CollectionOfMocks;
package uk.co.webamoeba.mockito.collections.sample;
/**
* This test shows how you can use Mockito Collections to test where there is a {@link Collection} of delegates that do
* not return values. Comments are included throughout the file to hellp clarify what's going on.
*
* @author James Kennard
*/
@RunWith(MockitoJUnitRunner.class)
public class ListenerManagerAlternativeTest {
// ListenerManager containing a Collection of SampleListeners
@InjectMocks
private ListenerManager manager;
// A Collection of two Mocks
@CollectionOfMocks(numberOfMocks = 2)
private Collection<Listener> listeners;
// Setup making use of Mockito Collections for injection of handlers
@Before
public void before() { | MockitoCollections.initialise(this); |
jameskennard/mockito-collections | mockito-collections-core/src/test/java/uk/co/webamoeba/mockito/collections/inject/DefaultMockSelectionStrategyTest.java | // Path: mockito-collections-core/src/main/java/uk/co/webamoeba/mockito/collections/util/OrderedSet.java
// public class OrderedSet<E> implements Set<E> {
//
// private LinkedHashSet<E> set;
//
// public OrderedSet() {
// this.set = new LinkedHashSet<E>();
// }
//
// public OrderedSet(Collection<E> set) {
// this.set = new LinkedHashSet<E>(set);
// }
//
// public OrderedSet(int initialCapacity) {
// this.set = new LinkedHashSet<E>(initialCapacity);
// }
//
// public Object[] toArray() {
// return set.toArray();
// }
//
// public boolean removeAll(Collection<?> c) {
// return set.removeAll(c);
// }
//
// public <T> T[] toArray(T[] a) {
// return set.toArray(a);
// }
//
// public Iterator<E> iterator() {
// return set.iterator();
// }
//
// public int size() {
// return set.size();
// }
//
// public boolean isEmpty() {
// return set.isEmpty();
// }
//
// public boolean contains(Object o) {
// return set.contains(o);
// }
//
// public boolean add(E o) {
// return set.add(o);
// }
//
// public boolean remove(Object o) {
// return set.remove(o);
// }
//
// public void clear() {
// set.clear();
// }
//
// @Override
// public Object clone() {
// return set.clone();
// }
//
// public boolean containsAll(Collection<?> c) {
// return set.containsAll(c);
// }
//
// public boolean addAll(Collection<? extends E> c) {
// return set.addAll(c);
// }
//
// public boolean retainAll(Collection<?> c) {
// return set.retainAll(c);
// }
//
// @Override
// public String toString() {
// return set.toString();
// }
//
// @Override
// public boolean equals(Object obj) {
// if (this == obj) {
// return true;
// }
// if (obj == null || !getClass().equals(obj.getClass())) {
// return false;
// }
// return set.equals(obj);
// }
//
// @Override
// public int hashCode() {
// return 31 * 1 + ((set == null) ? 0 : set.hashCode());
// }
// }
| import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.mock;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.EventListener;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.TreeSet;
import org.junit.Test;
import uk.co.webamoeba.mockito.collections.util.OrderedSet; | package uk.co.webamoeba.mockito.collections.inject;
/**
* @author James Kennard
*/
public class DefaultMockSelectionStrategyTest {
private DefaultMockSelectionStrategy strategy = new DefaultMockSelectionStrategy();
@Test
public void shouldGetMocks() {
// Given
InputStream mock1 = mock(InputStream.class);
OutputStream mock2 = mock(OutputStream.class);
InputStream mock3 = mock(FileInputStream.class); | // Path: mockito-collections-core/src/main/java/uk/co/webamoeba/mockito/collections/util/OrderedSet.java
// public class OrderedSet<E> implements Set<E> {
//
// private LinkedHashSet<E> set;
//
// public OrderedSet() {
// this.set = new LinkedHashSet<E>();
// }
//
// public OrderedSet(Collection<E> set) {
// this.set = new LinkedHashSet<E>(set);
// }
//
// public OrderedSet(int initialCapacity) {
// this.set = new LinkedHashSet<E>(initialCapacity);
// }
//
// public Object[] toArray() {
// return set.toArray();
// }
//
// public boolean removeAll(Collection<?> c) {
// return set.removeAll(c);
// }
//
// public <T> T[] toArray(T[] a) {
// return set.toArray(a);
// }
//
// public Iterator<E> iterator() {
// return set.iterator();
// }
//
// public int size() {
// return set.size();
// }
//
// public boolean isEmpty() {
// return set.isEmpty();
// }
//
// public boolean contains(Object o) {
// return set.contains(o);
// }
//
// public boolean add(E o) {
// return set.add(o);
// }
//
// public boolean remove(Object o) {
// return set.remove(o);
// }
//
// public void clear() {
// set.clear();
// }
//
// @Override
// public Object clone() {
// return set.clone();
// }
//
// public boolean containsAll(Collection<?> c) {
// return set.containsAll(c);
// }
//
// public boolean addAll(Collection<? extends E> c) {
// return set.addAll(c);
// }
//
// public boolean retainAll(Collection<?> c) {
// return set.retainAll(c);
// }
//
// @Override
// public String toString() {
// return set.toString();
// }
//
// @Override
// public boolean equals(Object obj) {
// if (this == obj) {
// return true;
// }
// if (obj == null || !getClass().equals(obj.getClass())) {
// return false;
// }
// return set.equals(obj);
// }
//
// @Override
// public int hashCode() {
// return 31 * 1 + ((set == null) ? 0 : set.hashCode());
// }
// }
// Path: mockito-collections-core/src/test/java/uk/co/webamoeba/mockito/collections/inject/DefaultMockSelectionStrategyTest.java
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.mock;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.EventListener;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.TreeSet;
import org.junit.Test;
import uk.co.webamoeba.mockito.collections.util.OrderedSet;
package uk.co.webamoeba.mockito.collections.inject;
/**
* @author James Kennard
*/
public class DefaultMockSelectionStrategyTest {
private DefaultMockSelectionStrategy strategy = new DefaultMockSelectionStrategy();
@Test
public void shouldGetMocks() {
// Given
InputStream mock1 = mock(InputStream.class);
OutputStream mock2 = mock(OutputStream.class);
InputStream mock3 = mock(FileInputStream.class); | OrderedSet<Object> mocks = new OrderedSet<Object>(Arrays.<Object> asList(mock1, mock2, mock3)); |
jameskennard/mockito-collections | mockito-collections-core-integration-tests/src/test/java/uk/co/webamoeba/mockito/collections/core/integrationtests/InjectCollectionOfMocksAnnotatedFieldsStoryIntegrationTest.java | // Path: mockito-collections-core/src/main/java/uk/co/webamoeba/mockito/collections/MockitoCollections.java
// public class MockitoCollections {
//
// private static Initialiser INITIALISER = new Initialiser();
//
// private static Verifier VERIFIER = new Verifier();
//
// /**
// * {@link Initialiser#initialise(Object)}
// *
// * @param object
// */
// public static void initialise(Object object) {
// INITIALISER.initialise(object);
// }
//
// /**
// * {@link Verifier#collectiveVerify(Class, Collection)}
// *
// * @param mockClass
// * @param collection
// * @return Object used for verification of all the mocks in the supplied collection
// */
// public static <T> T collectiveVerify(Class<T> mockClass, Collection<T> collection) {
// return VERIFIER.collectiveVerify(mockClass, collection);
// }
//
// /**
// * {@link Verifier#collectiveVerify(Class, Collection, VerificationMode)}
// *
// * @param mockClass
// * @param collection
// * @param mode
// * @return Object used for verification of all the mocks in the supplied collection
// */
// public static <T> T collectiveVerify(Class<T> mockClass, Collection<T> collection, VerificationMode mode) {
// return VERIFIER.collectiveVerify(mockClass, collection, mode);
// }
//
// /**
// * {@link Verifier#collectiveVerifyZeroInteractions(Collection...)}
// *
// * @param mocks
// */
// public static <T> void collectiveVerifyZeroInteractions(Collection<T>... mocks) {
// VERIFIER.collectiveVerifyZeroInteractions(mocks);
// }
//
// /**
// * {@link Verifier#collectiveVerifyNoMoreInteractions(Collection...)}
// *
// * @param mocks
// */
// public static <T> void collectiveVerifyNoMoreInteractions(Collection<T>... mocks) {
// VERIFIER.collectiveVerifyNoMoreInteractions(mocks);
// }
// }
//
// Path: mockito-collections-core-integration-tests/src/main/java/uk/co/webamoeba/mockito/collections/core/integrationtests/support/ClassWithCollectionOfCollaborators.java
// public class ClassWithCollectionOfCollaborators implements HasCollaborators<EventListener> {
//
// private Collection<EventListener> collaborators;
//
// public Collection<EventListener> getCollaborators() {
// return collaborators;
// }
// }
| import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import java.util.Collection;
import java.util.EventListener;
import org.junit.Test;
import org.mockito.InjectMocks;
import org.mockito.internal.util.MockUtil;
import uk.co.webamoeba.mockito.collections.MockitoCollections;
import uk.co.webamoeba.mockito.collections.annotation.CollectionOfMocks;
import uk.co.webamoeba.mockito.collections.core.integrationtests.support.ClassWithCollectionOfCollaborators; | package uk.co.webamoeba.mockito.collections.core.integrationtests;
public class InjectCollectionOfMocksAnnotatedFieldsStoryIntegrationTest implements
InjectCollectionOfMocksAnnotatedFieldsStory {
@Test
public void objectUnderTestHasCollectionOfCollaborators() {
// Given
ExampleTest test = new ExampleTest(); | // Path: mockito-collections-core/src/main/java/uk/co/webamoeba/mockito/collections/MockitoCollections.java
// public class MockitoCollections {
//
// private static Initialiser INITIALISER = new Initialiser();
//
// private static Verifier VERIFIER = new Verifier();
//
// /**
// * {@link Initialiser#initialise(Object)}
// *
// * @param object
// */
// public static void initialise(Object object) {
// INITIALISER.initialise(object);
// }
//
// /**
// * {@link Verifier#collectiveVerify(Class, Collection)}
// *
// * @param mockClass
// * @param collection
// * @return Object used for verification of all the mocks in the supplied collection
// */
// public static <T> T collectiveVerify(Class<T> mockClass, Collection<T> collection) {
// return VERIFIER.collectiveVerify(mockClass, collection);
// }
//
// /**
// * {@link Verifier#collectiveVerify(Class, Collection, VerificationMode)}
// *
// * @param mockClass
// * @param collection
// * @param mode
// * @return Object used for verification of all the mocks in the supplied collection
// */
// public static <T> T collectiveVerify(Class<T> mockClass, Collection<T> collection, VerificationMode mode) {
// return VERIFIER.collectiveVerify(mockClass, collection, mode);
// }
//
// /**
// * {@link Verifier#collectiveVerifyZeroInteractions(Collection...)}
// *
// * @param mocks
// */
// public static <T> void collectiveVerifyZeroInteractions(Collection<T>... mocks) {
// VERIFIER.collectiveVerifyZeroInteractions(mocks);
// }
//
// /**
// * {@link Verifier#collectiveVerifyNoMoreInteractions(Collection...)}
// *
// * @param mocks
// */
// public static <T> void collectiveVerifyNoMoreInteractions(Collection<T>... mocks) {
// VERIFIER.collectiveVerifyNoMoreInteractions(mocks);
// }
// }
//
// Path: mockito-collections-core-integration-tests/src/main/java/uk/co/webamoeba/mockito/collections/core/integrationtests/support/ClassWithCollectionOfCollaborators.java
// public class ClassWithCollectionOfCollaborators implements HasCollaborators<EventListener> {
//
// private Collection<EventListener> collaborators;
//
// public Collection<EventListener> getCollaborators() {
// return collaborators;
// }
// }
// Path: mockito-collections-core-integration-tests/src/test/java/uk/co/webamoeba/mockito/collections/core/integrationtests/InjectCollectionOfMocksAnnotatedFieldsStoryIntegrationTest.java
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import java.util.Collection;
import java.util.EventListener;
import org.junit.Test;
import org.mockito.InjectMocks;
import org.mockito.internal.util.MockUtil;
import uk.co.webamoeba.mockito.collections.MockitoCollections;
import uk.co.webamoeba.mockito.collections.annotation.CollectionOfMocks;
import uk.co.webamoeba.mockito.collections.core.integrationtests.support.ClassWithCollectionOfCollaborators;
package uk.co.webamoeba.mockito.collections.core.integrationtests;
public class InjectCollectionOfMocksAnnotatedFieldsStoryIntegrationTest implements
InjectCollectionOfMocksAnnotatedFieldsStory {
@Test
public void objectUnderTestHasCollectionOfCollaborators() {
// Given
ExampleTest test = new ExampleTest(); | test.objectUnderTest = new ClassWithCollectionOfCollaborators(); |
jameskennard/mockito-collections | mockito-collections-core-integration-tests/src/test/java/uk/co/webamoeba/mockito/collections/core/integrationtests/InjectCollectionOfMocksAnnotatedFieldsStoryIntegrationTest.java | // Path: mockito-collections-core/src/main/java/uk/co/webamoeba/mockito/collections/MockitoCollections.java
// public class MockitoCollections {
//
// private static Initialiser INITIALISER = new Initialiser();
//
// private static Verifier VERIFIER = new Verifier();
//
// /**
// * {@link Initialiser#initialise(Object)}
// *
// * @param object
// */
// public static void initialise(Object object) {
// INITIALISER.initialise(object);
// }
//
// /**
// * {@link Verifier#collectiveVerify(Class, Collection)}
// *
// * @param mockClass
// * @param collection
// * @return Object used for verification of all the mocks in the supplied collection
// */
// public static <T> T collectiveVerify(Class<T> mockClass, Collection<T> collection) {
// return VERIFIER.collectiveVerify(mockClass, collection);
// }
//
// /**
// * {@link Verifier#collectiveVerify(Class, Collection, VerificationMode)}
// *
// * @param mockClass
// * @param collection
// * @param mode
// * @return Object used for verification of all the mocks in the supplied collection
// */
// public static <T> T collectiveVerify(Class<T> mockClass, Collection<T> collection, VerificationMode mode) {
// return VERIFIER.collectiveVerify(mockClass, collection, mode);
// }
//
// /**
// * {@link Verifier#collectiveVerifyZeroInteractions(Collection...)}
// *
// * @param mocks
// */
// public static <T> void collectiveVerifyZeroInteractions(Collection<T>... mocks) {
// VERIFIER.collectiveVerifyZeroInteractions(mocks);
// }
//
// /**
// * {@link Verifier#collectiveVerifyNoMoreInteractions(Collection...)}
// *
// * @param mocks
// */
// public static <T> void collectiveVerifyNoMoreInteractions(Collection<T>... mocks) {
// VERIFIER.collectiveVerifyNoMoreInteractions(mocks);
// }
// }
//
// Path: mockito-collections-core-integration-tests/src/main/java/uk/co/webamoeba/mockito/collections/core/integrationtests/support/ClassWithCollectionOfCollaborators.java
// public class ClassWithCollectionOfCollaborators implements HasCollaborators<EventListener> {
//
// private Collection<EventListener> collaborators;
//
// public Collection<EventListener> getCollaborators() {
// return collaborators;
// }
// }
| import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import java.util.Collection;
import java.util.EventListener;
import org.junit.Test;
import org.mockito.InjectMocks;
import org.mockito.internal.util.MockUtil;
import uk.co.webamoeba.mockito.collections.MockitoCollections;
import uk.co.webamoeba.mockito.collections.annotation.CollectionOfMocks;
import uk.co.webamoeba.mockito.collections.core.integrationtests.support.ClassWithCollectionOfCollaborators; | package uk.co.webamoeba.mockito.collections.core.integrationtests;
public class InjectCollectionOfMocksAnnotatedFieldsStoryIntegrationTest implements
InjectCollectionOfMocksAnnotatedFieldsStory {
@Test
public void objectUnderTestHasCollectionOfCollaborators() {
// Given
ExampleTest test = new ExampleTest();
test.objectUnderTest = new ClassWithCollectionOfCollaborators();
// When | // Path: mockito-collections-core/src/main/java/uk/co/webamoeba/mockito/collections/MockitoCollections.java
// public class MockitoCollections {
//
// private static Initialiser INITIALISER = new Initialiser();
//
// private static Verifier VERIFIER = new Verifier();
//
// /**
// * {@link Initialiser#initialise(Object)}
// *
// * @param object
// */
// public static void initialise(Object object) {
// INITIALISER.initialise(object);
// }
//
// /**
// * {@link Verifier#collectiveVerify(Class, Collection)}
// *
// * @param mockClass
// * @param collection
// * @return Object used for verification of all the mocks in the supplied collection
// */
// public static <T> T collectiveVerify(Class<T> mockClass, Collection<T> collection) {
// return VERIFIER.collectiveVerify(mockClass, collection);
// }
//
// /**
// * {@link Verifier#collectiveVerify(Class, Collection, VerificationMode)}
// *
// * @param mockClass
// * @param collection
// * @param mode
// * @return Object used for verification of all the mocks in the supplied collection
// */
// public static <T> T collectiveVerify(Class<T> mockClass, Collection<T> collection, VerificationMode mode) {
// return VERIFIER.collectiveVerify(mockClass, collection, mode);
// }
//
// /**
// * {@link Verifier#collectiveVerifyZeroInteractions(Collection...)}
// *
// * @param mocks
// */
// public static <T> void collectiveVerifyZeroInteractions(Collection<T>... mocks) {
// VERIFIER.collectiveVerifyZeroInteractions(mocks);
// }
//
// /**
// * {@link Verifier#collectiveVerifyNoMoreInteractions(Collection...)}
// *
// * @param mocks
// */
// public static <T> void collectiveVerifyNoMoreInteractions(Collection<T>... mocks) {
// VERIFIER.collectiveVerifyNoMoreInteractions(mocks);
// }
// }
//
// Path: mockito-collections-core-integration-tests/src/main/java/uk/co/webamoeba/mockito/collections/core/integrationtests/support/ClassWithCollectionOfCollaborators.java
// public class ClassWithCollectionOfCollaborators implements HasCollaborators<EventListener> {
//
// private Collection<EventListener> collaborators;
//
// public Collection<EventListener> getCollaborators() {
// return collaborators;
// }
// }
// Path: mockito-collections-core-integration-tests/src/test/java/uk/co/webamoeba/mockito/collections/core/integrationtests/InjectCollectionOfMocksAnnotatedFieldsStoryIntegrationTest.java
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import java.util.Collection;
import java.util.EventListener;
import org.junit.Test;
import org.mockito.InjectMocks;
import org.mockito.internal.util.MockUtil;
import uk.co.webamoeba.mockito.collections.MockitoCollections;
import uk.co.webamoeba.mockito.collections.annotation.CollectionOfMocks;
import uk.co.webamoeba.mockito.collections.core.integrationtests.support.ClassWithCollectionOfCollaborators;
package uk.co.webamoeba.mockito.collections.core.integrationtests;
public class InjectCollectionOfMocksAnnotatedFieldsStoryIntegrationTest implements
InjectCollectionOfMocksAnnotatedFieldsStory {
@Test
public void objectUnderTestHasCollectionOfCollaborators() {
// Given
ExampleTest test = new ExampleTest();
test.objectUnderTest = new ClassWithCollectionOfCollaborators();
// When | MockitoCollections.initialise(test); |
jameskennard/mockito-collections | mockito-collections-samples/src/test/java/uk/co/webamoeba/mockito/collections/sample/HandlerManagerAlterantiveTest.java | // Path: mockito-collections-core/src/main/java/uk/co/webamoeba/mockito/collections/MockitoCollections.java
// public class MockitoCollections {
//
// private static Initialiser INITIALISER = new Initialiser();
//
// private static Verifier VERIFIER = new Verifier();
//
// /**
// * {@link Initialiser#initialise(Object)}
// *
// * @param object
// */
// public static void initialise(Object object) {
// INITIALISER.initialise(object);
// }
//
// /**
// * {@link Verifier#collectiveVerify(Class, Collection)}
// *
// * @param mockClass
// * @param collection
// * @return Object used for verification of all the mocks in the supplied collection
// */
// public static <T> T collectiveVerify(Class<T> mockClass, Collection<T> collection) {
// return VERIFIER.collectiveVerify(mockClass, collection);
// }
//
// /**
// * {@link Verifier#collectiveVerify(Class, Collection, VerificationMode)}
// *
// * @param mockClass
// * @param collection
// * @param mode
// * @return Object used for verification of all the mocks in the supplied collection
// */
// public static <T> T collectiveVerify(Class<T> mockClass, Collection<T> collection, VerificationMode mode) {
// return VERIFIER.collectiveVerify(mockClass, collection, mode);
// }
//
// /**
// * {@link Verifier#collectiveVerifyZeroInteractions(Collection...)}
// *
// * @param mocks
// */
// public static <T> void collectiveVerifyZeroInteractions(Collection<T>... mocks) {
// VERIFIER.collectiveVerifyZeroInteractions(mocks);
// }
//
// /**
// * {@link Verifier#collectiveVerifyNoMoreInteractions(Collection...)}
// *
// * @param mocks
// */
// public static <T> void collectiveVerifyNoMoreInteractions(Collection<T>... mocks) {
// VERIFIER.collectiveVerifyNoMoreInteractions(mocks);
// }
// }
| import static org.junit.Assert.assertArrayEquals;
import static org.mockito.BDDMockito.given;
import java.util.Set;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import uk.co.webamoeba.mockito.collections.MockitoCollections; | package uk.co.webamoeba.mockito.collections.sample;
/**
* This test shows how you can use Mockito Collections to deal simply with a {@link Set} of delegates that return
* values. Comments are included throughout the file to hellp clarify what's going on.
*
* @author James Kennard
*/
@RunWith(MockitoJUnitRunner.class)
public class HandlerManagerAlterantiveTest {
// HandlerManager containing a Set of Handlers
@InjectMocks
private HandlerManager manager;
// Mock to be injected
// Name means it will be always first even though it is to be injected into a Set (alphabetical)
@Mock
private Handler handler1;
// Another Mock to be injected
// Name means it will always be second even though it is to be injected into a Set (alphabetical)
@Mock
private Handler handler2;
// Setup making use of Mockito Collections for injection of handlers
@Before
public void before() { | // Path: mockito-collections-core/src/main/java/uk/co/webamoeba/mockito/collections/MockitoCollections.java
// public class MockitoCollections {
//
// private static Initialiser INITIALISER = new Initialiser();
//
// private static Verifier VERIFIER = new Verifier();
//
// /**
// * {@link Initialiser#initialise(Object)}
// *
// * @param object
// */
// public static void initialise(Object object) {
// INITIALISER.initialise(object);
// }
//
// /**
// * {@link Verifier#collectiveVerify(Class, Collection)}
// *
// * @param mockClass
// * @param collection
// * @return Object used for verification of all the mocks in the supplied collection
// */
// public static <T> T collectiveVerify(Class<T> mockClass, Collection<T> collection) {
// return VERIFIER.collectiveVerify(mockClass, collection);
// }
//
// /**
// * {@link Verifier#collectiveVerify(Class, Collection, VerificationMode)}
// *
// * @param mockClass
// * @param collection
// * @param mode
// * @return Object used for verification of all the mocks in the supplied collection
// */
// public static <T> T collectiveVerify(Class<T> mockClass, Collection<T> collection, VerificationMode mode) {
// return VERIFIER.collectiveVerify(mockClass, collection, mode);
// }
//
// /**
// * {@link Verifier#collectiveVerifyZeroInteractions(Collection...)}
// *
// * @param mocks
// */
// public static <T> void collectiveVerifyZeroInteractions(Collection<T>... mocks) {
// VERIFIER.collectiveVerifyZeroInteractions(mocks);
// }
//
// /**
// * {@link Verifier#collectiveVerifyNoMoreInteractions(Collection...)}
// *
// * @param mocks
// */
// public static <T> void collectiveVerifyNoMoreInteractions(Collection<T>... mocks) {
// VERIFIER.collectiveVerifyNoMoreInteractions(mocks);
// }
// }
// Path: mockito-collections-samples/src/test/java/uk/co/webamoeba/mockito/collections/sample/HandlerManagerAlterantiveTest.java
import static org.junit.Assert.assertArrayEquals;
import static org.mockito.BDDMockito.given;
import java.util.Set;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import uk.co.webamoeba.mockito.collections.MockitoCollections;
package uk.co.webamoeba.mockito.collections.sample;
/**
* This test shows how you can use Mockito Collections to deal simply with a {@link Set} of delegates that return
* values. Comments are included throughout the file to hellp clarify what's going on.
*
* @author James Kennard
*/
@RunWith(MockitoJUnitRunner.class)
public class HandlerManagerAlterantiveTest {
// HandlerManager containing a Set of Handlers
@InjectMocks
private HandlerManager manager;
// Mock to be injected
// Name means it will be always first even though it is to be injected into a Set (alphabetical)
@Mock
private Handler handler1;
// Another Mock to be injected
// Name means it will always be second even though it is to be injected into a Set (alphabetical)
@Mock
private Handler handler2;
// Setup making use of Mockito Collections for injection of handlers
@Before
public void before() { | MockitoCollections.initialise(this); |
jameskennard/mockito-collections | mockito-collections-core-integration-tests/src/test/java/uk/co/webamoeba/mockito/collections/core/integrationtests/DoNotInjectIgnoredMocksIntoCollectionsStoryIntegrationTest.java | // Path: mockito-collections-core/src/main/java/uk/co/webamoeba/mockito/collections/MockitoCollections.java
// public class MockitoCollections {
//
// private static Initialiser INITIALISER = new Initialiser();
//
// private static Verifier VERIFIER = new Verifier();
//
// /**
// * {@link Initialiser#initialise(Object)}
// *
// * @param object
// */
// public static void initialise(Object object) {
// INITIALISER.initialise(object);
// }
//
// /**
// * {@link Verifier#collectiveVerify(Class, Collection)}
// *
// * @param mockClass
// * @param collection
// * @return Object used for verification of all the mocks in the supplied collection
// */
// public static <T> T collectiveVerify(Class<T> mockClass, Collection<T> collection) {
// return VERIFIER.collectiveVerify(mockClass, collection);
// }
//
// /**
// * {@link Verifier#collectiveVerify(Class, Collection, VerificationMode)}
// *
// * @param mockClass
// * @param collection
// * @param mode
// * @return Object used for verification of all the mocks in the supplied collection
// */
// public static <T> T collectiveVerify(Class<T> mockClass, Collection<T> collection, VerificationMode mode) {
// return VERIFIER.collectiveVerify(mockClass, collection, mode);
// }
//
// /**
// * {@link Verifier#collectiveVerifyZeroInteractions(Collection...)}
// *
// * @param mocks
// */
// public static <T> void collectiveVerifyZeroInteractions(Collection<T>... mocks) {
// VERIFIER.collectiveVerifyZeroInteractions(mocks);
// }
//
// /**
// * {@link Verifier#collectiveVerifyNoMoreInteractions(Collection...)}
// *
// * @param mocks
// */
// public static <T> void collectiveVerifyNoMoreInteractions(Collection<T>... mocks) {
// VERIFIER.collectiveVerifyNoMoreInteractions(mocks);
// }
// }
//
// Path: mockito-collections-core-integration-tests/src/main/java/uk/co/webamoeba/mockito/collections/core/integrationtests/support/ClassWithCollectionOfCollaborators.java
// public class ClassWithCollectionOfCollaborators implements HasCollaborators<EventListener> {
//
// private Collection<EventListener> collaborators;
//
// public Collection<EventListener> getCollaborators() {
// return collaborators;
// }
// }
| import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
import static org.mockito.Mockito.mock;
import java.util.EventListener;
import org.junit.Test;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import uk.co.webamoeba.mockito.collections.MockitoCollections;
import uk.co.webamoeba.mockito.collections.annotation.IgnoreForCollections;
import uk.co.webamoeba.mockito.collections.core.integrationtests.support.ClassWithCollectionOfCollaborators; | package uk.co.webamoeba.mockito.collections.core.integrationtests;
public class DoNotInjectIgnoredMocksIntoCollectionsStoryIntegrationTest implements
DoNotInjectIgnoredMocksIntoCollectionsStory {
@Test
public void allMocksHaveTheIgnoreForCollectionsAnnotation() {
// Given | // Path: mockito-collections-core/src/main/java/uk/co/webamoeba/mockito/collections/MockitoCollections.java
// public class MockitoCollections {
//
// private static Initialiser INITIALISER = new Initialiser();
//
// private static Verifier VERIFIER = new Verifier();
//
// /**
// * {@link Initialiser#initialise(Object)}
// *
// * @param object
// */
// public static void initialise(Object object) {
// INITIALISER.initialise(object);
// }
//
// /**
// * {@link Verifier#collectiveVerify(Class, Collection)}
// *
// * @param mockClass
// * @param collection
// * @return Object used for verification of all the mocks in the supplied collection
// */
// public static <T> T collectiveVerify(Class<T> mockClass, Collection<T> collection) {
// return VERIFIER.collectiveVerify(mockClass, collection);
// }
//
// /**
// * {@link Verifier#collectiveVerify(Class, Collection, VerificationMode)}
// *
// * @param mockClass
// * @param collection
// * @param mode
// * @return Object used for verification of all the mocks in the supplied collection
// */
// public static <T> T collectiveVerify(Class<T> mockClass, Collection<T> collection, VerificationMode mode) {
// return VERIFIER.collectiveVerify(mockClass, collection, mode);
// }
//
// /**
// * {@link Verifier#collectiveVerifyZeroInteractions(Collection...)}
// *
// * @param mocks
// */
// public static <T> void collectiveVerifyZeroInteractions(Collection<T>... mocks) {
// VERIFIER.collectiveVerifyZeroInteractions(mocks);
// }
//
// /**
// * {@link Verifier#collectiveVerifyNoMoreInteractions(Collection...)}
// *
// * @param mocks
// */
// public static <T> void collectiveVerifyNoMoreInteractions(Collection<T>... mocks) {
// VERIFIER.collectiveVerifyNoMoreInteractions(mocks);
// }
// }
//
// Path: mockito-collections-core-integration-tests/src/main/java/uk/co/webamoeba/mockito/collections/core/integrationtests/support/ClassWithCollectionOfCollaborators.java
// public class ClassWithCollectionOfCollaborators implements HasCollaborators<EventListener> {
//
// private Collection<EventListener> collaborators;
//
// public Collection<EventListener> getCollaborators() {
// return collaborators;
// }
// }
// Path: mockito-collections-core-integration-tests/src/test/java/uk/co/webamoeba/mockito/collections/core/integrationtests/DoNotInjectIgnoredMocksIntoCollectionsStoryIntegrationTest.java
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
import static org.mockito.Mockito.mock;
import java.util.EventListener;
import org.junit.Test;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import uk.co.webamoeba.mockito.collections.MockitoCollections;
import uk.co.webamoeba.mockito.collections.annotation.IgnoreForCollections;
import uk.co.webamoeba.mockito.collections.core.integrationtests.support.ClassWithCollectionOfCollaborators;
package uk.co.webamoeba.mockito.collections.core.integrationtests;
public class DoNotInjectIgnoredMocksIntoCollectionsStoryIntegrationTest implements
DoNotInjectIgnoredMocksIntoCollectionsStory {
@Test
public void allMocksHaveTheIgnoreForCollectionsAnnotation() {
// Given | final ClassWithCollectionOfCollaborators outerObjectUnderTest = new ClassWithCollectionOfCollaborators(); |
jameskennard/mockito-collections | mockito-collections-core-integration-tests/src/test/java/uk/co/webamoeba/mockito/collections/core/integrationtests/DoNotInjectIgnoredMocksIntoCollectionsStoryIntegrationTest.java | // Path: mockito-collections-core/src/main/java/uk/co/webamoeba/mockito/collections/MockitoCollections.java
// public class MockitoCollections {
//
// private static Initialiser INITIALISER = new Initialiser();
//
// private static Verifier VERIFIER = new Verifier();
//
// /**
// * {@link Initialiser#initialise(Object)}
// *
// * @param object
// */
// public static void initialise(Object object) {
// INITIALISER.initialise(object);
// }
//
// /**
// * {@link Verifier#collectiveVerify(Class, Collection)}
// *
// * @param mockClass
// * @param collection
// * @return Object used for verification of all the mocks in the supplied collection
// */
// public static <T> T collectiveVerify(Class<T> mockClass, Collection<T> collection) {
// return VERIFIER.collectiveVerify(mockClass, collection);
// }
//
// /**
// * {@link Verifier#collectiveVerify(Class, Collection, VerificationMode)}
// *
// * @param mockClass
// * @param collection
// * @param mode
// * @return Object used for verification of all the mocks in the supplied collection
// */
// public static <T> T collectiveVerify(Class<T> mockClass, Collection<T> collection, VerificationMode mode) {
// return VERIFIER.collectiveVerify(mockClass, collection, mode);
// }
//
// /**
// * {@link Verifier#collectiveVerifyZeroInteractions(Collection...)}
// *
// * @param mocks
// */
// public static <T> void collectiveVerifyZeroInteractions(Collection<T>... mocks) {
// VERIFIER.collectiveVerifyZeroInteractions(mocks);
// }
//
// /**
// * {@link Verifier#collectiveVerifyNoMoreInteractions(Collection...)}
// *
// * @param mocks
// */
// public static <T> void collectiveVerifyNoMoreInteractions(Collection<T>... mocks) {
// VERIFIER.collectiveVerifyNoMoreInteractions(mocks);
// }
// }
//
// Path: mockito-collections-core-integration-tests/src/main/java/uk/co/webamoeba/mockito/collections/core/integrationtests/support/ClassWithCollectionOfCollaborators.java
// public class ClassWithCollectionOfCollaborators implements HasCollaborators<EventListener> {
//
// private Collection<EventListener> collaborators;
//
// public Collection<EventListener> getCollaborators() {
// return collaborators;
// }
// }
| import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
import static org.mockito.Mockito.mock;
import java.util.EventListener;
import org.junit.Test;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import uk.co.webamoeba.mockito.collections.MockitoCollections;
import uk.co.webamoeba.mockito.collections.annotation.IgnoreForCollections;
import uk.co.webamoeba.mockito.collections.core.integrationtests.support.ClassWithCollectionOfCollaborators; | package uk.co.webamoeba.mockito.collections.core.integrationtests;
public class DoNotInjectIgnoredMocksIntoCollectionsStoryIntegrationTest implements
DoNotInjectIgnoredMocksIntoCollectionsStory {
@Test
public void allMocksHaveTheIgnoreForCollectionsAnnotation() {
// Given
final ClassWithCollectionOfCollaborators outerObjectUnderTest = new ClassWithCollectionOfCollaborators();
final EventListener outerCollaborator1 = mock(EventListener.class);
final EventListener outerCollaborator2 = mock(EventListener.class);
@SuppressWarnings("unused")
Object exampleTest = new Object() {
@InjectMocks
ClassWithCollectionOfCollaborators objectUnderTest = outerObjectUnderTest;
@Mock
@IgnoreForCollections
private EventListener collaborator1 = outerCollaborator1;
@Mock
@IgnoreForCollections
private EventListener collaborator2 = outerCollaborator2;
};
// When | // Path: mockito-collections-core/src/main/java/uk/co/webamoeba/mockito/collections/MockitoCollections.java
// public class MockitoCollections {
//
// private static Initialiser INITIALISER = new Initialiser();
//
// private static Verifier VERIFIER = new Verifier();
//
// /**
// * {@link Initialiser#initialise(Object)}
// *
// * @param object
// */
// public static void initialise(Object object) {
// INITIALISER.initialise(object);
// }
//
// /**
// * {@link Verifier#collectiveVerify(Class, Collection)}
// *
// * @param mockClass
// * @param collection
// * @return Object used for verification of all the mocks in the supplied collection
// */
// public static <T> T collectiveVerify(Class<T> mockClass, Collection<T> collection) {
// return VERIFIER.collectiveVerify(mockClass, collection);
// }
//
// /**
// * {@link Verifier#collectiveVerify(Class, Collection, VerificationMode)}
// *
// * @param mockClass
// * @param collection
// * @param mode
// * @return Object used for verification of all the mocks in the supplied collection
// */
// public static <T> T collectiveVerify(Class<T> mockClass, Collection<T> collection, VerificationMode mode) {
// return VERIFIER.collectiveVerify(mockClass, collection, mode);
// }
//
// /**
// * {@link Verifier#collectiveVerifyZeroInteractions(Collection...)}
// *
// * @param mocks
// */
// public static <T> void collectiveVerifyZeroInteractions(Collection<T>... mocks) {
// VERIFIER.collectiveVerifyZeroInteractions(mocks);
// }
//
// /**
// * {@link Verifier#collectiveVerifyNoMoreInteractions(Collection...)}
// *
// * @param mocks
// */
// public static <T> void collectiveVerifyNoMoreInteractions(Collection<T>... mocks) {
// VERIFIER.collectiveVerifyNoMoreInteractions(mocks);
// }
// }
//
// Path: mockito-collections-core-integration-tests/src/main/java/uk/co/webamoeba/mockito/collections/core/integrationtests/support/ClassWithCollectionOfCollaborators.java
// public class ClassWithCollectionOfCollaborators implements HasCollaborators<EventListener> {
//
// private Collection<EventListener> collaborators;
//
// public Collection<EventListener> getCollaborators() {
// return collaborators;
// }
// }
// Path: mockito-collections-core-integration-tests/src/test/java/uk/co/webamoeba/mockito/collections/core/integrationtests/DoNotInjectIgnoredMocksIntoCollectionsStoryIntegrationTest.java
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
import static org.mockito.Mockito.mock;
import java.util.EventListener;
import org.junit.Test;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import uk.co.webamoeba.mockito.collections.MockitoCollections;
import uk.co.webamoeba.mockito.collections.annotation.IgnoreForCollections;
import uk.co.webamoeba.mockito.collections.core.integrationtests.support.ClassWithCollectionOfCollaborators;
package uk.co.webamoeba.mockito.collections.core.integrationtests;
public class DoNotInjectIgnoredMocksIntoCollectionsStoryIntegrationTest implements
DoNotInjectIgnoredMocksIntoCollectionsStory {
@Test
public void allMocksHaveTheIgnoreForCollectionsAnnotation() {
// Given
final ClassWithCollectionOfCollaborators outerObjectUnderTest = new ClassWithCollectionOfCollaborators();
final EventListener outerCollaborator1 = mock(EventListener.class);
final EventListener outerCollaborator2 = mock(EventListener.class);
@SuppressWarnings("unused")
Object exampleTest = new Object() {
@InjectMocks
ClassWithCollectionOfCollaborators objectUnderTest = outerObjectUnderTest;
@Mock
@IgnoreForCollections
private EventListener collaborator1 = outerCollaborator1;
@Mock
@IgnoreForCollections
private EventListener collaborator2 = outerCollaborator2;
};
// When | MockitoCollections.initialise(exampleTest); |
jameskennard/mockito-collections | mockito-collections-core-integration-tests/src/test/java/uk/co/webamoeba/mockito/collections/core/integrationtests/InjectCollectionsOfMatchingMocksStoryIntegrationTest.java | // Path: mockito-collections-core/src/main/java/uk/co/webamoeba/mockito/collections/MockitoCollections.java
// public class MockitoCollections {
//
// private static Initialiser INITIALISER = new Initialiser();
//
// private static Verifier VERIFIER = new Verifier();
//
// /**
// * {@link Initialiser#initialise(Object)}
// *
// * @param object
// */
// public static void initialise(Object object) {
// INITIALISER.initialise(object);
// }
//
// /**
// * {@link Verifier#collectiveVerify(Class, Collection)}
// *
// * @param mockClass
// * @param collection
// * @return Object used for verification of all the mocks in the supplied collection
// */
// public static <T> T collectiveVerify(Class<T> mockClass, Collection<T> collection) {
// return VERIFIER.collectiveVerify(mockClass, collection);
// }
//
// /**
// * {@link Verifier#collectiveVerify(Class, Collection, VerificationMode)}
// *
// * @param mockClass
// * @param collection
// * @param mode
// * @return Object used for verification of all the mocks in the supplied collection
// */
// public static <T> T collectiveVerify(Class<T> mockClass, Collection<T> collection, VerificationMode mode) {
// return VERIFIER.collectiveVerify(mockClass, collection, mode);
// }
//
// /**
// * {@link Verifier#collectiveVerifyZeroInteractions(Collection...)}
// *
// * @param mocks
// */
// public static <T> void collectiveVerifyZeroInteractions(Collection<T>... mocks) {
// VERIFIER.collectiveVerifyZeroInteractions(mocks);
// }
//
// /**
// * {@link Verifier#collectiveVerifyNoMoreInteractions(Collection...)}
// *
// * @param mocks
// */
// public static <T> void collectiveVerifyNoMoreInteractions(Collection<T>... mocks) {
// VERIFIER.collectiveVerifyNoMoreInteractions(mocks);
// }
// }
//
// Path: mockito-collections-core-integration-tests/src/main/java/uk/co/webamoeba/mockito/collections/core/integrationtests/support/ClassWithCollectionOfCollaborators.java
// public class ClassWithCollectionOfCollaborators implements HasCollaborators<EventListener> {
//
// private Collection<EventListener> collaborators;
//
// public Collection<EventListener> getCollaborators() {
// return collaborators;
// }
// }
| import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
import static org.mockito.Mockito.mock;
import java.util.EventListener;
import java.util.EventListenerProxy;
import java.util.Iterator;
import org.junit.Test;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import uk.co.webamoeba.mockito.collections.MockitoCollections;
import uk.co.webamoeba.mockito.collections.core.integrationtests.support.ClassWithCollectionOfCollaborators; | package uk.co.webamoeba.mockito.collections.core.integrationtests;
public class InjectCollectionsOfMatchingMocksStoryIntegrationTest implements InjectCollectionsOfMatchingMocksStory {
@Test
public void testHasMocksOfSameType() {
// Given | // Path: mockito-collections-core/src/main/java/uk/co/webamoeba/mockito/collections/MockitoCollections.java
// public class MockitoCollections {
//
// private static Initialiser INITIALISER = new Initialiser();
//
// private static Verifier VERIFIER = new Verifier();
//
// /**
// * {@link Initialiser#initialise(Object)}
// *
// * @param object
// */
// public static void initialise(Object object) {
// INITIALISER.initialise(object);
// }
//
// /**
// * {@link Verifier#collectiveVerify(Class, Collection)}
// *
// * @param mockClass
// * @param collection
// * @return Object used for verification of all the mocks in the supplied collection
// */
// public static <T> T collectiveVerify(Class<T> mockClass, Collection<T> collection) {
// return VERIFIER.collectiveVerify(mockClass, collection);
// }
//
// /**
// * {@link Verifier#collectiveVerify(Class, Collection, VerificationMode)}
// *
// * @param mockClass
// * @param collection
// * @param mode
// * @return Object used for verification of all the mocks in the supplied collection
// */
// public static <T> T collectiveVerify(Class<T> mockClass, Collection<T> collection, VerificationMode mode) {
// return VERIFIER.collectiveVerify(mockClass, collection, mode);
// }
//
// /**
// * {@link Verifier#collectiveVerifyZeroInteractions(Collection...)}
// *
// * @param mocks
// */
// public static <T> void collectiveVerifyZeroInteractions(Collection<T>... mocks) {
// VERIFIER.collectiveVerifyZeroInteractions(mocks);
// }
//
// /**
// * {@link Verifier#collectiveVerifyNoMoreInteractions(Collection...)}
// *
// * @param mocks
// */
// public static <T> void collectiveVerifyNoMoreInteractions(Collection<T>... mocks) {
// VERIFIER.collectiveVerifyNoMoreInteractions(mocks);
// }
// }
//
// Path: mockito-collections-core-integration-tests/src/main/java/uk/co/webamoeba/mockito/collections/core/integrationtests/support/ClassWithCollectionOfCollaborators.java
// public class ClassWithCollectionOfCollaborators implements HasCollaborators<EventListener> {
//
// private Collection<EventListener> collaborators;
//
// public Collection<EventListener> getCollaborators() {
// return collaborators;
// }
// }
// Path: mockito-collections-core-integration-tests/src/test/java/uk/co/webamoeba/mockito/collections/core/integrationtests/InjectCollectionsOfMatchingMocksStoryIntegrationTest.java
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
import static org.mockito.Mockito.mock;
import java.util.EventListener;
import java.util.EventListenerProxy;
import java.util.Iterator;
import org.junit.Test;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import uk.co.webamoeba.mockito.collections.MockitoCollections;
import uk.co.webamoeba.mockito.collections.core.integrationtests.support.ClassWithCollectionOfCollaborators;
package uk.co.webamoeba.mockito.collections.core.integrationtests;
public class InjectCollectionsOfMatchingMocksStoryIntegrationTest implements InjectCollectionsOfMatchingMocksStory {
@Test
public void testHasMocksOfSameType() {
// Given | final ClassWithCollectionOfCollaborators outerObjectUnderTest = new ClassWithCollectionOfCollaborators(); |
jameskennard/mockito-collections | mockito-collections-core-integration-tests/src/test/java/uk/co/webamoeba/mockito/collections/core/integrationtests/InjectCollectionsOfMatchingMocksStoryIntegrationTest.java | // Path: mockito-collections-core/src/main/java/uk/co/webamoeba/mockito/collections/MockitoCollections.java
// public class MockitoCollections {
//
// private static Initialiser INITIALISER = new Initialiser();
//
// private static Verifier VERIFIER = new Verifier();
//
// /**
// * {@link Initialiser#initialise(Object)}
// *
// * @param object
// */
// public static void initialise(Object object) {
// INITIALISER.initialise(object);
// }
//
// /**
// * {@link Verifier#collectiveVerify(Class, Collection)}
// *
// * @param mockClass
// * @param collection
// * @return Object used for verification of all the mocks in the supplied collection
// */
// public static <T> T collectiveVerify(Class<T> mockClass, Collection<T> collection) {
// return VERIFIER.collectiveVerify(mockClass, collection);
// }
//
// /**
// * {@link Verifier#collectiveVerify(Class, Collection, VerificationMode)}
// *
// * @param mockClass
// * @param collection
// * @param mode
// * @return Object used for verification of all the mocks in the supplied collection
// */
// public static <T> T collectiveVerify(Class<T> mockClass, Collection<T> collection, VerificationMode mode) {
// return VERIFIER.collectiveVerify(mockClass, collection, mode);
// }
//
// /**
// * {@link Verifier#collectiveVerifyZeroInteractions(Collection...)}
// *
// * @param mocks
// */
// public static <T> void collectiveVerifyZeroInteractions(Collection<T>... mocks) {
// VERIFIER.collectiveVerifyZeroInteractions(mocks);
// }
//
// /**
// * {@link Verifier#collectiveVerifyNoMoreInteractions(Collection...)}
// *
// * @param mocks
// */
// public static <T> void collectiveVerifyNoMoreInteractions(Collection<T>... mocks) {
// VERIFIER.collectiveVerifyNoMoreInteractions(mocks);
// }
// }
//
// Path: mockito-collections-core-integration-tests/src/main/java/uk/co/webamoeba/mockito/collections/core/integrationtests/support/ClassWithCollectionOfCollaborators.java
// public class ClassWithCollectionOfCollaborators implements HasCollaborators<EventListener> {
//
// private Collection<EventListener> collaborators;
//
// public Collection<EventListener> getCollaborators() {
// return collaborators;
// }
// }
| import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
import static org.mockito.Mockito.mock;
import java.util.EventListener;
import java.util.EventListenerProxy;
import java.util.Iterator;
import org.junit.Test;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import uk.co.webamoeba.mockito.collections.MockitoCollections;
import uk.co.webamoeba.mockito.collections.core.integrationtests.support.ClassWithCollectionOfCollaborators; | package uk.co.webamoeba.mockito.collections.core.integrationtests;
public class InjectCollectionsOfMatchingMocksStoryIntegrationTest implements InjectCollectionsOfMatchingMocksStory {
@Test
public void testHasMocksOfSameType() {
// Given
final ClassWithCollectionOfCollaborators outerObjectUnderTest = new ClassWithCollectionOfCollaborators();
final EventListener outerCollaborator1 = mock(EventListener.class);
final EventListener outerCollaborator2 = mock(EventListener.class);
@SuppressWarnings("unused")
Object exampleTest = new Object() {
@InjectMocks
ClassWithCollectionOfCollaborators objectUnderTest = outerObjectUnderTest;
@Mock
private EventListener collaborator1 = outerCollaborator1;
@Mock
private EventListener collaborator2 = outerCollaborator2;
};
// When | // Path: mockito-collections-core/src/main/java/uk/co/webamoeba/mockito/collections/MockitoCollections.java
// public class MockitoCollections {
//
// private static Initialiser INITIALISER = new Initialiser();
//
// private static Verifier VERIFIER = new Verifier();
//
// /**
// * {@link Initialiser#initialise(Object)}
// *
// * @param object
// */
// public static void initialise(Object object) {
// INITIALISER.initialise(object);
// }
//
// /**
// * {@link Verifier#collectiveVerify(Class, Collection)}
// *
// * @param mockClass
// * @param collection
// * @return Object used for verification of all the mocks in the supplied collection
// */
// public static <T> T collectiveVerify(Class<T> mockClass, Collection<T> collection) {
// return VERIFIER.collectiveVerify(mockClass, collection);
// }
//
// /**
// * {@link Verifier#collectiveVerify(Class, Collection, VerificationMode)}
// *
// * @param mockClass
// * @param collection
// * @param mode
// * @return Object used for verification of all the mocks in the supplied collection
// */
// public static <T> T collectiveVerify(Class<T> mockClass, Collection<T> collection, VerificationMode mode) {
// return VERIFIER.collectiveVerify(mockClass, collection, mode);
// }
//
// /**
// * {@link Verifier#collectiveVerifyZeroInteractions(Collection...)}
// *
// * @param mocks
// */
// public static <T> void collectiveVerifyZeroInteractions(Collection<T>... mocks) {
// VERIFIER.collectiveVerifyZeroInteractions(mocks);
// }
//
// /**
// * {@link Verifier#collectiveVerifyNoMoreInteractions(Collection...)}
// *
// * @param mocks
// */
// public static <T> void collectiveVerifyNoMoreInteractions(Collection<T>... mocks) {
// VERIFIER.collectiveVerifyNoMoreInteractions(mocks);
// }
// }
//
// Path: mockito-collections-core-integration-tests/src/main/java/uk/co/webamoeba/mockito/collections/core/integrationtests/support/ClassWithCollectionOfCollaborators.java
// public class ClassWithCollectionOfCollaborators implements HasCollaborators<EventListener> {
//
// private Collection<EventListener> collaborators;
//
// public Collection<EventListener> getCollaborators() {
// return collaborators;
// }
// }
// Path: mockito-collections-core-integration-tests/src/test/java/uk/co/webamoeba/mockito/collections/core/integrationtests/InjectCollectionsOfMatchingMocksStoryIntegrationTest.java
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
import static org.mockito.Mockito.mock;
import java.util.EventListener;
import java.util.EventListenerProxy;
import java.util.Iterator;
import org.junit.Test;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import uk.co.webamoeba.mockito.collections.MockitoCollections;
import uk.co.webamoeba.mockito.collections.core.integrationtests.support.ClassWithCollectionOfCollaborators;
package uk.co.webamoeba.mockito.collections.core.integrationtests;
public class InjectCollectionsOfMatchingMocksStoryIntegrationTest implements InjectCollectionsOfMatchingMocksStory {
@Test
public void testHasMocksOfSameType() {
// Given
final ClassWithCollectionOfCollaborators outerObjectUnderTest = new ClassWithCollectionOfCollaborators();
final EventListener outerCollaborator1 = mock(EventListener.class);
final EventListener outerCollaborator2 = mock(EventListener.class);
@SuppressWarnings("unused")
Object exampleTest = new Object() {
@InjectMocks
ClassWithCollectionOfCollaborators objectUnderTest = outerObjectUnderTest;
@Mock
private EventListener collaborator1 = outerCollaborator1;
@Mock
private EventListener collaborator2 = outerCollaborator2;
};
// When | MockitoCollections.initialise(exampleTest); |
jameskennard/mockito-collections | mockito-collections-core/src/test/java/uk/co/webamoeba/mockito/collections/inject/CollectionFactoryTest.java | // Path: mockito-collections-core/src/main/java/uk/co/webamoeba/mockito/collections/util/OrderedSet.java
// public class OrderedSet<E> implements Set<E> {
//
// private LinkedHashSet<E> set;
//
// public OrderedSet() {
// this.set = new LinkedHashSet<E>();
// }
//
// public OrderedSet(Collection<E> set) {
// this.set = new LinkedHashSet<E>(set);
// }
//
// public OrderedSet(int initialCapacity) {
// this.set = new LinkedHashSet<E>(initialCapacity);
// }
//
// public Object[] toArray() {
// return set.toArray();
// }
//
// public boolean removeAll(Collection<?> c) {
// return set.removeAll(c);
// }
//
// public <T> T[] toArray(T[] a) {
// return set.toArray(a);
// }
//
// public Iterator<E> iterator() {
// return set.iterator();
// }
//
// public int size() {
// return set.size();
// }
//
// public boolean isEmpty() {
// return set.isEmpty();
// }
//
// public boolean contains(Object o) {
// return set.contains(o);
// }
//
// public boolean add(E o) {
// return set.add(o);
// }
//
// public boolean remove(Object o) {
// return set.remove(o);
// }
//
// public void clear() {
// set.clear();
// }
//
// @Override
// public Object clone() {
// return set.clone();
// }
//
// public boolean containsAll(Collection<?> c) {
// return set.containsAll(c);
// }
//
// public boolean addAll(Collection<? extends E> c) {
// return set.addAll(c);
// }
//
// public boolean retainAll(Collection<?> c) {
// return set.retainAll(c);
// }
//
// @Override
// public String toString() {
// return set.toString();
// }
//
// @Override
// public boolean equals(Object obj) {
// if (this == obj) {
// return true;
// }
// if (obj == null || !getClass().equals(obj.getClass())) {
// return false;
// }
// return set.equals(obj);
// }
//
// @Override
// public int hashCode() {
// return 31 * 1 + ((set == null) ? 0 : set.hashCode());
// }
// }
| import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import java.util.AbstractCollection;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.Queue;
import java.util.Set;
import java.util.SortedSet;
import org.junit.Test;
import org.mockito.internal.util.MockUtil;
import org.mockito.mock.MockCreationSettings;
import uk.co.webamoeba.mockito.collections.util.OrderedSet; | package uk.co.webamoeba.mockito.collections.inject;
/**
* @author James Kennard
*/
@SuppressWarnings("unchecked")
public class CollectionFactoryTest {
private CollectionFactory factory = new CollectionFactory();
private MockUtil mockUtil = new MockUtil();
@Test
public void shouldCreateCollectionGivenCollection() {
shouldCreateCollection(Collection.class);
}
@Test
public void shouldCreateCollectionGivenCollectionAndContents() {
shouldCreateCollectionGivenContents(Collection.class);
}
@Test
public void shouldCreateCollectionGivenSortedSet() {
shouldCreateCollection(SortedSet.class);
}
@Test
public void shouldCreateCollectionGivenSortedSetAndContents() { | // Path: mockito-collections-core/src/main/java/uk/co/webamoeba/mockito/collections/util/OrderedSet.java
// public class OrderedSet<E> implements Set<E> {
//
// private LinkedHashSet<E> set;
//
// public OrderedSet() {
// this.set = new LinkedHashSet<E>();
// }
//
// public OrderedSet(Collection<E> set) {
// this.set = new LinkedHashSet<E>(set);
// }
//
// public OrderedSet(int initialCapacity) {
// this.set = new LinkedHashSet<E>(initialCapacity);
// }
//
// public Object[] toArray() {
// return set.toArray();
// }
//
// public boolean removeAll(Collection<?> c) {
// return set.removeAll(c);
// }
//
// public <T> T[] toArray(T[] a) {
// return set.toArray(a);
// }
//
// public Iterator<E> iterator() {
// return set.iterator();
// }
//
// public int size() {
// return set.size();
// }
//
// public boolean isEmpty() {
// return set.isEmpty();
// }
//
// public boolean contains(Object o) {
// return set.contains(o);
// }
//
// public boolean add(E o) {
// return set.add(o);
// }
//
// public boolean remove(Object o) {
// return set.remove(o);
// }
//
// public void clear() {
// set.clear();
// }
//
// @Override
// public Object clone() {
// return set.clone();
// }
//
// public boolean containsAll(Collection<?> c) {
// return set.containsAll(c);
// }
//
// public boolean addAll(Collection<? extends E> c) {
// return set.addAll(c);
// }
//
// public boolean retainAll(Collection<?> c) {
// return set.retainAll(c);
// }
//
// @Override
// public String toString() {
// return set.toString();
// }
//
// @Override
// public boolean equals(Object obj) {
// if (this == obj) {
// return true;
// }
// if (obj == null || !getClass().equals(obj.getClass())) {
// return false;
// }
// return set.equals(obj);
// }
//
// @Override
// public int hashCode() {
// return 31 * 1 + ((set == null) ? 0 : set.hashCode());
// }
// }
// Path: mockito-collections-core/src/test/java/uk/co/webamoeba/mockito/collections/inject/CollectionFactoryTest.java
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import java.util.AbstractCollection;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.Queue;
import java.util.Set;
import java.util.SortedSet;
import org.junit.Test;
import org.mockito.internal.util.MockUtil;
import org.mockito.mock.MockCreationSettings;
import uk.co.webamoeba.mockito.collections.util.OrderedSet;
package uk.co.webamoeba.mockito.collections.inject;
/**
* @author James Kennard
*/
@SuppressWarnings("unchecked")
public class CollectionFactoryTest {
private CollectionFactory factory = new CollectionFactory();
private MockUtil mockUtil = new MockUtil();
@Test
public void shouldCreateCollectionGivenCollection() {
shouldCreateCollection(Collection.class);
}
@Test
public void shouldCreateCollectionGivenCollectionAndContents() {
shouldCreateCollectionGivenContents(Collection.class);
}
@Test
public void shouldCreateCollectionGivenSortedSet() {
shouldCreateCollection(SortedSet.class);
}
@Test
public void shouldCreateCollectionGivenSortedSetAndContents() { | shouldCreateCollection(SortedSet.class, new OrderedSet<Object>(Arrays.<Object> asList("ABC", "DEF", "GHI"))); |
jameskennard/mockito-collections | mockito-collections-core/src/test/java/uk/co/webamoeba/mockito/collections/util/FieldValueMutatorTest.java | // Path: mockito-collections-core/src/main/java/uk/co/webamoeba/mockito/collections/exception/MockitoCollectionsException.java
// public class MockitoCollectionsException extends RuntimeException {
//
// private static final long serialVersionUID = 1L;
//
// public MockitoCollectionsException(String message, Throwable throwable) {
// super(message, throwable);
// }
//
// public MockitoCollectionsException(String message) {
// super(message);
// }
// }
| import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.mockito.Mockito.mock;
import java.lang.reflect.Field;
import java.util.Collection;
import org.junit.Test;
import uk.co.webamoeba.mockito.collections.exception.MockitoCollectionsException; | assertTrue(field.isAccessible());
}
@Test
public void shouldSetGivenPrivateField() {
// Given
Field field = getField("privateCollection");
FieldValueMutator mutator = new FieldValueMutator(support, field);
Object value = mock(Collection.class);
// When
mutator.mutateTo(value);
// Then
assertEquals(value, support.getPrivateCollection());
assertFalse(field.isAccessible());
}
@Test
public void shouldFailToSetGivenIncompatibleType() {
// Given
FieldValueMutator mutator = new FieldValueMutator(support, getField("privateCollection"));
Object value = 100L;
try {
// When
mutator.mutateTo(value);
// Then
fail(); | // Path: mockito-collections-core/src/main/java/uk/co/webamoeba/mockito/collections/exception/MockitoCollectionsException.java
// public class MockitoCollectionsException extends RuntimeException {
//
// private static final long serialVersionUID = 1L;
//
// public MockitoCollectionsException(String message, Throwable throwable) {
// super(message, throwable);
// }
//
// public MockitoCollectionsException(String message) {
// super(message);
// }
// }
// Path: mockito-collections-core/src/test/java/uk/co/webamoeba/mockito/collections/util/FieldValueMutatorTest.java
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.mockito.Mockito.mock;
import java.lang.reflect.Field;
import java.util.Collection;
import org.junit.Test;
import uk.co.webamoeba.mockito.collections.exception.MockitoCollectionsException;
assertTrue(field.isAccessible());
}
@Test
public void shouldSetGivenPrivateField() {
// Given
Field field = getField("privateCollection");
FieldValueMutator mutator = new FieldValueMutator(support, field);
Object value = mock(Collection.class);
// When
mutator.mutateTo(value);
// Then
assertEquals(value, support.getPrivateCollection());
assertFalse(field.isAccessible());
}
@Test
public void shouldFailToSetGivenIncompatibleType() {
// Given
FieldValueMutator mutator = new FieldValueMutator(support, getField("privateCollection"));
Object value = 100L;
try {
// When
mutator.mutateTo(value);
// Then
fail(); | } catch (MockitoCollectionsException e) { |
jameskennard/mockito-collections | mockito-collections-core/src/test/java/uk/co/webamoeba/mockito/collections/inject/InjectionDetailsTest.java | // Path: mockito-collections-core/src/main/java/uk/co/webamoeba/mockito/collections/util/OrderedSet.java
// public class OrderedSet<E> implements Set<E> {
//
// private LinkedHashSet<E> set;
//
// public OrderedSet() {
// this.set = new LinkedHashSet<E>();
// }
//
// public OrderedSet(Collection<E> set) {
// this.set = new LinkedHashSet<E>(set);
// }
//
// public OrderedSet(int initialCapacity) {
// this.set = new LinkedHashSet<E>(initialCapacity);
// }
//
// public Object[] toArray() {
// return set.toArray();
// }
//
// public boolean removeAll(Collection<?> c) {
// return set.removeAll(c);
// }
//
// public <T> T[] toArray(T[] a) {
// return set.toArray(a);
// }
//
// public Iterator<E> iterator() {
// return set.iterator();
// }
//
// public int size() {
// return set.size();
// }
//
// public boolean isEmpty() {
// return set.isEmpty();
// }
//
// public boolean contains(Object o) {
// return set.contains(o);
// }
//
// public boolean add(E o) {
// return set.add(o);
// }
//
// public boolean remove(Object o) {
// return set.remove(o);
// }
//
// public void clear() {
// set.clear();
// }
//
// @Override
// public Object clone() {
// return set.clone();
// }
//
// public boolean containsAll(Collection<?> c) {
// return set.containsAll(c);
// }
//
// public boolean addAll(Collection<? extends E> c) {
// return set.addAll(c);
// }
//
// public boolean retainAll(Collection<?> c) {
// return set.retainAll(c);
// }
//
// @Override
// public String toString() {
// return set.toString();
// }
//
// @Override
// public boolean equals(Object obj) {
// if (this == obj) {
// return true;
// }
// if (obj == null || !getClass().equals(obj.getClass())) {
// return false;
// }
// return set.equals(obj);
// }
//
// @Override
// public int hashCode() {
// return 31 * 1 + ((set == null) ? 0 : set.hashCode());
// }
// }
| import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
import java.util.Collections;
import java.util.Set;
import org.junit.Test;
import uk.co.webamoeba.mockito.collections.util.OrderedSet; | package uk.co.webamoeba.mockito.collections.inject;
/**
* @author James Kennard
*/
@SuppressWarnings("unchecked")
public class InjectionDetailsTest {
@Test
public void shouldGetInjectCollections() {
// Given
Object injectCollections = "Some InjectCollections";
Set<Object> setOfInjectCollections = Collections.singleton(injectCollections); | // Path: mockito-collections-core/src/main/java/uk/co/webamoeba/mockito/collections/util/OrderedSet.java
// public class OrderedSet<E> implements Set<E> {
//
// private LinkedHashSet<E> set;
//
// public OrderedSet() {
// this.set = new LinkedHashSet<E>();
// }
//
// public OrderedSet(Collection<E> set) {
// this.set = new LinkedHashSet<E>(set);
// }
//
// public OrderedSet(int initialCapacity) {
// this.set = new LinkedHashSet<E>(initialCapacity);
// }
//
// public Object[] toArray() {
// return set.toArray();
// }
//
// public boolean removeAll(Collection<?> c) {
// return set.removeAll(c);
// }
//
// public <T> T[] toArray(T[] a) {
// return set.toArray(a);
// }
//
// public Iterator<E> iterator() {
// return set.iterator();
// }
//
// public int size() {
// return set.size();
// }
//
// public boolean isEmpty() {
// return set.isEmpty();
// }
//
// public boolean contains(Object o) {
// return set.contains(o);
// }
//
// public boolean add(E o) {
// return set.add(o);
// }
//
// public boolean remove(Object o) {
// return set.remove(o);
// }
//
// public void clear() {
// set.clear();
// }
//
// @Override
// public Object clone() {
// return set.clone();
// }
//
// public boolean containsAll(Collection<?> c) {
// return set.containsAll(c);
// }
//
// public boolean addAll(Collection<? extends E> c) {
// return set.addAll(c);
// }
//
// public boolean retainAll(Collection<?> c) {
// return set.retainAll(c);
// }
//
// @Override
// public String toString() {
// return set.toString();
// }
//
// @Override
// public boolean equals(Object obj) {
// if (this == obj) {
// return true;
// }
// if (obj == null || !getClass().equals(obj.getClass())) {
// return false;
// }
// return set.equals(obj);
// }
//
// @Override
// public int hashCode() {
// return 31 * 1 + ((set == null) ? 0 : set.hashCode());
// }
// }
// Path: mockito-collections-core/src/test/java/uk/co/webamoeba/mockito/collections/inject/InjectionDetailsTest.java
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
import java.util.Collections;
import java.util.Set;
import org.junit.Test;
import uk.co.webamoeba.mockito.collections.util.OrderedSet;
package uk.co.webamoeba.mockito.collections.inject;
/**
* @author James Kennard
*/
@SuppressWarnings("unchecked")
public class InjectionDetailsTest {
@Test
public void shouldGetInjectCollections() {
// Given
Object injectCollections = "Some InjectCollections";
Set<Object> setOfInjectCollections = Collections.singleton(injectCollections); | OrderedSet<Object> mocks = new OrderedSet<Object>(); |
jameskennard/mockito-collections | mockito-collections-core/src/main/java/uk/co/webamoeba/mockito/collections/util/FieldValueMutator.java | // Path: mockito-collections-core/src/main/java/uk/co/webamoeba/mockito/collections/exception/MockitoCollectionsException.java
// public class MockitoCollectionsException extends RuntimeException {
//
// private static final long serialVersionUID = 1L;
//
// public MockitoCollectionsException(String message, Throwable throwable) {
// super(message, throwable);
// }
//
// public MockitoCollectionsException(String message) {
// super(message);
// }
// }
| import java.lang.reflect.Field;
import uk.co.webamoeba.mockito.collections.exception.MockitoCollectionsException; | package uk.co.webamoeba.mockito.collections.util;
/**
* Utility class that can be used to mutate the value of a field. <i>Based on Mockito's FieldSetter</i>.
*
* @author James Kennard
*/
public class FieldValueMutator {
private Object object;
private Field field;
public FieldValueMutator(Object object, Field field) {
this.object = object;
this.field = field;
}
public void mutateTo(Object value) {
boolean wasAccessible = field.isAccessible();
if (!wasAccessible) {
field.setAccessible(true);
}
try {
field.set(object, value);
} catch (IllegalAccessException e) { | // Path: mockito-collections-core/src/main/java/uk/co/webamoeba/mockito/collections/exception/MockitoCollectionsException.java
// public class MockitoCollectionsException extends RuntimeException {
//
// private static final long serialVersionUID = 1L;
//
// public MockitoCollectionsException(String message, Throwable throwable) {
// super(message, throwable);
// }
//
// public MockitoCollectionsException(String message) {
// super(message);
// }
// }
// Path: mockito-collections-core/src/main/java/uk/co/webamoeba/mockito/collections/util/FieldValueMutator.java
import java.lang.reflect.Field;
import uk.co.webamoeba.mockito.collections.exception.MockitoCollectionsException;
package uk.co.webamoeba.mockito.collections.util;
/**
* Utility class that can be used to mutate the value of a field. <i>Based on Mockito's FieldSetter</i>.
*
* @author James Kennard
*/
public class FieldValueMutator {
private Object object;
private Field field;
public FieldValueMutator(Object object, Field field) {
this.object = object;
this.field = field;
}
public void mutateTo(Object value) {
boolean wasAccessible = field.isAccessible();
if (!wasAccessible) {
field.setAccessible(true);
}
try {
field.set(object, value);
} catch (IllegalAccessException e) { | throw new MockitoCollectionsException("Could not set field '" + field + "' on object '" + object |
webinos/Webinos-Platform | webinos/platform/android/impl/src/org/webinos/impl/nfc/NfcManager.java | // Path: webinos/platform/android/impl/src/org/webinos/impl/nfc/NfcManager.java
// enum FilterType {
// UNKNOWN, TEXT, URI, MIME
// }
| import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import org.webinos.impl.nfc.NfcManager.NfcDiscoveryFilter.FilterType;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Parcelable; | super();
this.ctx = ctx;
ctx.registerReceiver(this, new IntentFilter(ACTION_DISPATCH_NFC));
}
static interface NfcDiscoveryListener {
void onTagDiscovered(Object tag);
}
private List<NfcDiscoveryListener> mListeners = new ArrayList<NfcDiscoveryListener>();
private Object mListenerLock = new Object();
public void addListener(NfcDiscoveryListener listener) {
synchronized (mListenerLock) {
if (!mListeners.contains(listener)) {
mListeners.add(listener);
}
}
}
public void removeListener(NfcDiscoveryListener listener) {
synchronized (mListenerLock) {
mListeners.remove(listener);
}
}
static final class NfcDiscoveryFilter implements Serializable {
private static final long serialVersionUID = 1L;
| // Path: webinos/platform/android/impl/src/org/webinos/impl/nfc/NfcManager.java
// enum FilterType {
// UNKNOWN, TEXT, URI, MIME
// }
// Path: webinos/platform/android/impl/src/org/webinos/impl/nfc/NfcManager.java
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import org.webinos.impl.nfc.NfcManager.NfcDiscoveryFilter.FilterType;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Parcelable;
super();
this.ctx = ctx;
ctx.registerReceiver(this, new IntentFilter(ACTION_DISPATCH_NFC));
}
static interface NfcDiscoveryListener {
void onTagDiscovered(Object tag);
}
private List<NfcDiscoveryListener> mListeners = new ArrayList<NfcDiscoveryListener>();
private Object mListenerLock = new Object();
public void addListener(NfcDiscoveryListener listener) {
synchronized (mListenerLock) {
if (!mListeners.contains(listener)) {
mListeners.add(listener);
}
}
}
public void removeListener(NfcDiscoveryListener listener) {
synchronized (mListenerLock) {
mListeners.remove(listener);
}
}
static final class NfcDiscoveryFilter implements Serializable {
private static final long serialVersionUID = 1L;
| enum FilterType { |
lihengming/java-codes | socket/src/main/java/rpc/RpcTest.java | // Path: socket/src/main/java/rpc/SimpleRpcFramework.java
// public static void export(Object serviceImpl, int port) {
// try {
// try (ServerSocket server = new ServerSocket(port)) {
// while (!Thread.currentThread().isInterrupted()) {
// Socket socket = server.accept();
// new Thread(() -> {
// try (ObjectInputStream in = new ObjectInputStream(socket.getInputStream())) {
// Method method = serviceImpl.getClass().getMethod(in.readUTF(), (Class<?>[]) in.readObject());
// Object result = method.invoke(serviceImpl, (Object[]) in.readObject());
// try (ObjectOutputStream out = new ObjectOutputStream(socket.getOutputStream())) {
// out.writeObject(result);
// }
// System.out.println("Invoke method [" + method.getName() + "()] success, form " + socket.getRemoteSocketAddress());
// } catch (Exception e) {
// throw new RuntimeException("Export service fail .", e);
// }
// }).start();
// }
// }
// } catch (Exception e) {
// throw new RuntimeException("Export service fail .", e);
// }
// System.out.println("Export service " + serviceImpl.getClass().getSimpleName() + " success on port " + port);
// }
//
// Path: socket/src/main/java/rpc/SimpleRpcFramework.java
// public static <T> T use(Class<T> serviceInterface, String host, int port) {
// System.out.println(String.format("Use remote service [%s] from [%s:%s]", serviceInterface.getSimpleName(), host, port));
// return (T) Proxy.newProxyInstance(serviceInterface.getClassLoader(), new Class<?>[]{serviceInterface}, (proxy, method, args) -> {
// try (Socket socket = new Socket(host, port)) {
// try (ObjectOutputStream out = new ObjectOutputStream(socket.getOutputStream())) {
// out.writeUTF(method.getName());
// out.writeObject(method.getParameterTypes());
// out.writeObject(args);
// try (ObjectInputStream in = new ObjectInputStream(socket.getInputStream())) {
// return in.readObject();
// }
// }
// }
// });
// }
| import java.util.concurrent.TimeUnit;
import static rpc.SimpleRpcFramework.export;
import static rpc.SimpleRpcFramework.use; | package rpc;
/**
* Created by 李恒名 on 2017/8/17.
*/
public class RpcTest {
private static final String HOST = "localhost";
private static final int PORT = 8888;
interface ComputeService {
int sum(int a, int b);
}
static class ComputeServiceImpl implements ComputeService {
@Override
public int sum(int a, int b) {
return a + b;
}
}
//服务提供者
static class Provider implements Runnable {
@Override
public void run() {
//暴露服务 | // Path: socket/src/main/java/rpc/SimpleRpcFramework.java
// public static void export(Object serviceImpl, int port) {
// try {
// try (ServerSocket server = new ServerSocket(port)) {
// while (!Thread.currentThread().isInterrupted()) {
// Socket socket = server.accept();
// new Thread(() -> {
// try (ObjectInputStream in = new ObjectInputStream(socket.getInputStream())) {
// Method method = serviceImpl.getClass().getMethod(in.readUTF(), (Class<?>[]) in.readObject());
// Object result = method.invoke(serviceImpl, (Object[]) in.readObject());
// try (ObjectOutputStream out = new ObjectOutputStream(socket.getOutputStream())) {
// out.writeObject(result);
// }
// System.out.println("Invoke method [" + method.getName() + "()] success, form " + socket.getRemoteSocketAddress());
// } catch (Exception e) {
// throw new RuntimeException("Export service fail .", e);
// }
// }).start();
// }
// }
// } catch (Exception e) {
// throw new RuntimeException("Export service fail .", e);
// }
// System.out.println("Export service " + serviceImpl.getClass().getSimpleName() + " success on port " + port);
// }
//
// Path: socket/src/main/java/rpc/SimpleRpcFramework.java
// public static <T> T use(Class<T> serviceInterface, String host, int port) {
// System.out.println(String.format("Use remote service [%s] from [%s:%s]", serviceInterface.getSimpleName(), host, port));
// return (T) Proxy.newProxyInstance(serviceInterface.getClassLoader(), new Class<?>[]{serviceInterface}, (proxy, method, args) -> {
// try (Socket socket = new Socket(host, port)) {
// try (ObjectOutputStream out = new ObjectOutputStream(socket.getOutputStream())) {
// out.writeUTF(method.getName());
// out.writeObject(method.getParameterTypes());
// out.writeObject(args);
// try (ObjectInputStream in = new ObjectInputStream(socket.getInputStream())) {
// return in.readObject();
// }
// }
// }
// });
// }
// Path: socket/src/main/java/rpc/RpcTest.java
import java.util.concurrent.TimeUnit;
import static rpc.SimpleRpcFramework.export;
import static rpc.SimpleRpcFramework.use;
package rpc;
/**
* Created by 李恒名 on 2017/8/17.
*/
public class RpcTest {
private static final String HOST = "localhost";
private static final int PORT = 8888;
interface ComputeService {
int sum(int a, int b);
}
static class ComputeServiceImpl implements ComputeService {
@Override
public int sum(int a, int b) {
return a + b;
}
}
//服务提供者
static class Provider implements Runnable {
@Override
public void run() {
//暴露服务 | export(new ComputeServiceImpl(), PORT); |
lihengming/java-codes | socket/src/main/java/rpc/RpcTest.java | // Path: socket/src/main/java/rpc/SimpleRpcFramework.java
// public static void export(Object serviceImpl, int port) {
// try {
// try (ServerSocket server = new ServerSocket(port)) {
// while (!Thread.currentThread().isInterrupted()) {
// Socket socket = server.accept();
// new Thread(() -> {
// try (ObjectInputStream in = new ObjectInputStream(socket.getInputStream())) {
// Method method = serviceImpl.getClass().getMethod(in.readUTF(), (Class<?>[]) in.readObject());
// Object result = method.invoke(serviceImpl, (Object[]) in.readObject());
// try (ObjectOutputStream out = new ObjectOutputStream(socket.getOutputStream())) {
// out.writeObject(result);
// }
// System.out.println("Invoke method [" + method.getName() + "()] success, form " + socket.getRemoteSocketAddress());
// } catch (Exception e) {
// throw new RuntimeException("Export service fail .", e);
// }
// }).start();
// }
// }
// } catch (Exception e) {
// throw new RuntimeException("Export service fail .", e);
// }
// System.out.println("Export service " + serviceImpl.getClass().getSimpleName() + " success on port " + port);
// }
//
// Path: socket/src/main/java/rpc/SimpleRpcFramework.java
// public static <T> T use(Class<T> serviceInterface, String host, int port) {
// System.out.println(String.format("Use remote service [%s] from [%s:%s]", serviceInterface.getSimpleName(), host, port));
// return (T) Proxy.newProxyInstance(serviceInterface.getClassLoader(), new Class<?>[]{serviceInterface}, (proxy, method, args) -> {
// try (Socket socket = new Socket(host, port)) {
// try (ObjectOutputStream out = new ObjectOutputStream(socket.getOutputStream())) {
// out.writeUTF(method.getName());
// out.writeObject(method.getParameterTypes());
// out.writeObject(args);
// try (ObjectInputStream in = new ObjectInputStream(socket.getInputStream())) {
// return in.readObject();
// }
// }
// }
// });
// }
| import java.util.concurrent.TimeUnit;
import static rpc.SimpleRpcFramework.export;
import static rpc.SimpleRpcFramework.use; | package rpc;
/**
* Created by 李恒名 on 2017/8/17.
*/
public class RpcTest {
private static final String HOST = "localhost";
private static final int PORT = 8888;
interface ComputeService {
int sum(int a, int b);
}
static class ComputeServiceImpl implements ComputeService {
@Override
public int sum(int a, int b) {
return a + b;
}
}
//服务提供者
static class Provider implements Runnable {
@Override
public void run() {
//暴露服务
export(new ComputeServiceImpl(), PORT);
}
}
//服务消费者
static class Customer implements Runnable {
@Override
public void run() {
//使用服务 | // Path: socket/src/main/java/rpc/SimpleRpcFramework.java
// public static void export(Object serviceImpl, int port) {
// try {
// try (ServerSocket server = new ServerSocket(port)) {
// while (!Thread.currentThread().isInterrupted()) {
// Socket socket = server.accept();
// new Thread(() -> {
// try (ObjectInputStream in = new ObjectInputStream(socket.getInputStream())) {
// Method method = serviceImpl.getClass().getMethod(in.readUTF(), (Class<?>[]) in.readObject());
// Object result = method.invoke(serviceImpl, (Object[]) in.readObject());
// try (ObjectOutputStream out = new ObjectOutputStream(socket.getOutputStream())) {
// out.writeObject(result);
// }
// System.out.println("Invoke method [" + method.getName() + "()] success, form " + socket.getRemoteSocketAddress());
// } catch (Exception e) {
// throw new RuntimeException("Export service fail .", e);
// }
// }).start();
// }
// }
// } catch (Exception e) {
// throw new RuntimeException("Export service fail .", e);
// }
// System.out.println("Export service " + serviceImpl.getClass().getSimpleName() + " success on port " + port);
// }
//
// Path: socket/src/main/java/rpc/SimpleRpcFramework.java
// public static <T> T use(Class<T> serviceInterface, String host, int port) {
// System.out.println(String.format("Use remote service [%s] from [%s:%s]", serviceInterface.getSimpleName(), host, port));
// return (T) Proxy.newProxyInstance(serviceInterface.getClassLoader(), new Class<?>[]{serviceInterface}, (proxy, method, args) -> {
// try (Socket socket = new Socket(host, port)) {
// try (ObjectOutputStream out = new ObjectOutputStream(socket.getOutputStream())) {
// out.writeUTF(method.getName());
// out.writeObject(method.getParameterTypes());
// out.writeObject(args);
// try (ObjectInputStream in = new ObjectInputStream(socket.getInputStream())) {
// return in.readObject();
// }
// }
// }
// });
// }
// Path: socket/src/main/java/rpc/RpcTest.java
import java.util.concurrent.TimeUnit;
import static rpc.SimpleRpcFramework.export;
import static rpc.SimpleRpcFramework.use;
package rpc;
/**
* Created by 李恒名 on 2017/8/17.
*/
public class RpcTest {
private static final String HOST = "localhost";
private static final int PORT = 8888;
interface ComputeService {
int sum(int a, int b);
}
static class ComputeServiceImpl implements ComputeService {
@Override
public int sum(int a, int b) {
return a + b;
}
}
//服务提供者
static class Provider implements Runnable {
@Override
public void run() {
//暴露服务
export(new ComputeServiceImpl(), PORT);
}
}
//服务消费者
static class Customer implements Runnable {
@Override
public void run() {
//使用服务 | ComputeService computeService = use(ComputeService.class, HOST, PORT); |
aredee/accumulo-mesos | accumulo-mesos-executor/src/main/java/aredee/mesos/frameworks/accumulo/executor/Main.java | // Path: accumulo-mesos-common/src/main/java/aredee/mesos/frameworks/accumulo/configuration/Environment.java
// public class Environment {
//
// public static final String JAVA_HOME = "JAVA_HOME";
//
// public static final String CLASSPATH = "CLASSPATH";
//
// public static final String HADOOP_PREFIX = "HADOOP_PREFIX";
// public static final String HADOOP_CONF_DIR = "HADOOP_CONF_DIR";
// public static final String HADOOP_HOME = "HADOOP_HOME";
//
// public static final String ACCUMULO_HOME = "ACCUMULO_HOME";
// public static final String ACCUMULO_LOG_DIR = "ACCUMULO_LOG_DIR";
// public static final String ACCUMULO_CLIENT_CONF_PATH = "ACCUMULO_CLIENT_CONF_PATH";
// public static final String ACCUMULO_CONF_DIR = "ACCUMULO_CONF_DIR";
// public static final String ACCUMULO_WALOG = "ACCUMULO_WALOG";
//
// public static final String LD_LIBRARY_PATH = "LD_LIBRARY_PATH";
// public static final String DYLD_LIBRARY_PATH = "DYLD_LIBRARY_PATH";
//
// // List of paths separated by commas
// public static final String NATIVE_LIB_PATHS = "NATIVE_LIB_PATHS";
//
// public static final String ZOOKEEPER_HOME = "ZOOKEEPER_HOME";
//
// public static final String MESOS_DIRECTORY = "MESOS_DIRECTORY";
//
// public static final List<String> REQUIRED_FRAMEWORK_VARS = Arrays.asList(
// JAVA_HOME,
// ACCUMULO_HOME,
// HADOOP_PREFIX,
// HADOOP_CONF_DIR,
// ZOOKEEPER_HOME);
//
// public static final List<String> REQUIRED_EXECUTOR_VARS = Arrays.asList(
// JAVA_HOME,
// ACCUMULO_HOME,
// HADOOP_PREFIX,
// ZOOKEEPER_HOME,
// ACCUMULO_LOG_DIR);
//
//
// /*
// Optional Accumulo vars for executor
// */
// public static final String ACCUMULO_XTRAJARS = "ACCUMULO_XTRAJARS";
// public static final String ACCUMULO_GENERAL_OPTS = "ACCUMULO_GENERAL_OPTS";
// public static final String ACCUMULO_JAAS_CONF = "ACCUMULO_JAAS_CONF"; //-Djava.security.auth.login.config=${ACCUMULO_JAAS_CONF}
// public static final String ACCUMULO_KRB5_CONF = "ACCUMULO_KRB5_CONF"; //-Djava.security.krb5.conf=${ACCUMULO_KRB5_CONF}
//
// public static final String ACCUMULO_MASTER_OPTS = "ACCUMULO_MASTER_OPTS";
// public static final String ACCUMULO_GC_OPTS = "ACCUMULO_GC_OPTS";
// public static final String ACCUMULO_TSERVER_OPTS = "ACCUMULO_TSERVER_OPTS";
// public static final String ACCUMULO_MONITOR_OPTS = "ACCUMULO_MONITOR_OPTS";
// public static final String ACCUMULO_LOGGER_OPTS = "ACCUMULO_LOGGER_OPTS";
// public static final String ACCUMULO_OTHER_OPTS = "ACCUMULO_OTHER_OPTS";
// public static final String ACCUMULO_KILL_CMD = "ACCUMULO_KILL_CMD";
//
// // generated
// public static final String START_JAR = "START_JAR";
// public static final String LIB_PATH = "LIB_PATH";
// /*
// if [ -e "${HADOOP_PREFIX}/lib/native/libhadoop.so" ]; then
// LIB_PATH="${HADOOP_PREFIX}/lib/native"
// LD_LIBRARY_PATH="${LIB_PATH}:${LD_LIBRARY_PATH}" # For Linux
// DYLD_LIBRARY_PATH="${LIB_PATH}:${DYLD_LIBRARY_PATH}" # For Mac
// fi
// */
//
//
// public static List<String> getMissingVariables(List<String> vars) {
// List<String> missingVariables = new ArrayList<>();
// Set<String> envKeys = System.getenv().keySet();
// for(String var : vars ) {
// if(!envKeys.contains(var)){
// missingVariables.add(var);
// }
// }
// return missingVariables;
// }
//
// public static String get(String var){
// return System.getenv(var);
// }
//
// }
| import aredee.mesos.frameworks.accumulo.configuration.Environment;
import org.apache.mesos.ExecutorDriver;
import org.apache.mesos.MesosExecutorDriver;
import org.apache.mesos.Protos;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.List; | package aredee.mesos.frameworks.accumulo.executor;
public class Main {
private static final Logger LOGGER = LoggerFactory.getLogger(Main.class);
public static void main(String[] args){
//TODO Should executors have REST API?
// TODO check for required environment variables | // Path: accumulo-mesos-common/src/main/java/aredee/mesos/frameworks/accumulo/configuration/Environment.java
// public class Environment {
//
// public static final String JAVA_HOME = "JAVA_HOME";
//
// public static final String CLASSPATH = "CLASSPATH";
//
// public static final String HADOOP_PREFIX = "HADOOP_PREFIX";
// public static final String HADOOP_CONF_DIR = "HADOOP_CONF_DIR";
// public static final String HADOOP_HOME = "HADOOP_HOME";
//
// public static final String ACCUMULO_HOME = "ACCUMULO_HOME";
// public static final String ACCUMULO_LOG_DIR = "ACCUMULO_LOG_DIR";
// public static final String ACCUMULO_CLIENT_CONF_PATH = "ACCUMULO_CLIENT_CONF_PATH";
// public static final String ACCUMULO_CONF_DIR = "ACCUMULO_CONF_DIR";
// public static final String ACCUMULO_WALOG = "ACCUMULO_WALOG";
//
// public static final String LD_LIBRARY_PATH = "LD_LIBRARY_PATH";
// public static final String DYLD_LIBRARY_PATH = "DYLD_LIBRARY_PATH";
//
// // List of paths separated by commas
// public static final String NATIVE_LIB_PATHS = "NATIVE_LIB_PATHS";
//
// public static final String ZOOKEEPER_HOME = "ZOOKEEPER_HOME";
//
// public static final String MESOS_DIRECTORY = "MESOS_DIRECTORY";
//
// public static final List<String> REQUIRED_FRAMEWORK_VARS = Arrays.asList(
// JAVA_HOME,
// ACCUMULO_HOME,
// HADOOP_PREFIX,
// HADOOP_CONF_DIR,
// ZOOKEEPER_HOME);
//
// public static final List<String> REQUIRED_EXECUTOR_VARS = Arrays.asList(
// JAVA_HOME,
// ACCUMULO_HOME,
// HADOOP_PREFIX,
// ZOOKEEPER_HOME,
// ACCUMULO_LOG_DIR);
//
//
// /*
// Optional Accumulo vars for executor
// */
// public static final String ACCUMULO_XTRAJARS = "ACCUMULO_XTRAJARS";
// public static final String ACCUMULO_GENERAL_OPTS = "ACCUMULO_GENERAL_OPTS";
// public static final String ACCUMULO_JAAS_CONF = "ACCUMULO_JAAS_CONF"; //-Djava.security.auth.login.config=${ACCUMULO_JAAS_CONF}
// public static final String ACCUMULO_KRB5_CONF = "ACCUMULO_KRB5_CONF"; //-Djava.security.krb5.conf=${ACCUMULO_KRB5_CONF}
//
// public static final String ACCUMULO_MASTER_OPTS = "ACCUMULO_MASTER_OPTS";
// public static final String ACCUMULO_GC_OPTS = "ACCUMULO_GC_OPTS";
// public static final String ACCUMULO_TSERVER_OPTS = "ACCUMULO_TSERVER_OPTS";
// public static final String ACCUMULO_MONITOR_OPTS = "ACCUMULO_MONITOR_OPTS";
// public static final String ACCUMULO_LOGGER_OPTS = "ACCUMULO_LOGGER_OPTS";
// public static final String ACCUMULO_OTHER_OPTS = "ACCUMULO_OTHER_OPTS";
// public static final String ACCUMULO_KILL_CMD = "ACCUMULO_KILL_CMD";
//
// // generated
// public static final String START_JAR = "START_JAR";
// public static final String LIB_PATH = "LIB_PATH";
// /*
// if [ -e "${HADOOP_PREFIX}/lib/native/libhadoop.so" ]; then
// LIB_PATH="${HADOOP_PREFIX}/lib/native"
// LD_LIBRARY_PATH="${LIB_PATH}:${LD_LIBRARY_PATH}" # For Linux
// DYLD_LIBRARY_PATH="${LIB_PATH}:${DYLD_LIBRARY_PATH}" # For Mac
// fi
// */
//
//
// public static List<String> getMissingVariables(List<String> vars) {
// List<String> missingVariables = new ArrayList<>();
// Set<String> envKeys = System.getenv().keySet();
// for(String var : vars ) {
// if(!envKeys.contains(var)){
// missingVariables.add(var);
// }
// }
// return missingVariables;
// }
//
// public static String get(String var){
// return System.getenv(var);
// }
//
// }
// Path: accumulo-mesos-executor/src/main/java/aredee/mesos/frameworks/accumulo/executor/Main.java
import aredee.mesos.frameworks.accumulo.configuration.Environment;
import org.apache.mesos.ExecutorDriver;
import org.apache.mesos.MesosExecutorDriver;
import org.apache.mesos.Protos;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.List;
package aredee.mesos.frameworks.accumulo.executor;
public class Main {
private static final Logger LOGGER = LoggerFactory.getLogger(Main.class);
public static void main(String[] args){
//TODO Should executors have REST API?
// TODO check for required environment variables | List<String> missingVars = Environment.getMissingVariables(Environment.REQUIRED_EXECUTOR_VARS); |
aredee/accumulo-mesos | accumulo-mesos-framework/src/main/java/aredee/mesos/frameworks/accumulo/framework/api/ApiServiceFactory.java | // Path: accumulo-mesos-framework/src/main/java/aredee/mesos/frameworks/accumulo/framework/api/impl/ClusterApiServiceImpl.java
// public class ClusterApiServiceImpl extends ClusterApiService {
//
// Cluster cluster = Cluster.INSTANCE;
//
// @Override
// public Response clusterKillPost() throws NotFoundException {
// return null;
// }
//
// @Override
// public Response clusterMasterReprovisionPost() throws NotFoundException {
// return null;
// }
//
// @Override
// public Response clusterMasterRestartPost() throws NotFoundException {
// return null;
// }
//
// @Override
// public Response clusterMonitorGet() throws NotFoundException {
// return null;
// }
//
// @Override
// public Response clusterStartPost() throws NotFoundException {
// return null;
// }
//
// @Override
// public Response clusterStopPost() throws NotFoundException {
// return null;
// }
//
// @Override
// public Response clusterTserverReprovisionPost(String id) throws NotFoundException {
// return null;
// }
//
// @Override
// public Response clusterTserverRestartPost(String id) throws NotFoundException {
// return null;
// }
//
// @Override
// public Response clusterTserverRollingrestartPost(Boolean master, Integer group, Boolean reprovision) throws NotFoundException {
// return null;
// }
// }
//
// Path: accumulo-mesos-framework/src/main/java/aredee/mesos/frameworks/accumulo/framework/api/impl/ConfigApiServiceImpl.java
// public class ConfigApiServiceImpl extends ConfigApiService {
//
// Cluster cluster = Cluster.INSTANCE;
//
// @Override
// public Response configGet() throws NotFoundException {
// return null;
// }
// }
//
// Path: accumulo-mesos-framework/src/main/java/aredee/mesos/frameworks/accumulo/framework/api/impl/DefaultApiServiceImpl.java
// public class DefaultApiServiceImpl extends DefaultApiService {
//
// Cluster cluster = Cluster.INSTANCE;
//
// @Override
// public Response rootGet() throws NotFoundException {
// return null;
// }
// }
//
// Path: accumulo-mesos-framework/src/main/java/aredee/mesos/frameworks/accumulo/framework/api/impl/StatusApiServiceImpl.java
// public class StatusApiServiceImpl extends StatusApiService {
//
// Cluster cluster = Cluster.INSTANCE;
//
// @Override
// public Response statusGet() throws NotFoundException {
// return null;
// }
//
// }
| import aredee.mesos.frameworks.accumulo.framework.api.impl.ClusterApiServiceImpl;
import aredee.mesos.frameworks.accumulo.framework.api.impl.ConfigApiServiceImpl;
import aredee.mesos.frameworks.accumulo.framework.api.impl.DefaultApiServiceImpl;
import aredee.mesos.frameworks.accumulo.framework.api.impl.StatusApiServiceImpl; | package aredee.mesos.frameworks.accumulo.framework.api;
public final class ApiServiceFactory {
public static final ClusterApiService getClusterApi(){ | // Path: accumulo-mesos-framework/src/main/java/aredee/mesos/frameworks/accumulo/framework/api/impl/ClusterApiServiceImpl.java
// public class ClusterApiServiceImpl extends ClusterApiService {
//
// Cluster cluster = Cluster.INSTANCE;
//
// @Override
// public Response clusterKillPost() throws NotFoundException {
// return null;
// }
//
// @Override
// public Response clusterMasterReprovisionPost() throws NotFoundException {
// return null;
// }
//
// @Override
// public Response clusterMasterRestartPost() throws NotFoundException {
// return null;
// }
//
// @Override
// public Response clusterMonitorGet() throws NotFoundException {
// return null;
// }
//
// @Override
// public Response clusterStartPost() throws NotFoundException {
// return null;
// }
//
// @Override
// public Response clusterStopPost() throws NotFoundException {
// return null;
// }
//
// @Override
// public Response clusterTserverReprovisionPost(String id) throws NotFoundException {
// return null;
// }
//
// @Override
// public Response clusterTserverRestartPost(String id) throws NotFoundException {
// return null;
// }
//
// @Override
// public Response clusterTserverRollingrestartPost(Boolean master, Integer group, Boolean reprovision) throws NotFoundException {
// return null;
// }
// }
//
// Path: accumulo-mesos-framework/src/main/java/aredee/mesos/frameworks/accumulo/framework/api/impl/ConfigApiServiceImpl.java
// public class ConfigApiServiceImpl extends ConfigApiService {
//
// Cluster cluster = Cluster.INSTANCE;
//
// @Override
// public Response configGet() throws NotFoundException {
// return null;
// }
// }
//
// Path: accumulo-mesos-framework/src/main/java/aredee/mesos/frameworks/accumulo/framework/api/impl/DefaultApiServiceImpl.java
// public class DefaultApiServiceImpl extends DefaultApiService {
//
// Cluster cluster = Cluster.INSTANCE;
//
// @Override
// public Response rootGet() throws NotFoundException {
// return null;
// }
// }
//
// Path: accumulo-mesos-framework/src/main/java/aredee/mesos/frameworks/accumulo/framework/api/impl/StatusApiServiceImpl.java
// public class StatusApiServiceImpl extends StatusApiService {
//
// Cluster cluster = Cluster.INSTANCE;
//
// @Override
// public Response statusGet() throws NotFoundException {
// return null;
// }
//
// }
// Path: accumulo-mesos-framework/src/main/java/aredee/mesos/frameworks/accumulo/framework/api/ApiServiceFactory.java
import aredee.mesos.frameworks.accumulo.framework.api.impl.ClusterApiServiceImpl;
import aredee.mesos.frameworks.accumulo.framework.api.impl.ConfigApiServiceImpl;
import aredee.mesos.frameworks.accumulo.framework.api.impl.DefaultApiServiceImpl;
import aredee.mesos.frameworks.accumulo.framework.api.impl.StatusApiServiceImpl;
package aredee.mesos.frameworks.accumulo.framework.api;
public final class ApiServiceFactory {
public static final ClusterApiService getClusterApi(){ | return new ClusterApiServiceImpl(); |
aredee/accumulo-mesos | accumulo-mesos-framework/src/main/java/aredee/mesos/frameworks/accumulo/framework/api/ApiServiceFactory.java | // Path: accumulo-mesos-framework/src/main/java/aredee/mesos/frameworks/accumulo/framework/api/impl/ClusterApiServiceImpl.java
// public class ClusterApiServiceImpl extends ClusterApiService {
//
// Cluster cluster = Cluster.INSTANCE;
//
// @Override
// public Response clusterKillPost() throws NotFoundException {
// return null;
// }
//
// @Override
// public Response clusterMasterReprovisionPost() throws NotFoundException {
// return null;
// }
//
// @Override
// public Response clusterMasterRestartPost() throws NotFoundException {
// return null;
// }
//
// @Override
// public Response clusterMonitorGet() throws NotFoundException {
// return null;
// }
//
// @Override
// public Response clusterStartPost() throws NotFoundException {
// return null;
// }
//
// @Override
// public Response clusterStopPost() throws NotFoundException {
// return null;
// }
//
// @Override
// public Response clusterTserverReprovisionPost(String id) throws NotFoundException {
// return null;
// }
//
// @Override
// public Response clusterTserverRestartPost(String id) throws NotFoundException {
// return null;
// }
//
// @Override
// public Response clusterTserverRollingrestartPost(Boolean master, Integer group, Boolean reprovision) throws NotFoundException {
// return null;
// }
// }
//
// Path: accumulo-mesos-framework/src/main/java/aredee/mesos/frameworks/accumulo/framework/api/impl/ConfigApiServiceImpl.java
// public class ConfigApiServiceImpl extends ConfigApiService {
//
// Cluster cluster = Cluster.INSTANCE;
//
// @Override
// public Response configGet() throws NotFoundException {
// return null;
// }
// }
//
// Path: accumulo-mesos-framework/src/main/java/aredee/mesos/frameworks/accumulo/framework/api/impl/DefaultApiServiceImpl.java
// public class DefaultApiServiceImpl extends DefaultApiService {
//
// Cluster cluster = Cluster.INSTANCE;
//
// @Override
// public Response rootGet() throws NotFoundException {
// return null;
// }
// }
//
// Path: accumulo-mesos-framework/src/main/java/aredee/mesos/frameworks/accumulo/framework/api/impl/StatusApiServiceImpl.java
// public class StatusApiServiceImpl extends StatusApiService {
//
// Cluster cluster = Cluster.INSTANCE;
//
// @Override
// public Response statusGet() throws NotFoundException {
// return null;
// }
//
// }
| import aredee.mesos.frameworks.accumulo.framework.api.impl.ClusterApiServiceImpl;
import aredee.mesos.frameworks.accumulo.framework.api.impl.ConfigApiServiceImpl;
import aredee.mesos.frameworks.accumulo.framework.api.impl.DefaultApiServiceImpl;
import aredee.mesos.frameworks.accumulo.framework.api.impl.StatusApiServiceImpl; | package aredee.mesos.frameworks.accumulo.framework.api;
public final class ApiServiceFactory {
public static final ClusterApiService getClusterApi(){
return new ClusterApiServiceImpl();
}
public static final ConfigApiService getConfigApi(){ | // Path: accumulo-mesos-framework/src/main/java/aredee/mesos/frameworks/accumulo/framework/api/impl/ClusterApiServiceImpl.java
// public class ClusterApiServiceImpl extends ClusterApiService {
//
// Cluster cluster = Cluster.INSTANCE;
//
// @Override
// public Response clusterKillPost() throws NotFoundException {
// return null;
// }
//
// @Override
// public Response clusterMasterReprovisionPost() throws NotFoundException {
// return null;
// }
//
// @Override
// public Response clusterMasterRestartPost() throws NotFoundException {
// return null;
// }
//
// @Override
// public Response clusterMonitorGet() throws NotFoundException {
// return null;
// }
//
// @Override
// public Response clusterStartPost() throws NotFoundException {
// return null;
// }
//
// @Override
// public Response clusterStopPost() throws NotFoundException {
// return null;
// }
//
// @Override
// public Response clusterTserverReprovisionPost(String id) throws NotFoundException {
// return null;
// }
//
// @Override
// public Response clusterTserverRestartPost(String id) throws NotFoundException {
// return null;
// }
//
// @Override
// public Response clusterTserverRollingrestartPost(Boolean master, Integer group, Boolean reprovision) throws NotFoundException {
// return null;
// }
// }
//
// Path: accumulo-mesos-framework/src/main/java/aredee/mesos/frameworks/accumulo/framework/api/impl/ConfigApiServiceImpl.java
// public class ConfigApiServiceImpl extends ConfigApiService {
//
// Cluster cluster = Cluster.INSTANCE;
//
// @Override
// public Response configGet() throws NotFoundException {
// return null;
// }
// }
//
// Path: accumulo-mesos-framework/src/main/java/aredee/mesos/frameworks/accumulo/framework/api/impl/DefaultApiServiceImpl.java
// public class DefaultApiServiceImpl extends DefaultApiService {
//
// Cluster cluster = Cluster.INSTANCE;
//
// @Override
// public Response rootGet() throws NotFoundException {
// return null;
// }
// }
//
// Path: accumulo-mesos-framework/src/main/java/aredee/mesos/frameworks/accumulo/framework/api/impl/StatusApiServiceImpl.java
// public class StatusApiServiceImpl extends StatusApiService {
//
// Cluster cluster = Cluster.INSTANCE;
//
// @Override
// public Response statusGet() throws NotFoundException {
// return null;
// }
//
// }
// Path: accumulo-mesos-framework/src/main/java/aredee/mesos/frameworks/accumulo/framework/api/ApiServiceFactory.java
import aredee.mesos.frameworks.accumulo.framework.api.impl.ClusterApiServiceImpl;
import aredee.mesos.frameworks.accumulo.framework.api.impl.ConfigApiServiceImpl;
import aredee.mesos.frameworks.accumulo.framework.api.impl.DefaultApiServiceImpl;
import aredee.mesos.frameworks.accumulo.framework.api.impl.StatusApiServiceImpl;
package aredee.mesos.frameworks.accumulo.framework.api;
public final class ApiServiceFactory {
public static final ClusterApiService getClusterApi(){
return new ClusterApiServiceImpl();
}
public static final ConfigApiService getConfigApi(){ | return new ConfigApiServiceImpl(); |
aredee/accumulo-mesos | accumulo-mesos-framework/src/main/java/aredee/mesos/frameworks/accumulo/framework/api/ApiServiceFactory.java | // Path: accumulo-mesos-framework/src/main/java/aredee/mesos/frameworks/accumulo/framework/api/impl/ClusterApiServiceImpl.java
// public class ClusterApiServiceImpl extends ClusterApiService {
//
// Cluster cluster = Cluster.INSTANCE;
//
// @Override
// public Response clusterKillPost() throws NotFoundException {
// return null;
// }
//
// @Override
// public Response clusterMasterReprovisionPost() throws NotFoundException {
// return null;
// }
//
// @Override
// public Response clusterMasterRestartPost() throws NotFoundException {
// return null;
// }
//
// @Override
// public Response clusterMonitorGet() throws NotFoundException {
// return null;
// }
//
// @Override
// public Response clusterStartPost() throws NotFoundException {
// return null;
// }
//
// @Override
// public Response clusterStopPost() throws NotFoundException {
// return null;
// }
//
// @Override
// public Response clusterTserverReprovisionPost(String id) throws NotFoundException {
// return null;
// }
//
// @Override
// public Response clusterTserverRestartPost(String id) throws NotFoundException {
// return null;
// }
//
// @Override
// public Response clusterTserverRollingrestartPost(Boolean master, Integer group, Boolean reprovision) throws NotFoundException {
// return null;
// }
// }
//
// Path: accumulo-mesos-framework/src/main/java/aredee/mesos/frameworks/accumulo/framework/api/impl/ConfigApiServiceImpl.java
// public class ConfigApiServiceImpl extends ConfigApiService {
//
// Cluster cluster = Cluster.INSTANCE;
//
// @Override
// public Response configGet() throws NotFoundException {
// return null;
// }
// }
//
// Path: accumulo-mesos-framework/src/main/java/aredee/mesos/frameworks/accumulo/framework/api/impl/DefaultApiServiceImpl.java
// public class DefaultApiServiceImpl extends DefaultApiService {
//
// Cluster cluster = Cluster.INSTANCE;
//
// @Override
// public Response rootGet() throws NotFoundException {
// return null;
// }
// }
//
// Path: accumulo-mesos-framework/src/main/java/aredee/mesos/frameworks/accumulo/framework/api/impl/StatusApiServiceImpl.java
// public class StatusApiServiceImpl extends StatusApiService {
//
// Cluster cluster = Cluster.INSTANCE;
//
// @Override
// public Response statusGet() throws NotFoundException {
// return null;
// }
//
// }
| import aredee.mesos.frameworks.accumulo.framework.api.impl.ClusterApiServiceImpl;
import aredee.mesos.frameworks.accumulo.framework.api.impl.ConfigApiServiceImpl;
import aredee.mesos.frameworks.accumulo.framework.api.impl.DefaultApiServiceImpl;
import aredee.mesos.frameworks.accumulo.framework.api.impl.StatusApiServiceImpl; | package aredee.mesos.frameworks.accumulo.framework.api;
public final class ApiServiceFactory {
public static final ClusterApiService getClusterApi(){
return new ClusterApiServiceImpl();
}
public static final ConfigApiService getConfigApi(){
return new ConfigApiServiceImpl();
}
public static final DefaultApiService getDefaultApi(){ | // Path: accumulo-mesos-framework/src/main/java/aredee/mesos/frameworks/accumulo/framework/api/impl/ClusterApiServiceImpl.java
// public class ClusterApiServiceImpl extends ClusterApiService {
//
// Cluster cluster = Cluster.INSTANCE;
//
// @Override
// public Response clusterKillPost() throws NotFoundException {
// return null;
// }
//
// @Override
// public Response clusterMasterReprovisionPost() throws NotFoundException {
// return null;
// }
//
// @Override
// public Response clusterMasterRestartPost() throws NotFoundException {
// return null;
// }
//
// @Override
// public Response clusterMonitorGet() throws NotFoundException {
// return null;
// }
//
// @Override
// public Response clusterStartPost() throws NotFoundException {
// return null;
// }
//
// @Override
// public Response clusterStopPost() throws NotFoundException {
// return null;
// }
//
// @Override
// public Response clusterTserverReprovisionPost(String id) throws NotFoundException {
// return null;
// }
//
// @Override
// public Response clusterTserverRestartPost(String id) throws NotFoundException {
// return null;
// }
//
// @Override
// public Response clusterTserverRollingrestartPost(Boolean master, Integer group, Boolean reprovision) throws NotFoundException {
// return null;
// }
// }
//
// Path: accumulo-mesos-framework/src/main/java/aredee/mesos/frameworks/accumulo/framework/api/impl/ConfigApiServiceImpl.java
// public class ConfigApiServiceImpl extends ConfigApiService {
//
// Cluster cluster = Cluster.INSTANCE;
//
// @Override
// public Response configGet() throws NotFoundException {
// return null;
// }
// }
//
// Path: accumulo-mesos-framework/src/main/java/aredee/mesos/frameworks/accumulo/framework/api/impl/DefaultApiServiceImpl.java
// public class DefaultApiServiceImpl extends DefaultApiService {
//
// Cluster cluster = Cluster.INSTANCE;
//
// @Override
// public Response rootGet() throws NotFoundException {
// return null;
// }
// }
//
// Path: accumulo-mesos-framework/src/main/java/aredee/mesos/frameworks/accumulo/framework/api/impl/StatusApiServiceImpl.java
// public class StatusApiServiceImpl extends StatusApiService {
//
// Cluster cluster = Cluster.INSTANCE;
//
// @Override
// public Response statusGet() throws NotFoundException {
// return null;
// }
//
// }
// Path: accumulo-mesos-framework/src/main/java/aredee/mesos/frameworks/accumulo/framework/api/ApiServiceFactory.java
import aredee.mesos.frameworks.accumulo.framework.api.impl.ClusterApiServiceImpl;
import aredee.mesos.frameworks.accumulo.framework.api.impl.ConfigApiServiceImpl;
import aredee.mesos.frameworks.accumulo.framework.api.impl.DefaultApiServiceImpl;
import aredee.mesos.frameworks.accumulo.framework.api.impl.StatusApiServiceImpl;
package aredee.mesos.frameworks.accumulo.framework.api;
public final class ApiServiceFactory {
public static final ClusterApiService getClusterApi(){
return new ClusterApiServiceImpl();
}
public static final ConfigApiService getConfigApi(){
return new ConfigApiServiceImpl();
}
public static final DefaultApiService getDefaultApi(){ | return new DefaultApiServiceImpl(); |
aredee/accumulo-mesos | accumulo-mesos-framework/src/main/java/aredee/mesos/frameworks/accumulo/framework/api/ApiServiceFactory.java | // Path: accumulo-mesos-framework/src/main/java/aredee/mesos/frameworks/accumulo/framework/api/impl/ClusterApiServiceImpl.java
// public class ClusterApiServiceImpl extends ClusterApiService {
//
// Cluster cluster = Cluster.INSTANCE;
//
// @Override
// public Response clusterKillPost() throws NotFoundException {
// return null;
// }
//
// @Override
// public Response clusterMasterReprovisionPost() throws NotFoundException {
// return null;
// }
//
// @Override
// public Response clusterMasterRestartPost() throws NotFoundException {
// return null;
// }
//
// @Override
// public Response clusterMonitorGet() throws NotFoundException {
// return null;
// }
//
// @Override
// public Response clusterStartPost() throws NotFoundException {
// return null;
// }
//
// @Override
// public Response clusterStopPost() throws NotFoundException {
// return null;
// }
//
// @Override
// public Response clusterTserverReprovisionPost(String id) throws NotFoundException {
// return null;
// }
//
// @Override
// public Response clusterTserverRestartPost(String id) throws NotFoundException {
// return null;
// }
//
// @Override
// public Response clusterTserverRollingrestartPost(Boolean master, Integer group, Boolean reprovision) throws NotFoundException {
// return null;
// }
// }
//
// Path: accumulo-mesos-framework/src/main/java/aredee/mesos/frameworks/accumulo/framework/api/impl/ConfigApiServiceImpl.java
// public class ConfigApiServiceImpl extends ConfigApiService {
//
// Cluster cluster = Cluster.INSTANCE;
//
// @Override
// public Response configGet() throws NotFoundException {
// return null;
// }
// }
//
// Path: accumulo-mesos-framework/src/main/java/aredee/mesos/frameworks/accumulo/framework/api/impl/DefaultApiServiceImpl.java
// public class DefaultApiServiceImpl extends DefaultApiService {
//
// Cluster cluster = Cluster.INSTANCE;
//
// @Override
// public Response rootGet() throws NotFoundException {
// return null;
// }
// }
//
// Path: accumulo-mesos-framework/src/main/java/aredee/mesos/frameworks/accumulo/framework/api/impl/StatusApiServiceImpl.java
// public class StatusApiServiceImpl extends StatusApiService {
//
// Cluster cluster = Cluster.INSTANCE;
//
// @Override
// public Response statusGet() throws NotFoundException {
// return null;
// }
//
// }
| import aredee.mesos.frameworks.accumulo.framework.api.impl.ClusterApiServiceImpl;
import aredee.mesos.frameworks.accumulo.framework.api.impl.ConfigApiServiceImpl;
import aredee.mesos.frameworks.accumulo.framework.api.impl.DefaultApiServiceImpl;
import aredee.mesos.frameworks.accumulo.framework.api.impl.StatusApiServiceImpl; | package aredee.mesos.frameworks.accumulo.framework.api;
public final class ApiServiceFactory {
public static final ClusterApiService getClusterApi(){
return new ClusterApiServiceImpl();
}
public static final ConfigApiService getConfigApi(){
return new ConfigApiServiceImpl();
}
public static final DefaultApiService getDefaultApi(){
return new DefaultApiServiceImpl();
}
public static final StatusApiService getStatusApi(){ | // Path: accumulo-mesos-framework/src/main/java/aredee/mesos/frameworks/accumulo/framework/api/impl/ClusterApiServiceImpl.java
// public class ClusterApiServiceImpl extends ClusterApiService {
//
// Cluster cluster = Cluster.INSTANCE;
//
// @Override
// public Response clusterKillPost() throws NotFoundException {
// return null;
// }
//
// @Override
// public Response clusterMasterReprovisionPost() throws NotFoundException {
// return null;
// }
//
// @Override
// public Response clusterMasterRestartPost() throws NotFoundException {
// return null;
// }
//
// @Override
// public Response clusterMonitorGet() throws NotFoundException {
// return null;
// }
//
// @Override
// public Response clusterStartPost() throws NotFoundException {
// return null;
// }
//
// @Override
// public Response clusterStopPost() throws NotFoundException {
// return null;
// }
//
// @Override
// public Response clusterTserverReprovisionPost(String id) throws NotFoundException {
// return null;
// }
//
// @Override
// public Response clusterTserverRestartPost(String id) throws NotFoundException {
// return null;
// }
//
// @Override
// public Response clusterTserverRollingrestartPost(Boolean master, Integer group, Boolean reprovision) throws NotFoundException {
// return null;
// }
// }
//
// Path: accumulo-mesos-framework/src/main/java/aredee/mesos/frameworks/accumulo/framework/api/impl/ConfigApiServiceImpl.java
// public class ConfigApiServiceImpl extends ConfigApiService {
//
// Cluster cluster = Cluster.INSTANCE;
//
// @Override
// public Response configGet() throws NotFoundException {
// return null;
// }
// }
//
// Path: accumulo-mesos-framework/src/main/java/aredee/mesos/frameworks/accumulo/framework/api/impl/DefaultApiServiceImpl.java
// public class DefaultApiServiceImpl extends DefaultApiService {
//
// Cluster cluster = Cluster.INSTANCE;
//
// @Override
// public Response rootGet() throws NotFoundException {
// return null;
// }
// }
//
// Path: accumulo-mesos-framework/src/main/java/aredee/mesos/frameworks/accumulo/framework/api/impl/StatusApiServiceImpl.java
// public class StatusApiServiceImpl extends StatusApiService {
//
// Cluster cluster = Cluster.INSTANCE;
//
// @Override
// public Response statusGet() throws NotFoundException {
// return null;
// }
//
// }
// Path: accumulo-mesos-framework/src/main/java/aredee/mesos/frameworks/accumulo/framework/api/ApiServiceFactory.java
import aredee.mesos.frameworks.accumulo.framework.api.impl.ClusterApiServiceImpl;
import aredee.mesos.frameworks.accumulo.framework.api.impl.ConfigApiServiceImpl;
import aredee.mesos.frameworks.accumulo.framework.api.impl.DefaultApiServiceImpl;
import aredee.mesos.frameworks.accumulo.framework.api.impl.StatusApiServiceImpl;
package aredee.mesos.frameworks.accumulo.framework.api;
public final class ApiServiceFactory {
public static final ClusterApiService getClusterApi(){
return new ClusterApiServiceImpl();
}
public static final ConfigApiService getConfigApi(){
return new ConfigApiServiceImpl();
}
public static final DefaultApiService getDefaultApi(){
return new DefaultApiServiceImpl();
}
public static final StatusApiService getStatusApi(){ | return new StatusApiServiceImpl(); |
aredee/accumulo-mesos | accumulo-mesos-common/src/main/java/aredee/mesos/frameworks/accumulo/process/AccumuloProcessFactory.java | // Path: accumulo-mesos-common/src/main/java/aredee/mesos/frameworks/accumulo/configuration/Environment.java
// public class Environment {
//
// public static final String JAVA_HOME = "JAVA_HOME";
//
// public static final String CLASSPATH = "CLASSPATH";
//
// public static final String HADOOP_PREFIX = "HADOOP_PREFIX";
// public static final String HADOOP_CONF_DIR = "HADOOP_CONF_DIR";
// public static final String HADOOP_HOME = "HADOOP_HOME";
//
// public static final String ACCUMULO_HOME = "ACCUMULO_HOME";
// public static final String ACCUMULO_LOG_DIR = "ACCUMULO_LOG_DIR";
// public static final String ACCUMULO_CLIENT_CONF_PATH = "ACCUMULO_CLIENT_CONF_PATH";
// public static final String ACCUMULO_CONF_DIR = "ACCUMULO_CONF_DIR";
// public static final String ACCUMULO_WALOG = "ACCUMULO_WALOG";
//
// public static final String LD_LIBRARY_PATH = "LD_LIBRARY_PATH";
// public static final String DYLD_LIBRARY_PATH = "DYLD_LIBRARY_PATH";
//
// // List of paths separated by commas
// public static final String NATIVE_LIB_PATHS = "NATIVE_LIB_PATHS";
//
// public static final String ZOOKEEPER_HOME = "ZOOKEEPER_HOME";
//
// public static final String MESOS_DIRECTORY = "MESOS_DIRECTORY";
//
// public static final List<String> REQUIRED_FRAMEWORK_VARS = Arrays.asList(
// JAVA_HOME,
// ACCUMULO_HOME,
// HADOOP_PREFIX,
// HADOOP_CONF_DIR,
// ZOOKEEPER_HOME);
//
// public static final List<String> REQUIRED_EXECUTOR_VARS = Arrays.asList(
// JAVA_HOME,
// ACCUMULO_HOME,
// HADOOP_PREFIX,
// ZOOKEEPER_HOME,
// ACCUMULO_LOG_DIR);
//
//
// /*
// Optional Accumulo vars for executor
// */
// public static final String ACCUMULO_XTRAJARS = "ACCUMULO_XTRAJARS";
// public static final String ACCUMULO_GENERAL_OPTS = "ACCUMULO_GENERAL_OPTS";
// public static final String ACCUMULO_JAAS_CONF = "ACCUMULO_JAAS_CONF"; //-Djava.security.auth.login.config=${ACCUMULO_JAAS_CONF}
// public static final String ACCUMULO_KRB5_CONF = "ACCUMULO_KRB5_CONF"; //-Djava.security.krb5.conf=${ACCUMULO_KRB5_CONF}
//
// public static final String ACCUMULO_MASTER_OPTS = "ACCUMULO_MASTER_OPTS";
// public static final String ACCUMULO_GC_OPTS = "ACCUMULO_GC_OPTS";
// public static final String ACCUMULO_TSERVER_OPTS = "ACCUMULO_TSERVER_OPTS";
// public static final String ACCUMULO_MONITOR_OPTS = "ACCUMULO_MONITOR_OPTS";
// public static final String ACCUMULO_LOGGER_OPTS = "ACCUMULO_LOGGER_OPTS";
// public static final String ACCUMULO_OTHER_OPTS = "ACCUMULO_OTHER_OPTS";
// public static final String ACCUMULO_KILL_CMD = "ACCUMULO_KILL_CMD";
//
// // generated
// public static final String START_JAR = "START_JAR";
// public static final String LIB_PATH = "LIB_PATH";
// /*
// if [ -e "${HADOOP_PREFIX}/lib/native/libhadoop.so" ]; then
// LIB_PATH="${HADOOP_PREFIX}/lib/native"
// LD_LIBRARY_PATH="${LIB_PATH}:${LD_LIBRARY_PATH}" # For Linux
// DYLD_LIBRARY_PATH="${LIB_PATH}:${DYLD_LIBRARY_PATH}" # For Mac
// fi
// */
//
//
// public static List<String> getMissingVariables(List<String> vars) {
// List<String> missingVariables = new ArrayList<>();
// Set<String> envKeys = System.getenv().keySet();
// for(String var : vars ) {
// if(!envKeys.contains(var)){
// missingVariables.add(var);
// }
// }
// return missingVariables;
// }
//
// public static String get(String var){
// return System.getenv(var);
// }
//
// }
| import aredee.mesos.frameworks.accumulo.configuration.Environment;
import com.google.common.base.Joiner;
import com.google.common.collect.Maps;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.vfs2.FileObject;
import org.apache.commons.vfs2.impl.VFSClassLoader;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.*;
import java.net.URISyntaxException;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.*; | package aredee.mesos.frameworks.accumulo.process;
public class AccumuloProcessFactory {
private static final Logger LOGGER = LoggerFactory.getLogger(AccumuloProcessFactory.class);
private List<LogWriter> logWriters = new ArrayList<>(5);
private List<Process> cleanup = new ArrayList<>();
private Map<String, String> processEnv = Maps.newHashMap();
public AccumuloProcessFactory(){
initializeEnvironment();
}
public Process exec(String keyword, String... keywordArgs) throws IOException {
String javaHome = System.getProperty("java.home");
String javaBin = javaHome + File.separator + "bin" + File.separator + "java";
LOGGER.debug("exec: Java Bin? " + javaBin);
String classpath = getClasspath(); | // Path: accumulo-mesos-common/src/main/java/aredee/mesos/frameworks/accumulo/configuration/Environment.java
// public class Environment {
//
// public static final String JAVA_HOME = "JAVA_HOME";
//
// public static final String CLASSPATH = "CLASSPATH";
//
// public static final String HADOOP_PREFIX = "HADOOP_PREFIX";
// public static final String HADOOP_CONF_DIR = "HADOOP_CONF_DIR";
// public static final String HADOOP_HOME = "HADOOP_HOME";
//
// public static final String ACCUMULO_HOME = "ACCUMULO_HOME";
// public static final String ACCUMULO_LOG_DIR = "ACCUMULO_LOG_DIR";
// public static final String ACCUMULO_CLIENT_CONF_PATH = "ACCUMULO_CLIENT_CONF_PATH";
// public static final String ACCUMULO_CONF_DIR = "ACCUMULO_CONF_DIR";
// public static final String ACCUMULO_WALOG = "ACCUMULO_WALOG";
//
// public static final String LD_LIBRARY_PATH = "LD_LIBRARY_PATH";
// public static final String DYLD_LIBRARY_PATH = "DYLD_LIBRARY_PATH";
//
// // List of paths separated by commas
// public static final String NATIVE_LIB_PATHS = "NATIVE_LIB_PATHS";
//
// public static final String ZOOKEEPER_HOME = "ZOOKEEPER_HOME";
//
// public static final String MESOS_DIRECTORY = "MESOS_DIRECTORY";
//
// public static final List<String> REQUIRED_FRAMEWORK_VARS = Arrays.asList(
// JAVA_HOME,
// ACCUMULO_HOME,
// HADOOP_PREFIX,
// HADOOP_CONF_DIR,
// ZOOKEEPER_HOME);
//
// public static final List<String> REQUIRED_EXECUTOR_VARS = Arrays.asList(
// JAVA_HOME,
// ACCUMULO_HOME,
// HADOOP_PREFIX,
// ZOOKEEPER_HOME,
// ACCUMULO_LOG_DIR);
//
//
// /*
// Optional Accumulo vars for executor
// */
// public static final String ACCUMULO_XTRAJARS = "ACCUMULO_XTRAJARS";
// public static final String ACCUMULO_GENERAL_OPTS = "ACCUMULO_GENERAL_OPTS";
// public static final String ACCUMULO_JAAS_CONF = "ACCUMULO_JAAS_CONF"; //-Djava.security.auth.login.config=${ACCUMULO_JAAS_CONF}
// public static final String ACCUMULO_KRB5_CONF = "ACCUMULO_KRB5_CONF"; //-Djava.security.krb5.conf=${ACCUMULO_KRB5_CONF}
//
// public static final String ACCUMULO_MASTER_OPTS = "ACCUMULO_MASTER_OPTS";
// public static final String ACCUMULO_GC_OPTS = "ACCUMULO_GC_OPTS";
// public static final String ACCUMULO_TSERVER_OPTS = "ACCUMULO_TSERVER_OPTS";
// public static final String ACCUMULO_MONITOR_OPTS = "ACCUMULO_MONITOR_OPTS";
// public static final String ACCUMULO_LOGGER_OPTS = "ACCUMULO_LOGGER_OPTS";
// public static final String ACCUMULO_OTHER_OPTS = "ACCUMULO_OTHER_OPTS";
// public static final String ACCUMULO_KILL_CMD = "ACCUMULO_KILL_CMD";
//
// // generated
// public static final String START_JAR = "START_JAR";
// public static final String LIB_PATH = "LIB_PATH";
// /*
// if [ -e "${HADOOP_PREFIX}/lib/native/libhadoop.so" ]; then
// LIB_PATH="${HADOOP_PREFIX}/lib/native"
// LD_LIBRARY_PATH="${LIB_PATH}:${LD_LIBRARY_PATH}" # For Linux
// DYLD_LIBRARY_PATH="${LIB_PATH}:${DYLD_LIBRARY_PATH}" # For Mac
// fi
// */
//
//
// public static List<String> getMissingVariables(List<String> vars) {
// List<String> missingVariables = new ArrayList<>();
// Set<String> envKeys = System.getenv().keySet();
// for(String var : vars ) {
// if(!envKeys.contains(var)){
// missingVariables.add(var);
// }
// }
// return missingVariables;
// }
//
// public static String get(String var){
// return System.getenv(var);
// }
//
// }
// Path: accumulo-mesos-common/src/main/java/aredee/mesos/frameworks/accumulo/process/AccumuloProcessFactory.java
import aredee.mesos.frameworks.accumulo.configuration.Environment;
import com.google.common.base.Joiner;
import com.google.common.collect.Maps;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.vfs2.FileObject;
import org.apache.commons.vfs2.impl.VFSClassLoader;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.*;
import java.net.URISyntaxException;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.*;
package aredee.mesos.frameworks.accumulo.process;
public class AccumuloProcessFactory {
private static final Logger LOGGER = LoggerFactory.getLogger(AccumuloProcessFactory.class);
private List<LogWriter> logWriters = new ArrayList<>(5);
private List<Process> cleanup = new ArrayList<>();
private Map<String, String> processEnv = Maps.newHashMap();
public AccumuloProcessFactory(){
initializeEnvironment();
}
public Process exec(String keyword, String... keywordArgs) throws IOException {
String javaHome = System.getProperty("java.home");
String javaBin = javaHome + File.separator + "bin" + File.separator + "java";
LOGGER.debug("exec: Java Bin? " + javaBin);
String classpath = getClasspath(); | putProcessEnv(Environment.CLASSPATH, classpath); |
KoperGroup/koper | koper-testcase/src/main/java/koper/event/OrderAsyncListener.java | // Path: koper-testcase/src/main/java/koper/demo/trading/mapper/Order.java
// public class Order {
//
// public String orderId;
// public String orderName;
// public Date createDate;
// public String memberId;
// public BigDecimal totalPrice;
//
// public String getOrderId() {
// return orderId;
// }
// public void setOrderId(String orderId) {
// this.orderId = orderId;
// }
// public String getOrderName() {
// return orderName;
// }
// public void setOrderName(String orderName) {
// this.orderName = orderName;
// }
// public Date getCreateDate() {
// return createDate;
// }
// public void setCreateDate(Date createDate) {
// this.createDate = createDate;
// }
// public String getMemberId() {
// return memberId;
// }
// public void setMemberId(String memberId) {
// this.memberId = memberId;
// }
// public BigDecimal getTotalPrice() {
// return totalPrice;
// }
// public void setTotalPrice(BigDecimal totalPrice) {
// this.totalPrice = totalPrice;
// }
//
// @Override
// public String toString() {
// return "Order{" +
// "orderId='" + orderId + '\'' +
// ", orderName='" + orderName + '\'' +
// ", createDate=" + createDate +
// ", memberId='" + memberId + '\'' +
// ", totalPrice=" + totalPrice +
// '}';
// }
// }
| import com.alibaba.fastjson.JSON;
import koper.demo.trading.mapper.Order;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import java.util.List; | /*
* 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 koper.event;
/**
* OrderAsyncListener
*
* @author kk [email protected]
* @since 1.0
* 2016年2月19日
*/
@Component
@DataListener(dataObject="com.zhaimi.koper.demo.trading.mapper.impl.OrderMapperImpl")
public class OrderAsyncListener {
private static Logger log = LoggerFactory.getLogger(OrderAsyncListener.class);
public void onDeleteOrder_B(DataEvent event) {
log.info("onDeleteOrder_B" + event.getArgs());
}
/**
* deleteOrder事件响应处理方法
* 从event中获取数据:输入参数args,返回值 result。
* 数据格式为JSON。使用 fastjson工具类 进行解析
* @param event
*/
public void onDeleteOrder(DataEvent event) {
List<?> args = event.getArgs();
//数据解析:需要根据生产接口定义的参数个数,数据类型进行解析
//根据定义,第一个参数String类型
String orderId = (String) args.get(0);
//根据定义,第二个参数类型为 Order 类型 | // Path: koper-testcase/src/main/java/koper/demo/trading/mapper/Order.java
// public class Order {
//
// public String orderId;
// public String orderName;
// public Date createDate;
// public String memberId;
// public BigDecimal totalPrice;
//
// public String getOrderId() {
// return orderId;
// }
// public void setOrderId(String orderId) {
// this.orderId = orderId;
// }
// public String getOrderName() {
// return orderName;
// }
// public void setOrderName(String orderName) {
// this.orderName = orderName;
// }
// public Date getCreateDate() {
// return createDate;
// }
// public void setCreateDate(Date createDate) {
// this.createDate = createDate;
// }
// public String getMemberId() {
// return memberId;
// }
// public void setMemberId(String memberId) {
// this.memberId = memberId;
// }
// public BigDecimal getTotalPrice() {
// return totalPrice;
// }
// public void setTotalPrice(BigDecimal totalPrice) {
// this.totalPrice = totalPrice;
// }
//
// @Override
// public String toString() {
// return "Order{" +
// "orderId='" + orderId + '\'' +
// ", orderName='" + orderName + '\'' +
// ", createDate=" + createDate +
// ", memberId='" + memberId + '\'' +
// ", totalPrice=" + totalPrice +
// '}';
// }
// }
// Path: koper-testcase/src/main/java/koper/event/OrderAsyncListener.java
import com.alibaba.fastjson.JSON;
import koper.demo.trading.mapper.Order;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import java.util.List;
/*
* 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 koper.event;
/**
* OrderAsyncListener
*
* @author kk [email protected]
* @since 1.0
* 2016年2月19日
*/
@Component
@DataListener(dataObject="com.zhaimi.koper.demo.trading.mapper.impl.OrderMapperImpl")
public class OrderAsyncListener {
private static Logger log = LoggerFactory.getLogger(OrderAsyncListener.class);
public void onDeleteOrder_B(DataEvent event) {
log.info("onDeleteOrder_B" + event.getArgs());
}
/**
* deleteOrder事件响应处理方法
* 从event中获取数据:输入参数args,返回值 result。
* 数据格式为JSON。使用 fastjson工具类 进行解析
* @param event
*/
public void onDeleteOrder(DataEvent event) {
List<?> args = event.getArgs();
//数据解析:需要根据生产接口定义的参数个数,数据类型进行解析
//根据定义,第一个参数String类型
String orderId = (String) args.get(0);
//根据定义,第二个参数类型为 Order 类型 | Order order = JSON.parseObject( args.get(1).toString(),Order.class); |
KoperGroup/koper | koper-core/src/main/java/koper/client/MessageReceiver.java | // Path: koper-core/src/main/java/koper/ListenerRegistry.java
// public class ListenerRegistry {
//
// private Map<String, Object> listenerMap = new ConcurrentHashMap<>();
//
// /**
// * 注册监听器。 register listener
// *
// * @param topic
// * @param listener
// */
// public void register(String topic, Object listener) {
//
// Object listener1 = listenerMap.get(topic);
// if (listener1 != null) {
// throw new IllegalArgumentException("Listener with the same topic has been registered! topic=" + topic
// + ". Existed listener " + listener1 + ". New listener " + listener1);
// } else
// listenerMap.put(topic, listener);
//
// }
//
// public Map<String, Object> getListenerMap() {
// return listenerMap;
// }
// }
//
// Path: koper-core/src/main/java/koper/MessageCenter.java
// public interface MessageCenter<T> {
//
// @Deprecated
// T takeMessage();
//
// void putMessage(T msg);
//
// Router getRouter();
//
// }
| import koper.ListenerRegistry;
import koper.MessageCenter;
import java.util.Properties; | /*
* 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 koper.client;
/**
* @author kk
* @since 1.0
*/
public interface MessageReceiver {
boolean init();
public void start();
void setProperties(Properties properties);
| // Path: koper-core/src/main/java/koper/ListenerRegistry.java
// public class ListenerRegistry {
//
// private Map<String, Object> listenerMap = new ConcurrentHashMap<>();
//
// /**
// * 注册监听器。 register listener
// *
// * @param topic
// * @param listener
// */
// public void register(String topic, Object listener) {
//
// Object listener1 = listenerMap.get(topic);
// if (listener1 != null) {
// throw new IllegalArgumentException("Listener with the same topic has been registered! topic=" + topic
// + ". Existed listener " + listener1 + ". New listener " + listener1);
// } else
// listenerMap.put(topic, listener);
//
// }
//
// public Map<String, Object> getListenerMap() {
// return listenerMap;
// }
// }
//
// Path: koper-core/src/main/java/koper/MessageCenter.java
// public interface MessageCenter<T> {
//
// @Deprecated
// T takeMessage();
//
// void putMessage(T msg);
//
// Router getRouter();
//
// }
// Path: koper-core/src/main/java/koper/client/MessageReceiver.java
import koper.ListenerRegistry;
import koper.MessageCenter;
import java.util.Properties;
/*
* 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 koper.client;
/**
* @author kk
* @since 1.0
*/
public interface MessageReceiver {
boolean init();
public void start();
void setProperties(Properties properties);
| void setListenerRegistry(ListenerRegistry listenerRegistry); |
KoperGroup/koper | koper-core/src/main/java/koper/client/MessageReceiver.java | // Path: koper-core/src/main/java/koper/ListenerRegistry.java
// public class ListenerRegistry {
//
// private Map<String, Object> listenerMap = new ConcurrentHashMap<>();
//
// /**
// * 注册监听器。 register listener
// *
// * @param topic
// * @param listener
// */
// public void register(String topic, Object listener) {
//
// Object listener1 = listenerMap.get(topic);
// if (listener1 != null) {
// throw new IllegalArgumentException("Listener with the same topic has been registered! topic=" + topic
// + ". Existed listener " + listener1 + ". New listener " + listener1);
// } else
// listenerMap.put(topic, listener);
//
// }
//
// public Map<String, Object> getListenerMap() {
// return listenerMap;
// }
// }
//
// Path: koper-core/src/main/java/koper/MessageCenter.java
// public interface MessageCenter<T> {
//
// @Deprecated
// T takeMessage();
//
// void putMessage(T msg);
//
// Router getRouter();
//
// }
| import koper.ListenerRegistry;
import koper.MessageCenter;
import java.util.Properties; | /*
* 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 koper.client;
/**
* @author kk
* @since 1.0
*/
public interface MessageReceiver {
boolean init();
public void start();
void setProperties(Properties properties);
void setListenerRegistry(ListenerRegistry listenerRegistry);
| // Path: koper-core/src/main/java/koper/ListenerRegistry.java
// public class ListenerRegistry {
//
// private Map<String, Object> listenerMap = new ConcurrentHashMap<>();
//
// /**
// * 注册监听器。 register listener
// *
// * @param topic
// * @param listener
// */
// public void register(String topic, Object listener) {
//
// Object listener1 = listenerMap.get(topic);
// if (listener1 != null) {
// throw new IllegalArgumentException("Listener with the same topic has been registered! topic=" + topic
// + ". Existed listener " + listener1 + ". New listener " + listener1);
// } else
// listenerMap.put(topic, listener);
//
// }
//
// public Map<String, Object> getListenerMap() {
// return listenerMap;
// }
// }
//
// Path: koper-core/src/main/java/koper/MessageCenter.java
// public interface MessageCenter<T> {
//
// @Deprecated
// T takeMessage();
//
// void putMessage(T msg);
//
// Router getRouter();
//
// }
// Path: koper-core/src/main/java/koper/client/MessageReceiver.java
import koper.ListenerRegistry;
import koper.MessageCenter;
import java.util.Properties;
/*
* 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 koper.client;
/**
* @author kk
* @since 1.0
*/
public interface MessageReceiver {
boolean init();
public void start();
void setProperties(Properties properties);
void setListenerRegistry(ListenerRegistry listenerRegistry);
| void setMessageCenter(MessageCenter messageCenter); |
KoperGroup/koper | koper-testcase/src/main/java/koper/event/binding/MemberListener.java | // Path: koper-testcase/src/main/java/koper/demo/member/mapper/Member.java
// public class Member {
//
// private Integer id;
//
// private String name;
//
// private String phone;
//
// public Integer getId() {
// return id;
// }
//
// public void setId(Integer id) {
// this.id = id;
// }
//
// public String getName() {
// return name;
// }
//
// public void setName(String name) {
// this.name = name;
// }
//
// public String getPhone() {
// return phone;
// }
//
// public void setPhone(String phone) {
// this.phone = phone;
// }
//
// @Override
// public String toString() {
// return "Member{" +
// "id=" + id +
// ", name='" + name + '\'' +
// ", phone='" + phone + '\'' +
// '}';
// }
// }
//
// Path: koper-dataevent/src/main/java/koper/event/DataEvent.java
// public interface DataEvent {
//
// void setException(String exception);
//
// String getException();
//
// void setResult(Object result);
//
// Object getResult();
//
// void setArgs(List<?> args);
//
// List<?> getArgs();
//
// void setMsgBean(MsgBean<String, String> msgBean);
//
// MsgBean<String, String> getMsgBean();
//
// void setEventName(String eventName);
//
// String getEventName();
//
// void setDataObjectName(String dataObjectName);
//
// String getDataObjectName();
//
// void setTopic(String topic);
//
// String getTopic();
//
// }
| import koper.demo.member.mapper.Member;
import koper.event.DataEvent;
import koper.event.DataListener;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import java.math.BigDecimal; | /*
* 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 koper.event.binding;
/**
* @author caie
* @since 1.2
*/
@Component
@DataListener(dataObject = "koper.demo.member.mapper.impl.MemberMapperImpl")
public class MemberListener {
private Logger logger = LoggerFactory.getLogger(MemberListener.class);
/**
* test with Integer String type param
*/
public void onInsertMember(Integer id, String name, String phone) {
logger.info("on insert Member successful, id : {}, name : {}, phone : {}", id, name, phone);
}
/**
* test with pojo and Integer type param
*/ | // Path: koper-testcase/src/main/java/koper/demo/member/mapper/Member.java
// public class Member {
//
// private Integer id;
//
// private String name;
//
// private String phone;
//
// public Integer getId() {
// return id;
// }
//
// public void setId(Integer id) {
// this.id = id;
// }
//
// public String getName() {
// return name;
// }
//
// public void setName(String name) {
// this.name = name;
// }
//
// public String getPhone() {
// return phone;
// }
//
// public void setPhone(String phone) {
// this.phone = phone;
// }
//
// @Override
// public String toString() {
// return "Member{" +
// "id=" + id +
// ", name='" + name + '\'' +
// ", phone='" + phone + '\'' +
// '}';
// }
// }
//
// Path: koper-dataevent/src/main/java/koper/event/DataEvent.java
// public interface DataEvent {
//
// void setException(String exception);
//
// String getException();
//
// void setResult(Object result);
//
// Object getResult();
//
// void setArgs(List<?> args);
//
// List<?> getArgs();
//
// void setMsgBean(MsgBean<String, String> msgBean);
//
// MsgBean<String, String> getMsgBean();
//
// void setEventName(String eventName);
//
// String getEventName();
//
// void setDataObjectName(String dataObjectName);
//
// String getDataObjectName();
//
// void setTopic(String topic);
//
// String getTopic();
//
// }
// Path: koper-testcase/src/main/java/koper/event/binding/MemberListener.java
import koper.demo.member.mapper.Member;
import koper.event.DataEvent;
import koper.event.DataListener;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import java.math.BigDecimal;
/*
* 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 koper.event.binding;
/**
* @author caie
* @since 1.2
*/
@Component
@DataListener(dataObject = "koper.demo.member.mapper.impl.MemberMapperImpl")
public class MemberListener {
private Logger logger = LoggerFactory.getLogger(MemberListener.class);
/**
* test with Integer String type param
*/
public void onInsertMember(Integer id, String name, String phone) {
logger.info("on insert Member successful, id : {}, name : {}, phone : {}", id, name, phone);
}
/**
* test with pojo and Integer type param
*/ | public void onCancelMember(Integer id, Member member) { |
KoperGroup/koper | koper-testcase/src/main/java/koper/event/binding/MemberListener.java | // Path: koper-testcase/src/main/java/koper/demo/member/mapper/Member.java
// public class Member {
//
// private Integer id;
//
// private String name;
//
// private String phone;
//
// public Integer getId() {
// return id;
// }
//
// public void setId(Integer id) {
// this.id = id;
// }
//
// public String getName() {
// return name;
// }
//
// public void setName(String name) {
// this.name = name;
// }
//
// public String getPhone() {
// return phone;
// }
//
// public void setPhone(String phone) {
// this.phone = phone;
// }
//
// @Override
// public String toString() {
// return "Member{" +
// "id=" + id +
// ", name='" + name + '\'' +
// ", phone='" + phone + '\'' +
// '}';
// }
// }
//
// Path: koper-dataevent/src/main/java/koper/event/DataEvent.java
// public interface DataEvent {
//
// void setException(String exception);
//
// String getException();
//
// void setResult(Object result);
//
// Object getResult();
//
// void setArgs(List<?> args);
//
// List<?> getArgs();
//
// void setMsgBean(MsgBean<String, String> msgBean);
//
// MsgBean<String, String> getMsgBean();
//
// void setEventName(String eventName);
//
// String getEventName();
//
// void setDataObjectName(String dataObjectName);
//
// String getDataObjectName();
//
// void setTopic(String topic);
//
// String getTopic();
//
// }
| import koper.demo.member.mapper.Member;
import koper.event.DataEvent;
import koper.event.DataListener;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import java.math.BigDecimal; | /*
* 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 koper.event.binding;
/**
* @author caie
* @since 1.2
*/
@Component
@DataListener(dataObject = "koper.demo.member.mapper.impl.MemberMapperImpl")
public class MemberListener {
private Logger logger = LoggerFactory.getLogger(MemberListener.class);
/**
* test with Integer String type param
*/
public void onInsertMember(Integer id, String name, String phone) {
logger.info("on insert Member successful, id : {}, name : {}, phone : {}", id, name, phone);
}
/**
* test with pojo and Integer type param
*/
public void onCancelMember(Integer id, Member member) {
logger.info("on cancel member successful, member info : {}, id : {}",
member.toString(), id);
}
/**
* test with DataEvent type param
*/ | // Path: koper-testcase/src/main/java/koper/demo/member/mapper/Member.java
// public class Member {
//
// private Integer id;
//
// private String name;
//
// private String phone;
//
// public Integer getId() {
// return id;
// }
//
// public void setId(Integer id) {
// this.id = id;
// }
//
// public String getName() {
// return name;
// }
//
// public void setName(String name) {
// this.name = name;
// }
//
// public String getPhone() {
// return phone;
// }
//
// public void setPhone(String phone) {
// this.phone = phone;
// }
//
// @Override
// public String toString() {
// return "Member{" +
// "id=" + id +
// ", name='" + name + '\'' +
// ", phone='" + phone + '\'' +
// '}';
// }
// }
//
// Path: koper-dataevent/src/main/java/koper/event/DataEvent.java
// public interface DataEvent {
//
// void setException(String exception);
//
// String getException();
//
// void setResult(Object result);
//
// Object getResult();
//
// void setArgs(List<?> args);
//
// List<?> getArgs();
//
// void setMsgBean(MsgBean<String, String> msgBean);
//
// MsgBean<String, String> getMsgBean();
//
// void setEventName(String eventName);
//
// String getEventName();
//
// void setDataObjectName(String dataObjectName);
//
// String getDataObjectName();
//
// void setTopic(String topic);
//
// String getTopic();
//
// }
// Path: koper-testcase/src/main/java/koper/event/binding/MemberListener.java
import koper.demo.member.mapper.Member;
import koper.event.DataEvent;
import koper.event.DataListener;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import java.math.BigDecimal;
/*
* 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 koper.event.binding;
/**
* @author caie
* @since 1.2
*/
@Component
@DataListener(dataObject = "koper.demo.member.mapper.impl.MemberMapperImpl")
public class MemberListener {
private Logger logger = LoggerFactory.getLogger(MemberListener.class);
/**
* test with Integer String type param
*/
public void onInsertMember(Integer id, String name, String phone) {
logger.info("on insert Member successful, id : {}, name : {}, phone : {}", id, name, phone);
}
/**
* test with pojo and Integer type param
*/
public void onCancelMember(Integer id, Member member) {
logger.info("on cancel member successful, member info : {}, id : {}",
member.toString(), id);
}
/**
* test with DataEvent type param
*/ | public void onDeleteMember(DataEvent dataEvent) { |
KoperGroup/koper | koper-core/src/main/java/koper/MessageCenter.java | // Path: koper-core/src/main/java/koper/router/Router.java
// public interface Router {
//
// /**
// * register dispatcher thread 's mail box here, mq receiver will dispatch {@Link MsgBean} to mail box
// *
// * @param thread which thread's main box
// * @param mailBox dispatcher thread 's local cache
// */
// void registerThreadMailBox(Runnable thread, BlockingQueue mailBox);
//
// /**
// * dispatch {@Link MsgBean} to mail box
// *
// * @param msgBean msg
// */
// void dispatch(Object msgBean) throws InterruptedException;
//
// /**
// * call it when thread is interrupted
// *
// * @param thread
// */
// void deRegister(Runnable thread);
// }
| import koper.router.Router; | /*
* 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 koper;
/**
* message center
*
* @author kk
* @since 1.0
*/
public interface MessageCenter<T> {
@Deprecated
T takeMessage();
void putMessage(T msg);
| // Path: koper-core/src/main/java/koper/router/Router.java
// public interface Router {
//
// /**
// * register dispatcher thread 's mail box here, mq receiver will dispatch {@Link MsgBean} to mail box
// *
// * @param thread which thread's main box
// * @param mailBox dispatcher thread 's local cache
// */
// void registerThreadMailBox(Runnable thread, BlockingQueue mailBox);
//
// /**
// * dispatch {@Link MsgBean} to mail box
// *
// * @param msgBean msg
// */
// void dispatch(Object msgBean) throws InterruptedException;
//
// /**
// * call it when thread is interrupted
// *
// * @param thread
// */
// void deRegister(Runnable thread);
// }
// Path: koper-core/src/main/java/koper/MessageCenter.java
import koper.router.Router;
/*
* 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 koper;
/**
* message center
*
* @author kk
* @since 1.0
*/
public interface MessageCenter<T> {
@Deprecated
T takeMessage();
void putMessage(T msg);
| Router getRouter(); |
KoperGroup/koper | koper-reactor/src/test/java/koper/reactor/demo/CustomerApp.java | // Path: koper-core/src/main/java/koper/client/ConsumerLauncher.java
// public interface ConsumerLauncher {
//
// /**
// * start consumer
// */
// public void start();
//
// void setAutoStart(boolean autoStart);
//
// void setPartitions(int partitions);
//
// /**
// * @param threads
// */
// void setDispatcherThreads(int threads);
//
// /**
// * @return
// */
// public ListenerRegistry getListenerRegistry();
// }
| import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import koper.client.ConsumerLauncher; | /*
* 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 koper.reactor.demo;
/**
* CustomerApp
* @author Raymond He, [email protected]
* @since 1.0
* 2016年8月26日
*
*/
public class CustomerApp {
public static void main(String[] args) {
ApplicationContext context = new ClassPathXmlApplicationContext("classpath:kafka/context-data-consumer.xml"); | // Path: koper-core/src/main/java/koper/client/ConsumerLauncher.java
// public interface ConsumerLauncher {
//
// /**
// * start consumer
// */
// public void start();
//
// void setAutoStart(boolean autoStart);
//
// void setPartitions(int partitions);
//
// /**
// * @param threads
// */
// void setDispatcherThreads(int threads);
//
// /**
// * @return
// */
// public ListenerRegistry getListenerRegistry();
// }
// Path: koper-reactor/src/test/java/koper/reactor/demo/CustomerApp.java
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import koper.client.ConsumerLauncher;
/*
* 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 koper.reactor.demo;
/**
* CustomerApp
* @author Raymond He, [email protected]
* @since 1.0
* 2016年8月26日
*
*/
public class CustomerApp {
public static void main(String[] args) {
ApplicationContext context = new ClassPathXmlApplicationContext("classpath:kafka/context-data-consumer.xml"); | ConsumerLauncher consumerLauncher = context.getBean(ConsumerLauncher.class); |
KoperGroup/koper | koper-demo/src/main/java/koper/demo/performance/KafkaReceiverPerf.java | // Path: koper-core/src/main/java/koper/client/ConsumerLauncher.java
// public interface ConsumerLauncher {
//
// /**
// * start consumer
// */
// public void start();
//
// void setAutoStart(boolean autoStart);
//
// void setPartitions(int partitions);
//
// /**
// * @param threads
// */
// void setDispatcherThreads(int threads);
//
// /**
// * @return
// */
// public ListenerRegistry getListenerRegistry();
// }
//
// Path: koper-demo/src/main/java/koper/demo/dataevent/listener/OrderListener.java
// @Component
// @DataListener(dataObject = "koper.demo.dataevent.mapper.impl.OrderMapperImpl")
// public class OrderListener {
// private static int WRITE_PERIOD = 10000;
//
// private static AtomicLong msgCount = new AtomicLong(0);
// private static AtomicLong lastTs = new AtomicLong(0);
// private static AtomicLong sumReceiveTime = new AtomicLong(0);
// private static AtomicLong sumConsumeTime = new AtomicLong(0);
//
// private static final File file = new File(String.format("OrderListenerStatistic_%d.txt", System.currentTimeMillis()));
//
// public void onInsertOrder(Order order, DataEvent dataEvent) {
// // 用写入文件来模拟真实的消息消费
// File output = new File("output.txt");
// try {
// FileUtils.writeStringToFile(output,
// "\norderNo : " + order.getOrderNo() + ", create time : " + order.getCreatedTime()
// , true);
// } catch (Exception e) {
// e.printStackTrace();
// }
//
// // 统计信息
// MsgBean<String, String> msgBean = dataEvent.getMsgBean();
// long receive = msgBean.getReceiveUseTime();
// long consume = msgBean.getConsumeUseTime();
// sumReceiveTime.getAndAdd(receive);
// sumConsumeTime.getAndAdd(consume - receive);
//
// long cnt = msgCount.incrementAndGet();
// if (cnt % WRITE_PERIOD == 0) writeFile(file);
// }
//
// private void writeFile(File file) {
// try {
// long currTs = System.currentTimeMillis();
// long period = currTs - lastTs.getAndSet(currTs);
// long sumReceive = sumReceiveTime.getAndSet(0);
// long sumConsume = sumConsumeTime.getAndSet(0);
// String record = String.format("TimeStamp = %d, Count = %d, MillSeconds = %d, TPS = %.2f, AvgReceive = %d, AvgConsume = %d\n",
// currTs,
// msgCount.get(),
// period,
// WRITE_PERIOD / ((double) period / 1000),
// sumReceive / WRITE_PERIOD,
// sumConsume / WRITE_PERIOD);
// FileUtils.writeStringToFile(file, record, true);
// } catch (Exception e) {
// e.printStackTrace();
// }
// }
//
// public void changeStatLine(int line) {
// if (line > 0) WRITE_PERIOD = line;
// }
//
// public void onUpdateOrder(Order order, DataEvent dataEvent) {
// System.out.println("orderNo : " + order.getOrderNo());
// System.out.println("create time :" + order.getCreatedTime());
// }
//
// }
| import koper.client.ConsumerLauncher;
import koper.demo.dataevent.listener.OrderListener;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext; | /*
* 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 koper.demo.performance;
/**
* @author kk
* @since 1.0
*/
public class KafkaReceiverPerf {
private static Logger logger = LoggerFactory.getLogger(KafkaReceiverPerf.class);
/**
* 消费者程序入口
* @param args : 第一个命令行参数(可选)设定统计信息每隔多少条消息记录一次
*/
public static void main(String[] args) {
final ApplicationContext context =
new ClassPathXmlApplicationContext("classpath:kafka/context-data-consumer.xml");
if (args.length > 0) {
int statLine = Integer.parseInt(args[0]); | // Path: koper-core/src/main/java/koper/client/ConsumerLauncher.java
// public interface ConsumerLauncher {
//
// /**
// * start consumer
// */
// public void start();
//
// void setAutoStart(boolean autoStart);
//
// void setPartitions(int partitions);
//
// /**
// * @param threads
// */
// void setDispatcherThreads(int threads);
//
// /**
// * @return
// */
// public ListenerRegistry getListenerRegistry();
// }
//
// Path: koper-demo/src/main/java/koper/demo/dataevent/listener/OrderListener.java
// @Component
// @DataListener(dataObject = "koper.demo.dataevent.mapper.impl.OrderMapperImpl")
// public class OrderListener {
// private static int WRITE_PERIOD = 10000;
//
// private static AtomicLong msgCount = new AtomicLong(0);
// private static AtomicLong lastTs = new AtomicLong(0);
// private static AtomicLong sumReceiveTime = new AtomicLong(0);
// private static AtomicLong sumConsumeTime = new AtomicLong(0);
//
// private static final File file = new File(String.format("OrderListenerStatistic_%d.txt", System.currentTimeMillis()));
//
// public void onInsertOrder(Order order, DataEvent dataEvent) {
// // 用写入文件来模拟真实的消息消费
// File output = new File("output.txt");
// try {
// FileUtils.writeStringToFile(output,
// "\norderNo : " + order.getOrderNo() + ", create time : " + order.getCreatedTime()
// , true);
// } catch (Exception e) {
// e.printStackTrace();
// }
//
// // 统计信息
// MsgBean<String, String> msgBean = dataEvent.getMsgBean();
// long receive = msgBean.getReceiveUseTime();
// long consume = msgBean.getConsumeUseTime();
// sumReceiveTime.getAndAdd(receive);
// sumConsumeTime.getAndAdd(consume - receive);
//
// long cnt = msgCount.incrementAndGet();
// if (cnt % WRITE_PERIOD == 0) writeFile(file);
// }
//
// private void writeFile(File file) {
// try {
// long currTs = System.currentTimeMillis();
// long period = currTs - lastTs.getAndSet(currTs);
// long sumReceive = sumReceiveTime.getAndSet(0);
// long sumConsume = sumConsumeTime.getAndSet(0);
// String record = String.format("TimeStamp = %d, Count = %d, MillSeconds = %d, TPS = %.2f, AvgReceive = %d, AvgConsume = %d\n",
// currTs,
// msgCount.get(),
// period,
// WRITE_PERIOD / ((double) period / 1000),
// sumReceive / WRITE_PERIOD,
// sumConsume / WRITE_PERIOD);
// FileUtils.writeStringToFile(file, record, true);
// } catch (Exception e) {
// e.printStackTrace();
// }
// }
//
// public void changeStatLine(int line) {
// if (line > 0) WRITE_PERIOD = line;
// }
//
// public void onUpdateOrder(Order order, DataEvent dataEvent) {
// System.out.println("orderNo : " + order.getOrderNo());
// System.out.println("create time :" + order.getCreatedTime());
// }
//
// }
// Path: koper-demo/src/main/java/koper/demo/performance/KafkaReceiverPerf.java
import koper.client.ConsumerLauncher;
import koper.demo.dataevent.listener.OrderListener;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
/*
* 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 koper.demo.performance;
/**
* @author kk
* @since 1.0
*/
public class KafkaReceiverPerf {
private static Logger logger = LoggerFactory.getLogger(KafkaReceiverPerf.class);
/**
* 消费者程序入口
* @param args : 第一个命令行参数(可选)设定统计信息每隔多少条消息记录一次
*/
public static void main(String[] args) {
final ApplicationContext context =
new ClassPathXmlApplicationContext("classpath:kafka/context-data-consumer.xml");
if (args.length > 0) {
int statLine = Integer.parseInt(args[0]); | OrderListener listener = context.getBean(OrderListener.class); |
KoperGroup/koper | koper-demo/src/main/java/koper/demo/performance/KafkaReceiverPerf.java | // Path: koper-core/src/main/java/koper/client/ConsumerLauncher.java
// public interface ConsumerLauncher {
//
// /**
// * start consumer
// */
// public void start();
//
// void setAutoStart(boolean autoStart);
//
// void setPartitions(int partitions);
//
// /**
// * @param threads
// */
// void setDispatcherThreads(int threads);
//
// /**
// * @return
// */
// public ListenerRegistry getListenerRegistry();
// }
//
// Path: koper-demo/src/main/java/koper/demo/dataevent/listener/OrderListener.java
// @Component
// @DataListener(dataObject = "koper.demo.dataevent.mapper.impl.OrderMapperImpl")
// public class OrderListener {
// private static int WRITE_PERIOD = 10000;
//
// private static AtomicLong msgCount = new AtomicLong(0);
// private static AtomicLong lastTs = new AtomicLong(0);
// private static AtomicLong sumReceiveTime = new AtomicLong(0);
// private static AtomicLong sumConsumeTime = new AtomicLong(0);
//
// private static final File file = new File(String.format("OrderListenerStatistic_%d.txt", System.currentTimeMillis()));
//
// public void onInsertOrder(Order order, DataEvent dataEvent) {
// // 用写入文件来模拟真实的消息消费
// File output = new File("output.txt");
// try {
// FileUtils.writeStringToFile(output,
// "\norderNo : " + order.getOrderNo() + ", create time : " + order.getCreatedTime()
// , true);
// } catch (Exception e) {
// e.printStackTrace();
// }
//
// // 统计信息
// MsgBean<String, String> msgBean = dataEvent.getMsgBean();
// long receive = msgBean.getReceiveUseTime();
// long consume = msgBean.getConsumeUseTime();
// sumReceiveTime.getAndAdd(receive);
// sumConsumeTime.getAndAdd(consume - receive);
//
// long cnt = msgCount.incrementAndGet();
// if (cnt % WRITE_PERIOD == 0) writeFile(file);
// }
//
// private void writeFile(File file) {
// try {
// long currTs = System.currentTimeMillis();
// long period = currTs - lastTs.getAndSet(currTs);
// long sumReceive = sumReceiveTime.getAndSet(0);
// long sumConsume = sumConsumeTime.getAndSet(0);
// String record = String.format("TimeStamp = %d, Count = %d, MillSeconds = %d, TPS = %.2f, AvgReceive = %d, AvgConsume = %d\n",
// currTs,
// msgCount.get(),
// period,
// WRITE_PERIOD / ((double) period / 1000),
// sumReceive / WRITE_PERIOD,
// sumConsume / WRITE_PERIOD);
// FileUtils.writeStringToFile(file, record, true);
// } catch (Exception e) {
// e.printStackTrace();
// }
// }
//
// public void changeStatLine(int line) {
// if (line > 0) WRITE_PERIOD = line;
// }
//
// public void onUpdateOrder(Order order, DataEvent dataEvent) {
// System.out.println("orderNo : " + order.getOrderNo());
// System.out.println("create time :" + order.getCreatedTime());
// }
//
// }
| import koper.client.ConsumerLauncher;
import koper.demo.dataevent.listener.OrderListener;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext; | /*
* 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 koper.demo.performance;
/**
* @author kk
* @since 1.0
*/
public class KafkaReceiverPerf {
private static Logger logger = LoggerFactory.getLogger(KafkaReceiverPerf.class);
/**
* 消费者程序入口
* @param args : 第一个命令行参数(可选)设定统计信息每隔多少条消息记录一次
*/
public static void main(String[] args) {
final ApplicationContext context =
new ClassPathXmlApplicationContext("classpath:kafka/context-data-consumer.xml");
if (args.length > 0) {
int statLine = Integer.parseInt(args[0]);
OrderListener listener = context.getBean(OrderListener.class);
listener.changeStatLine(statLine);
}
| // Path: koper-core/src/main/java/koper/client/ConsumerLauncher.java
// public interface ConsumerLauncher {
//
// /**
// * start consumer
// */
// public void start();
//
// void setAutoStart(boolean autoStart);
//
// void setPartitions(int partitions);
//
// /**
// * @param threads
// */
// void setDispatcherThreads(int threads);
//
// /**
// * @return
// */
// public ListenerRegistry getListenerRegistry();
// }
//
// Path: koper-demo/src/main/java/koper/demo/dataevent/listener/OrderListener.java
// @Component
// @DataListener(dataObject = "koper.demo.dataevent.mapper.impl.OrderMapperImpl")
// public class OrderListener {
// private static int WRITE_PERIOD = 10000;
//
// private static AtomicLong msgCount = new AtomicLong(0);
// private static AtomicLong lastTs = new AtomicLong(0);
// private static AtomicLong sumReceiveTime = new AtomicLong(0);
// private static AtomicLong sumConsumeTime = new AtomicLong(0);
//
// private static final File file = new File(String.format("OrderListenerStatistic_%d.txt", System.currentTimeMillis()));
//
// public void onInsertOrder(Order order, DataEvent dataEvent) {
// // 用写入文件来模拟真实的消息消费
// File output = new File("output.txt");
// try {
// FileUtils.writeStringToFile(output,
// "\norderNo : " + order.getOrderNo() + ", create time : " + order.getCreatedTime()
// , true);
// } catch (Exception e) {
// e.printStackTrace();
// }
//
// // 统计信息
// MsgBean<String, String> msgBean = dataEvent.getMsgBean();
// long receive = msgBean.getReceiveUseTime();
// long consume = msgBean.getConsumeUseTime();
// sumReceiveTime.getAndAdd(receive);
// sumConsumeTime.getAndAdd(consume - receive);
//
// long cnt = msgCount.incrementAndGet();
// if (cnt % WRITE_PERIOD == 0) writeFile(file);
// }
//
// private void writeFile(File file) {
// try {
// long currTs = System.currentTimeMillis();
// long period = currTs - lastTs.getAndSet(currTs);
// long sumReceive = sumReceiveTime.getAndSet(0);
// long sumConsume = sumConsumeTime.getAndSet(0);
// String record = String.format("TimeStamp = %d, Count = %d, MillSeconds = %d, TPS = %.2f, AvgReceive = %d, AvgConsume = %d\n",
// currTs,
// msgCount.get(),
// period,
// WRITE_PERIOD / ((double) period / 1000),
// sumReceive / WRITE_PERIOD,
// sumConsume / WRITE_PERIOD);
// FileUtils.writeStringToFile(file, record, true);
// } catch (Exception e) {
// e.printStackTrace();
// }
// }
//
// public void changeStatLine(int line) {
// if (line > 0) WRITE_PERIOD = line;
// }
//
// public void onUpdateOrder(Order order, DataEvent dataEvent) {
// System.out.println("orderNo : " + order.getOrderNo());
// System.out.println("create time :" + order.getCreatedTime());
// }
//
// }
// Path: koper-demo/src/main/java/koper/demo/performance/KafkaReceiverPerf.java
import koper.client.ConsumerLauncher;
import koper.demo.dataevent.listener.OrderListener;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
/*
* 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 koper.demo.performance;
/**
* @author kk
* @since 1.0
*/
public class KafkaReceiverPerf {
private static Logger logger = LoggerFactory.getLogger(KafkaReceiverPerf.class);
/**
* 消费者程序入口
* @param args : 第一个命令行参数(可选)设定统计信息每隔多少条消息记录一次
*/
public static void main(String[] args) {
final ApplicationContext context =
new ClassPathXmlApplicationContext("classpath:kafka/context-data-consumer.xml");
if (args.length > 0) {
int statLine = Integer.parseInt(args[0]);
OrderListener listener = context.getBean(OrderListener.class);
listener.changeStatLine(statLine);
}
| final ConsumerLauncher consumerLauncher = context.getBean(ConsumerLauncher.class); |
KoperGroup/koper | koper-reactor/src/test/java/koper/reactor/demo/Digger.java | // Path: koper-reactor/src/main/java/koper/reactor/Reactor.java
// public abstract class Reactor extends AbstractMessageListener implements Identifieable {
//
// private String id;
// /**
// * @param id the id to set
// */
// @Override
// public void setId(String id) {
// this.id = id;
// }
//
// /**
// * @return the id
// */
// @Override
// public String getId() {
// return id;
// }
// }
| import org.springframework.stereotype.Component;
import koper.Listen;
import koper.reactor.Reactor; | /*
* 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 koper.reactor.demo;
/**
* Digger
* @author Raymond He, [email protected],[email protected]
* @since 1.0
* 2016年8月25日
*
*/
@Component
@Listen(topic="koper.reactor.demo.Digger") | // Path: koper-reactor/src/main/java/koper/reactor/Reactor.java
// public abstract class Reactor extends AbstractMessageListener implements Identifieable {
//
// private String id;
// /**
// * @param id the id to set
// */
// @Override
// public void setId(String id) {
// this.id = id;
// }
//
// /**
// * @return the id
// */
// @Override
// public String getId() {
// return id;
// }
// }
// Path: koper-reactor/src/test/java/koper/reactor/demo/Digger.java
import org.springframework.stereotype.Component;
import koper.Listen;
import koper.reactor.Reactor;
/*
* 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 koper.reactor.demo;
/**
* Digger
* @author Raymond He, [email protected],[email protected]
* @since 1.0
* 2016年8月25日
*
*/
@Component
@Listen(topic="koper.reactor.demo.Digger") | public class Digger extends Reactor { |
KoperGroup/koper | koper-testcase/src/test/java/koper/kafka/OrderListenerTestCase.java | // Path: koper-core/src/main/java/koper/AbstractMessageListener.java
// public abstract class AbstractMessageListener implements MessageListener {
//
// @Override
// public void onMsgBean(MsgBean<String, String> msgBean) {
//
// }
//
// @Override
// public void onMessage(String msg) {
// }
// }
//
// Path: koper-testcase/src/main/java/koper/demo/trading/mapper/Order.java
// public class Order {
//
// public String orderId;
// public String orderName;
// public Date createDate;
// public String memberId;
// public BigDecimal totalPrice;
//
// public String getOrderId() {
// return orderId;
// }
// public void setOrderId(String orderId) {
// this.orderId = orderId;
// }
// public String getOrderName() {
// return orderName;
// }
// public void setOrderName(String orderName) {
// this.orderName = orderName;
// }
// public Date getCreateDate() {
// return createDate;
// }
// public void setCreateDate(Date createDate) {
// this.createDate = createDate;
// }
// public String getMemberId() {
// return memberId;
// }
// public void setMemberId(String memberId) {
// this.memberId = memberId;
// }
// public BigDecimal getTotalPrice() {
// return totalPrice;
// }
// public void setTotalPrice(BigDecimal totalPrice) {
// this.totalPrice = totalPrice;
// }
//
// @Override
// public String toString() {
// return "Order{" +
// "orderId='" + orderId + '\'' +
// ", orderName='" + orderName + '\'' +
// ", createDate=" + createDate +
// ", memberId='" + memberId + '\'' +
// ", totalPrice=" + totalPrice +
// '}';
// }
// }
//
// Path: koper-core/src/main/java/koper/sender/MessageSender.java
// public interface MessageSender {
//
// void send(String topic, String msg);
//
// void send(String topic, String key, String msg);
//
// void send(String topic, Object msg);
//
// void send(String topic, String key, Object msg);
// }
| import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import koper.AbstractMessageListener;
import koper.Listen;
import koper.demo.trading.mapper.Order;
import koper.sender.MessageSender;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import java.math.BigDecimal; | /*
* 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 koper.kafka;
/**
* 将消息的生产者, 消费者 组合在一起测试.
* 每当发送消息后, 主动让主线程沉睡一定时间,
* 从而使得启动的实例可以让消费者接收到从遥远的Kafka来的消息,
* 并作相应断言.
*
* @author caie
* @since 1.2
*/
@ContextConfiguration(locations = {
"classpath:kafka/context-data-producer.xml",
"classpath:kafka/context-data-message.xml",
"classpath:kafka/context-data-consumer.xml"
})
@RunWith(SpringJUnit4ClassRunner.class) | // Path: koper-core/src/main/java/koper/AbstractMessageListener.java
// public abstract class AbstractMessageListener implements MessageListener {
//
// @Override
// public void onMsgBean(MsgBean<String, String> msgBean) {
//
// }
//
// @Override
// public void onMessage(String msg) {
// }
// }
//
// Path: koper-testcase/src/main/java/koper/demo/trading/mapper/Order.java
// public class Order {
//
// public String orderId;
// public String orderName;
// public Date createDate;
// public String memberId;
// public BigDecimal totalPrice;
//
// public String getOrderId() {
// return orderId;
// }
// public void setOrderId(String orderId) {
// this.orderId = orderId;
// }
// public String getOrderName() {
// return orderName;
// }
// public void setOrderName(String orderName) {
// this.orderName = orderName;
// }
// public Date getCreateDate() {
// return createDate;
// }
// public void setCreateDate(Date createDate) {
// this.createDate = createDate;
// }
// public String getMemberId() {
// return memberId;
// }
// public void setMemberId(String memberId) {
// this.memberId = memberId;
// }
// public BigDecimal getTotalPrice() {
// return totalPrice;
// }
// public void setTotalPrice(BigDecimal totalPrice) {
// this.totalPrice = totalPrice;
// }
//
// @Override
// public String toString() {
// return "Order{" +
// "orderId='" + orderId + '\'' +
// ", orderName='" + orderName + '\'' +
// ", createDate=" + createDate +
// ", memberId='" + memberId + '\'' +
// ", totalPrice=" + totalPrice +
// '}';
// }
// }
//
// Path: koper-core/src/main/java/koper/sender/MessageSender.java
// public interface MessageSender {
//
// void send(String topic, String msg);
//
// void send(String topic, String key, String msg);
//
// void send(String topic, Object msg);
//
// void send(String topic, String key, Object msg);
// }
// Path: koper-testcase/src/test/java/koper/kafka/OrderListenerTestCase.java
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import koper.AbstractMessageListener;
import koper.Listen;
import koper.demo.trading.mapper.Order;
import koper.sender.MessageSender;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import java.math.BigDecimal;
/*
* 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 koper.kafka;
/**
* 将消息的生产者, 消费者 组合在一起测试.
* 每当发送消息后, 主动让主线程沉睡一定时间,
* 从而使得启动的实例可以让消费者接收到从遥远的Kafka来的消息,
* 并作相应断言.
*
* @author caie
* @since 1.2
*/
@ContextConfiguration(locations = {
"classpath:kafka/context-data-producer.xml",
"classpath:kafka/context-data-message.xml",
"classpath:kafka/context-data-consumer.xml"
})
@RunWith(SpringJUnit4ClassRunner.class) | public class OrderListenerTestCase extends AbstractMessageListener { |
KoperGroup/koper | koper-testcase/src/test/java/koper/kafka/OrderListenerTestCase.java | // Path: koper-core/src/main/java/koper/AbstractMessageListener.java
// public abstract class AbstractMessageListener implements MessageListener {
//
// @Override
// public void onMsgBean(MsgBean<String, String> msgBean) {
//
// }
//
// @Override
// public void onMessage(String msg) {
// }
// }
//
// Path: koper-testcase/src/main/java/koper/demo/trading/mapper/Order.java
// public class Order {
//
// public String orderId;
// public String orderName;
// public Date createDate;
// public String memberId;
// public BigDecimal totalPrice;
//
// public String getOrderId() {
// return orderId;
// }
// public void setOrderId(String orderId) {
// this.orderId = orderId;
// }
// public String getOrderName() {
// return orderName;
// }
// public void setOrderName(String orderName) {
// this.orderName = orderName;
// }
// public Date getCreateDate() {
// return createDate;
// }
// public void setCreateDate(Date createDate) {
// this.createDate = createDate;
// }
// public String getMemberId() {
// return memberId;
// }
// public void setMemberId(String memberId) {
// this.memberId = memberId;
// }
// public BigDecimal getTotalPrice() {
// return totalPrice;
// }
// public void setTotalPrice(BigDecimal totalPrice) {
// this.totalPrice = totalPrice;
// }
//
// @Override
// public String toString() {
// return "Order{" +
// "orderId='" + orderId + '\'' +
// ", orderName='" + orderName + '\'' +
// ", createDate=" + createDate +
// ", memberId='" + memberId + '\'' +
// ", totalPrice=" + totalPrice +
// '}';
// }
// }
//
// Path: koper-core/src/main/java/koper/sender/MessageSender.java
// public interface MessageSender {
//
// void send(String topic, String msg);
//
// void send(String topic, String key, String msg);
//
// void send(String topic, Object msg);
//
// void send(String topic, String key, Object msg);
// }
| import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import koper.AbstractMessageListener;
import koper.Listen;
import koper.demo.trading.mapper.Order;
import koper.sender.MessageSender;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import java.math.BigDecimal; | /*
* 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 koper.kafka;
/**
* 将消息的生产者, 消费者 组合在一起测试.
* 每当发送消息后, 主动让主线程沉睡一定时间,
* 从而使得启动的实例可以让消费者接收到从遥远的Kafka来的消息,
* 并作相应断言.
*
* @author caie
* @since 1.2
*/
@ContextConfiguration(locations = {
"classpath:kafka/context-data-producer.xml",
"classpath:kafka/context-data-message.xml",
"classpath:kafka/context-data-consumer.xml"
})
@RunWith(SpringJUnit4ClassRunner.class)
public class OrderListenerTestCase extends AbstractMessageListener {
private final Logger logger = LoggerFactory.getLogger(getClass());
@Autowired | // Path: koper-core/src/main/java/koper/AbstractMessageListener.java
// public abstract class AbstractMessageListener implements MessageListener {
//
// @Override
// public void onMsgBean(MsgBean<String, String> msgBean) {
//
// }
//
// @Override
// public void onMessage(String msg) {
// }
// }
//
// Path: koper-testcase/src/main/java/koper/demo/trading/mapper/Order.java
// public class Order {
//
// public String orderId;
// public String orderName;
// public Date createDate;
// public String memberId;
// public BigDecimal totalPrice;
//
// public String getOrderId() {
// return orderId;
// }
// public void setOrderId(String orderId) {
// this.orderId = orderId;
// }
// public String getOrderName() {
// return orderName;
// }
// public void setOrderName(String orderName) {
// this.orderName = orderName;
// }
// public Date getCreateDate() {
// return createDate;
// }
// public void setCreateDate(Date createDate) {
// this.createDate = createDate;
// }
// public String getMemberId() {
// return memberId;
// }
// public void setMemberId(String memberId) {
// this.memberId = memberId;
// }
// public BigDecimal getTotalPrice() {
// return totalPrice;
// }
// public void setTotalPrice(BigDecimal totalPrice) {
// this.totalPrice = totalPrice;
// }
//
// @Override
// public String toString() {
// return "Order{" +
// "orderId='" + orderId + '\'' +
// ", orderName='" + orderName + '\'' +
// ", createDate=" + createDate +
// ", memberId='" + memberId + '\'' +
// ", totalPrice=" + totalPrice +
// '}';
// }
// }
//
// Path: koper-core/src/main/java/koper/sender/MessageSender.java
// public interface MessageSender {
//
// void send(String topic, String msg);
//
// void send(String topic, String key, String msg);
//
// void send(String topic, Object msg);
//
// void send(String topic, String key, Object msg);
// }
// Path: koper-testcase/src/test/java/koper/kafka/OrderListenerTestCase.java
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import koper.AbstractMessageListener;
import koper.Listen;
import koper.demo.trading.mapper.Order;
import koper.sender.MessageSender;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import java.math.BigDecimal;
/*
* 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 koper.kafka;
/**
* 将消息的生产者, 消费者 组合在一起测试.
* 每当发送消息后, 主动让主线程沉睡一定时间,
* 从而使得启动的实例可以让消费者接收到从遥远的Kafka来的消息,
* 并作相应断言.
*
* @author caie
* @since 1.2
*/
@ContextConfiguration(locations = {
"classpath:kafka/context-data-producer.xml",
"classpath:kafka/context-data-message.xml",
"classpath:kafka/context-data-consumer.xml"
})
@RunWith(SpringJUnit4ClassRunner.class)
public class OrderListenerTestCase extends AbstractMessageListener {
private final Logger logger = LoggerFactory.getLogger(getClass());
@Autowired | private MessageSender messageSender; |
KoperGroup/koper | koper-testcase/src/test/java/koper/kafka/OrderListenerTestCase.java | // Path: koper-core/src/main/java/koper/AbstractMessageListener.java
// public abstract class AbstractMessageListener implements MessageListener {
//
// @Override
// public void onMsgBean(MsgBean<String, String> msgBean) {
//
// }
//
// @Override
// public void onMessage(String msg) {
// }
// }
//
// Path: koper-testcase/src/main/java/koper/demo/trading/mapper/Order.java
// public class Order {
//
// public String orderId;
// public String orderName;
// public Date createDate;
// public String memberId;
// public BigDecimal totalPrice;
//
// public String getOrderId() {
// return orderId;
// }
// public void setOrderId(String orderId) {
// this.orderId = orderId;
// }
// public String getOrderName() {
// return orderName;
// }
// public void setOrderName(String orderName) {
// this.orderName = orderName;
// }
// public Date getCreateDate() {
// return createDate;
// }
// public void setCreateDate(Date createDate) {
// this.createDate = createDate;
// }
// public String getMemberId() {
// return memberId;
// }
// public void setMemberId(String memberId) {
// this.memberId = memberId;
// }
// public BigDecimal getTotalPrice() {
// return totalPrice;
// }
// public void setTotalPrice(BigDecimal totalPrice) {
// this.totalPrice = totalPrice;
// }
//
// @Override
// public String toString() {
// return "Order{" +
// "orderId='" + orderId + '\'' +
// ", orderName='" + orderName + '\'' +
// ", createDate=" + createDate +
// ", memberId='" + memberId + '\'' +
// ", totalPrice=" + totalPrice +
// '}';
// }
// }
//
// Path: koper-core/src/main/java/koper/sender/MessageSender.java
// public interface MessageSender {
//
// void send(String topic, String msg);
//
// void send(String topic, String key, String msg);
//
// void send(String topic, Object msg);
//
// void send(String topic, String key, Object msg);
// }
| import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import koper.AbstractMessageListener;
import koper.Listen;
import koper.demo.trading.mapper.Order;
import koper.sender.MessageSender;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import java.math.BigDecimal; | /*
* 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 koper.kafka;
/**
* 将消息的生产者, 消费者 组合在一起测试.
* 每当发送消息后, 主动让主线程沉睡一定时间,
* 从而使得启动的实例可以让消费者接收到从遥远的Kafka来的消息,
* 并作相应断言.
*
* @author caie
* @since 1.2
*/
@ContextConfiguration(locations = {
"classpath:kafka/context-data-producer.xml",
"classpath:kafka/context-data-message.xml",
"classpath:kafka/context-data-consumer.xml"
})
@RunWith(SpringJUnit4ClassRunner.class)
public class OrderListenerTestCase extends AbstractMessageListener {
private final Logger logger = LoggerFactory.getLogger(getClass());
@Autowired
private MessageSender messageSender; | // Path: koper-core/src/main/java/koper/AbstractMessageListener.java
// public abstract class AbstractMessageListener implements MessageListener {
//
// @Override
// public void onMsgBean(MsgBean<String, String> msgBean) {
//
// }
//
// @Override
// public void onMessage(String msg) {
// }
// }
//
// Path: koper-testcase/src/main/java/koper/demo/trading/mapper/Order.java
// public class Order {
//
// public String orderId;
// public String orderName;
// public Date createDate;
// public String memberId;
// public BigDecimal totalPrice;
//
// public String getOrderId() {
// return orderId;
// }
// public void setOrderId(String orderId) {
// this.orderId = orderId;
// }
// public String getOrderName() {
// return orderName;
// }
// public void setOrderName(String orderName) {
// this.orderName = orderName;
// }
// public Date getCreateDate() {
// return createDate;
// }
// public void setCreateDate(Date createDate) {
// this.createDate = createDate;
// }
// public String getMemberId() {
// return memberId;
// }
// public void setMemberId(String memberId) {
// this.memberId = memberId;
// }
// public BigDecimal getTotalPrice() {
// return totalPrice;
// }
// public void setTotalPrice(BigDecimal totalPrice) {
// this.totalPrice = totalPrice;
// }
//
// @Override
// public String toString() {
// return "Order{" +
// "orderId='" + orderId + '\'' +
// ", orderName='" + orderName + '\'' +
// ", createDate=" + createDate +
// ", memberId='" + memberId + '\'' +
// ", totalPrice=" + totalPrice +
// '}';
// }
// }
//
// Path: koper-core/src/main/java/koper/sender/MessageSender.java
// public interface MessageSender {
//
// void send(String topic, String msg);
//
// void send(String topic, String key, String msg);
//
// void send(String topic, Object msg);
//
// void send(String topic, String key, Object msg);
// }
// Path: koper-testcase/src/test/java/koper/kafka/OrderListenerTestCase.java
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import koper.AbstractMessageListener;
import koper.Listen;
import koper.demo.trading.mapper.Order;
import koper.sender.MessageSender;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import java.math.BigDecimal;
/*
* 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 koper.kafka;
/**
* 将消息的生产者, 消费者 组合在一起测试.
* 每当发送消息后, 主动让主线程沉睡一定时间,
* 从而使得启动的实例可以让消费者接收到从遥远的Kafka来的消息,
* 并作相应断言.
*
* @author caie
* @since 1.2
*/
@ContextConfiguration(locations = {
"classpath:kafka/context-data-producer.xml",
"classpath:kafka/context-data-message.xml",
"classpath:kafka/context-data-consumer.xml"
})
@RunWith(SpringJUnit4ClassRunner.class)
public class OrderListenerTestCase extends AbstractMessageListener {
private final Logger logger = LoggerFactory.getLogger(getClass());
@Autowired
private MessageSender messageSender; | private Order expectOrder; |
KoperGroup/koper | koper-core/src/main/java/koper/client/ConsumerLauncher.java | // Path: koper-core/src/main/java/koper/ListenerRegistry.java
// public class ListenerRegistry {
//
// private Map<String, Object> listenerMap = new ConcurrentHashMap<>();
//
// /**
// * 注册监听器。 register listener
// *
// * @param topic
// * @param listener
// */
// public void register(String topic, Object listener) {
//
// Object listener1 = listenerMap.get(topic);
// if (listener1 != null) {
// throw new IllegalArgumentException("Listener with the same topic has been registered! topic=" + topic
// + ". Existed listener " + listener1 + ". New listener " + listener1);
// } else
// listenerMap.put(topic, listener);
//
// }
//
// public Map<String, Object> getListenerMap() {
// return listenerMap;
// }
// }
| import koper.ListenerRegistry; | /*
* 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 koper.client;
/**
* @author kk
* @since 1.0
*/
public interface ConsumerLauncher {
/**
* start consumer
*/
public void start();
void setAutoStart(boolean autoStart);
void setPartitions(int partitions);
/**
* @param threads
*/
void setDispatcherThreads(int threads);
/**
* @return
*/ | // Path: koper-core/src/main/java/koper/ListenerRegistry.java
// public class ListenerRegistry {
//
// private Map<String, Object> listenerMap = new ConcurrentHashMap<>();
//
// /**
// * 注册监听器。 register listener
// *
// * @param topic
// * @param listener
// */
// public void register(String topic, Object listener) {
//
// Object listener1 = listenerMap.get(topic);
// if (listener1 != null) {
// throw new IllegalArgumentException("Listener with the same topic has been registered! topic=" + topic
// + ". Existed listener " + listener1 + ". New listener " + listener1);
// } else
// listenerMap.put(topic, listener);
//
// }
//
// public Map<String, Object> getListenerMap() {
// return listenerMap;
// }
// }
// Path: koper-core/src/main/java/koper/client/ConsumerLauncher.java
import koper.ListenerRegistry;
/*
* 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 koper.client;
/**
* @author kk
* @since 1.0
*/
public interface ConsumerLauncher {
/**
* start consumer
*/
public void start();
void setAutoStart(boolean autoStart);
void setPartitions(int partitions);
/**
* @param threads
*/
void setDispatcherThreads(int threads);
/**
* @return
*/ | public ListenerRegistry getListenerRegistry(); |
KoperGroup/koper | koper-testcase/src/main/java/koper/demo/trading/mapper/impl/OrderMapperImpl.java | // Path: koper-testcase/src/main/java/koper/demo/trading/mapper/OrderMapper.java
// public interface OrderMapper {
//
// String getOrder(String orderId, Order order);
//
// String cancelOrder(Order order);
//
// String createOrder(String memberId, Order order);
//
// String updateOrder(Order order);
//
// String insertOrder(Order order);
//
// /**
// * @param orderId
// * @param order
// * @return
// */
// String deleteOrder(String orderId, Order order);
//
// String deleteOldOrder(int orderId, boolean reserve);
//
// String cancelOldOrder(Order order);
// }
//
// Path: koper-testcase/src/main/java/koper/demo/trading/mapper/Order.java
// public class Order {
//
// public String orderId;
// public String orderName;
// public Date createDate;
// public String memberId;
// public BigDecimal totalPrice;
//
// public String getOrderId() {
// return orderId;
// }
// public void setOrderId(String orderId) {
// this.orderId = orderId;
// }
// public String getOrderName() {
// return orderName;
// }
// public void setOrderName(String orderName) {
// this.orderName = orderName;
// }
// public Date getCreateDate() {
// return createDate;
// }
// public void setCreateDate(Date createDate) {
// this.createDate = createDate;
// }
// public String getMemberId() {
// return memberId;
// }
// public void setMemberId(String memberId) {
// this.memberId = memberId;
// }
// public BigDecimal getTotalPrice() {
// return totalPrice;
// }
// public void setTotalPrice(BigDecimal totalPrice) {
// this.totalPrice = totalPrice;
// }
//
// @Override
// public String toString() {
// return "Order{" +
// "orderId='" + orderId + '\'' +
// ", orderName='" + orderName + '\'' +
// ", createDate=" + createDate +
// ", memberId='" + memberId + '\'' +
// ", totalPrice=" + totalPrice +
// '}';
// }
// }
| import koper.aop.SendMessageAfter;
import koper.aop.SendMessageBefore;
import koper.demo.trading.mapper.OrderMapper;
import koper.demo.trading.mapper.Order;
import org.springframework.stereotype.Component; | package koper.demo.trading.mapper.impl;
/**
* @author kk
* @since 1.0
*/
@Component
public class OrderMapperImpl implements OrderMapper {
/**
* 方法调用前发送数据消息
*/
@SendMessageBefore(topic = "Order.onBeforeCreateOrder") | // Path: koper-testcase/src/main/java/koper/demo/trading/mapper/OrderMapper.java
// public interface OrderMapper {
//
// String getOrder(String orderId, Order order);
//
// String cancelOrder(Order order);
//
// String createOrder(String memberId, Order order);
//
// String updateOrder(Order order);
//
// String insertOrder(Order order);
//
// /**
// * @param orderId
// * @param order
// * @return
// */
// String deleteOrder(String orderId, Order order);
//
// String deleteOldOrder(int orderId, boolean reserve);
//
// String cancelOldOrder(Order order);
// }
//
// Path: koper-testcase/src/main/java/koper/demo/trading/mapper/Order.java
// public class Order {
//
// public String orderId;
// public String orderName;
// public Date createDate;
// public String memberId;
// public BigDecimal totalPrice;
//
// public String getOrderId() {
// return orderId;
// }
// public void setOrderId(String orderId) {
// this.orderId = orderId;
// }
// public String getOrderName() {
// return orderName;
// }
// public void setOrderName(String orderName) {
// this.orderName = orderName;
// }
// public Date getCreateDate() {
// return createDate;
// }
// public void setCreateDate(Date createDate) {
// this.createDate = createDate;
// }
// public String getMemberId() {
// return memberId;
// }
// public void setMemberId(String memberId) {
// this.memberId = memberId;
// }
// public BigDecimal getTotalPrice() {
// return totalPrice;
// }
// public void setTotalPrice(BigDecimal totalPrice) {
// this.totalPrice = totalPrice;
// }
//
// @Override
// public String toString() {
// return "Order{" +
// "orderId='" + orderId + '\'' +
// ", orderName='" + orderName + '\'' +
// ", createDate=" + createDate +
// ", memberId='" + memberId + '\'' +
// ", totalPrice=" + totalPrice +
// '}';
// }
// }
// Path: koper-testcase/src/main/java/koper/demo/trading/mapper/impl/OrderMapperImpl.java
import koper.aop.SendMessageAfter;
import koper.aop.SendMessageBefore;
import koper.demo.trading.mapper.OrderMapper;
import koper.demo.trading.mapper.Order;
import org.springframework.stereotype.Component;
package koper.demo.trading.mapper.impl;
/**
* @author kk
* @since 1.0
*/
@Component
public class OrderMapperImpl implements OrderMapper {
/**
* 方法调用前发送数据消息
*/
@SendMessageBefore(topic = "Order.onBeforeCreateOrder") | public String createOrder(String memberId, Order order) { |
KoperGroup/koper | koper-reactor/src/test/java/koper/reactor/demo/ProducerApp.java | // Path: koper-reactor/src/main/java/koper/reactor/ReactorRef.java
// public class ReactorRef {
//
// private long id;
// private Class<? extends Reactor> reactorClass;
// public MessageSender messageSender;
//
// private static final Random rd = new Random();
// /**
// *
// */
// private ReactorRef(Class<? extends Reactor> reactorClass) {
// this.reactorClass = reactorClass;
// }
//
// /**
// * @param id the id to set
// */
// public void setId(long id) {
// this.id = id;
// }
//
// /**
// * @return the id
// */
// public long getId() {
// return id;
// }
//
// /**
// * Create a remote object. Specify a random global id;
// * @param reactorClass
// * @return
// */
// public static ReactorRef create(Class<? extends Reactor> reactorClass) {
// ReactorRef ref = new ReactorRef(reactorClass);
// long id = rd.nextLong();
// id = id<0 ? -id : id;
// ref.setId(id);
// return ref;
// }
//
// /**
// * Refer to an existing remote object with a given id.
// * @param id
// * @param reactorClass
// * @return
// */
// public static ReactorRef ref( Class<? extends Reactor> reactorClass,long id) {
// ReactorRef ref = new ReactorRef(reactorClass);
// ref.setId(id);
// return ref;
// }
//
// public void setMessageSender(MessageSender messageSender) {
// this.messageSender = messageSender;
// }
//
// /**
// * send message to remote object refered by this ref
// * @param message
// */
// public void send(Object message) {
// String className = reactorClass.getName();
// String classAndMethod = className ;
// System.out.println("id " + id);
// messageSender.send(classAndMethod , String.valueOf( id ) , message);
// }
//
// public static void main(String[] args) {
// Random rd = new Random(1000);
// for(int i=0;i<10;i++) {
// long id = rd.nextLong();
// id = id<0? -id : id;
// System.out.println("x " + id);
// }
// }
// }
//
// Path: koper-core/src/main/java/koper/sender/MessageSender.java
// public interface MessageSender {
//
// void send(String topic, String msg);
//
// void send(String topic, String key, String msg);
//
// void send(String topic, Object msg);
//
// void send(String topic, String key, Object msg);
// }
| import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import koper.reactor.ReactorRef;
import koper.sender.MessageSender;
import scala.util.Random; | /*
* 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 koper.reactor.demo;
/**
* ProducerApp
* @author Raymond He, [email protected]
* @since 1.0
* 2016年8月25日
*
*/
public class ProducerApp {
/**
* Reactor produce demo.
* Create prototype(multiple instances) reactor and send message to them.
* @param args
*/
public static void main(String[] args) {
ApplicationContext context = new ClassPathXmlApplicationContext("classpath:kafka/context-data-producer.xml"); | // Path: koper-reactor/src/main/java/koper/reactor/ReactorRef.java
// public class ReactorRef {
//
// private long id;
// private Class<? extends Reactor> reactorClass;
// public MessageSender messageSender;
//
// private static final Random rd = new Random();
// /**
// *
// */
// private ReactorRef(Class<? extends Reactor> reactorClass) {
// this.reactorClass = reactorClass;
// }
//
// /**
// * @param id the id to set
// */
// public void setId(long id) {
// this.id = id;
// }
//
// /**
// * @return the id
// */
// public long getId() {
// return id;
// }
//
// /**
// * Create a remote object. Specify a random global id;
// * @param reactorClass
// * @return
// */
// public static ReactorRef create(Class<? extends Reactor> reactorClass) {
// ReactorRef ref = new ReactorRef(reactorClass);
// long id = rd.nextLong();
// id = id<0 ? -id : id;
// ref.setId(id);
// return ref;
// }
//
// /**
// * Refer to an existing remote object with a given id.
// * @param id
// * @param reactorClass
// * @return
// */
// public static ReactorRef ref( Class<? extends Reactor> reactorClass,long id) {
// ReactorRef ref = new ReactorRef(reactorClass);
// ref.setId(id);
// return ref;
// }
//
// public void setMessageSender(MessageSender messageSender) {
// this.messageSender = messageSender;
// }
//
// /**
// * send message to remote object refered by this ref
// * @param message
// */
// public void send(Object message) {
// String className = reactorClass.getName();
// String classAndMethod = className ;
// System.out.println("id " + id);
// messageSender.send(classAndMethod , String.valueOf( id ) , message);
// }
//
// public static void main(String[] args) {
// Random rd = new Random(1000);
// for(int i=0;i<10;i++) {
// long id = rd.nextLong();
// id = id<0? -id : id;
// System.out.println("x " + id);
// }
// }
// }
//
// Path: koper-core/src/main/java/koper/sender/MessageSender.java
// public interface MessageSender {
//
// void send(String topic, String msg);
//
// void send(String topic, String key, String msg);
//
// void send(String topic, Object msg);
//
// void send(String topic, String key, Object msg);
// }
// Path: koper-reactor/src/test/java/koper/reactor/demo/ProducerApp.java
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import koper.reactor.ReactorRef;
import koper.sender.MessageSender;
import scala.util.Random;
/*
* 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 koper.reactor.demo;
/**
* ProducerApp
* @author Raymond He, [email protected]
* @since 1.0
* 2016年8月25日
*
*/
public class ProducerApp {
/**
* Reactor produce demo.
* Create prototype(multiple instances) reactor and send message to them.
* @param args
*/
public static void main(String[] args) {
ApplicationContext context = new ClassPathXmlApplicationContext("classpath:kafka/context-data-producer.xml"); | MessageSender messageSender = (MessageSender) context.getBean("messageSender"); |
KoperGroup/koper | koper-reactor/src/test/java/koper/reactor/demo/ProducerApp.java | // Path: koper-reactor/src/main/java/koper/reactor/ReactorRef.java
// public class ReactorRef {
//
// private long id;
// private Class<? extends Reactor> reactorClass;
// public MessageSender messageSender;
//
// private static final Random rd = new Random();
// /**
// *
// */
// private ReactorRef(Class<? extends Reactor> reactorClass) {
// this.reactorClass = reactorClass;
// }
//
// /**
// * @param id the id to set
// */
// public void setId(long id) {
// this.id = id;
// }
//
// /**
// * @return the id
// */
// public long getId() {
// return id;
// }
//
// /**
// * Create a remote object. Specify a random global id;
// * @param reactorClass
// * @return
// */
// public static ReactorRef create(Class<? extends Reactor> reactorClass) {
// ReactorRef ref = new ReactorRef(reactorClass);
// long id = rd.nextLong();
// id = id<0 ? -id : id;
// ref.setId(id);
// return ref;
// }
//
// /**
// * Refer to an existing remote object with a given id.
// * @param id
// * @param reactorClass
// * @return
// */
// public static ReactorRef ref( Class<? extends Reactor> reactorClass,long id) {
// ReactorRef ref = new ReactorRef(reactorClass);
// ref.setId(id);
// return ref;
// }
//
// public void setMessageSender(MessageSender messageSender) {
// this.messageSender = messageSender;
// }
//
// /**
// * send message to remote object refered by this ref
// * @param message
// */
// public void send(Object message) {
// String className = reactorClass.getName();
// String classAndMethod = className ;
// System.out.println("id " + id);
// messageSender.send(classAndMethod , String.valueOf( id ) , message);
// }
//
// public static void main(String[] args) {
// Random rd = new Random(1000);
// for(int i=0;i<10;i++) {
// long id = rd.nextLong();
// id = id<0? -id : id;
// System.out.println("x " + id);
// }
// }
// }
//
// Path: koper-core/src/main/java/koper/sender/MessageSender.java
// public interface MessageSender {
//
// void send(String topic, String msg);
//
// void send(String topic, String key, String msg);
//
// void send(String topic, Object msg);
//
// void send(String topic, String key, Object msg);
// }
| import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import koper.reactor.ReactorRef;
import koper.sender.MessageSender;
import scala.util.Random; | /*
* 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 koper.reactor.demo;
/**
* ProducerApp
* @author Raymond He, [email protected]
* @since 1.0
* 2016年8月25日
*
*/
public class ProducerApp {
/**
* Reactor produce demo.
* Create prototype(multiple instances) reactor and send message to them.
* @param args
*/
public static void main(String[] args) {
ApplicationContext context = new ClassPathXmlApplicationContext("classpath:kafka/context-data-producer.xml");
MessageSender messageSender = (MessageSender) context.getBean("messageSender");
| // Path: koper-reactor/src/main/java/koper/reactor/ReactorRef.java
// public class ReactorRef {
//
// private long id;
// private Class<? extends Reactor> reactorClass;
// public MessageSender messageSender;
//
// private static final Random rd = new Random();
// /**
// *
// */
// private ReactorRef(Class<? extends Reactor> reactorClass) {
// this.reactorClass = reactorClass;
// }
//
// /**
// * @param id the id to set
// */
// public void setId(long id) {
// this.id = id;
// }
//
// /**
// * @return the id
// */
// public long getId() {
// return id;
// }
//
// /**
// * Create a remote object. Specify a random global id;
// * @param reactorClass
// * @return
// */
// public static ReactorRef create(Class<? extends Reactor> reactorClass) {
// ReactorRef ref = new ReactorRef(reactorClass);
// long id = rd.nextLong();
// id = id<0 ? -id : id;
// ref.setId(id);
// return ref;
// }
//
// /**
// * Refer to an existing remote object with a given id.
// * @param id
// * @param reactorClass
// * @return
// */
// public static ReactorRef ref( Class<? extends Reactor> reactorClass,long id) {
// ReactorRef ref = new ReactorRef(reactorClass);
// ref.setId(id);
// return ref;
// }
//
// public void setMessageSender(MessageSender messageSender) {
// this.messageSender = messageSender;
// }
//
// /**
// * send message to remote object refered by this ref
// * @param message
// */
// public void send(Object message) {
// String className = reactorClass.getName();
// String classAndMethod = className ;
// System.out.println("id " + id);
// messageSender.send(classAndMethod , String.valueOf( id ) , message);
// }
//
// public static void main(String[] args) {
// Random rd = new Random(1000);
// for(int i=0;i<10;i++) {
// long id = rd.nextLong();
// id = id<0? -id : id;
// System.out.println("x " + id);
// }
// }
// }
//
// Path: koper-core/src/main/java/koper/sender/MessageSender.java
// public interface MessageSender {
//
// void send(String topic, String msg);
//
// void send(String topic, String key, String msg);
//
// void send(String topic, Object msg);
//
// void send(String topic, String key, Object msg);
// }
// Path: koper-reactor/src/test/java/koper/reactor/demo/ProducerApp.java
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import koper.reactor.ReactorRef;
import koper.sender.MessageSender;
import scala.util.Random;
/*
* 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 koper.reactor.demo;
/**
* ProducerApp
* @author Raymond He, [email protected]
* @since 1.0
* 2016年8月25日
*
*/
public class ProducerApp {
/**
* Reactor produce demo.
* Create prototype(multiple instances) reactor and send message to them.
* @param args
*/
public static void main(String[] args) {
ApplicationContext context = new ClassPathXmlApplicationContext("classpath:kafka/context-data-producer.xml");
MessageSender messageSender = (MessageSender) context.getBean("messageSender");
| ReactorRef ref = ReactorRef.create(Digger.class); |
KoperGroup/koper | koper-testcase/src/main/java/koper/demo/member/mapper/impl/MemberMapperImpl.java | // Path: koper-testcase/src/main/java/koper/demo/member/mapper/Member.java
// public class Member {
//
// private Integer id;
//
// private String name;
//
// private String phone;
//
// public Integer getId() {
// return id;
// }
//
// public void setId(Integer id) {
// this.id = id;
// }
//
// public String getName() {
// return name;
// }
//
// public void setName(String name) {
// this.name = name;
// }
//
// public String getPhone() {
// return phone;
// }
//
// public void setPhone(String phone) {
// this.phone = phone;
// }
//
// @Override
// public String toString() {
// return "Member{" +
// "id=" + id +
// ", name='" + name + '\'' +
// ", phone='" + phone + '\'' +
// '}';
// }
// }
//
// Path: koper-testcase/src/main/java/koper/demo/member/mapper/MemberMapper.java
// public interface MemberMapper {
//
// String insertMember(Integer id, String name, String phone);
//
// String cancelMember(Integer id, Member member);
//
// String deleteMember(Integer id, String name);
//
// String updateMember(Double id, Long name, BigDecimal account);
//
// String insertWithFloatAndShortAndByteAndChar(Float fl, Short s, Byte b, Character c);
//
// String deleteWithIntegerAndStringAndDataEvent(Integer id, String name);
//
//
// }
| import koper.demo.member.mapper.Member;
import koper.demo.member.mapper.MemberMapper;
import org.springframework.stereotype.Repository;
import java.math.BigDecimal; | /*
* 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 koper.demo.member.mapper.impl;
/**
* @author caie
* @since 1.2
*/
@Repository
public class MemberMapperImpl implements MemberMapper {
@Override
public String insertMember(Integer id, String name, String phone) {
return "on insert Member successful";
}
@Override | // Path: koper-testcase/src/main/java/koper/demo/member/mapper/Member.java
// public class Member {
//
// private Integer id;
//
// private String name;
//
// private String phone;
//
// public Integer getId() {
// return id;
// }
//
// public void setId(Integer id) {
// this.id = id;
// }
//
// public String getName() {
// return name;
// }
//
// public void setName(String name) {
// this.name = name;
// }
//
// public String getPhone() {
// return phone;
// }
//
// public void setPhone(String phone) {
// this.phone = phone;
// }
//
// @Override
// public String toString() {
// return "Member{" +
// "id=" + id +
// ", name='" + name + '\'' +
// ", phone='" + phone + '\'' +
// '}';
// }
// }
//
// Path: koper-testcase/src/main/java/koper/demo/member/mapper/MemberMapper.java
// public interface MemberMapper {
//
// String insertMember(Integer id, String name, String phone);
//
// String cancelMember(Integer id, Member member);
//
// String deleteMember(Integer id, String name);
//
// String updateMember(Double id, Long name, BigDecimal account);
//
// String insertWithFloatAndShortAndByteAndChar(Float fl, Short s, Byte b, Character c);
//
// String deleteWithIntegerAndStringAndDataEvent(Integer id, String name);
//
//
// }
// Path: koper-testcase/src/main/java/koper/demo/member/mapper/impl/MemberMapperImpl.java
import koper.demo.member.mapper.Member;
import koper.demo.member.mapper.MemberMapper;
import org.springframework.stereotype.Repository;
import java.math.BigDecimal;
/*
* 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 koper.demo.member.mapper.impl;
/**
* @author caie
* @since 1.2
*/
@Repository
public class MemberMapperImpl implements MemberMapper {
@Override
public String insertMember(Integer id, String name, String phone) {
return "on insert Member successful";
}
@Override | public String cancelMember(Integer id, Member member) { |
KoperGroup/koper | koper-core/src/main/java/koper/client/MessageReceiverThread.java | // Path: koper-core/src/main/java/koper/ListenerRegistry.java
// public class ListenerRegistry {
//
// private Map<String, Object> listenerMap = new ConcurrentHashMap<>();
//
// /**
// * 注册监听器。 register listener
// *
// * @param topic
// * @param listener
// */
// public void register(String topic, Object listener) {
//
// Object listener1 = listenerMap.get(topic);
// if (listener1 != null) {
// throw new IllegalArgumentException("Listener with the same topic has been registered! topic=" + topic
// + ". Existed listener " + listener1 + ". New listener " + listener1);
// } else
// listenerMap.put(topic, listener);
//
// }
//
// public Map<String, Object> getListenerMap() {
// return listenerMap;
// }
// }
//
// Path: koper-core/src/main/java/koper/MessageCenter.java
// public interface MessageCenter<T> {
//
// @Deprecated
// T takeMessage();
//
// void putMessage(T msg);
//
// Router getRouter();
//
// }
| import koper.ListenerRegistry;
import koper.MessageCenter;
import java.util.Properties; | /*
* 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 koper.client;
/**
* ConsumerThread. 每个topic由一个线程接收。
*
* @author kk
* @since 1.0
*/
public class MessageReceiverThread implements Runnable {
private Properties properties;
private MessageReceiver messageReceiver; | // Path: koper-core/src/main/java/koper/ListenerRegistry.java
// public class ListenerRegistry {
//
// private Map<String, Object> listenerMap = new ConcurrentHashMap<>();
//
// /**
// * 注册监听器。 register listener
// *
// * @param topic
// * @param listener
// */
// public void register(String topic, Object listener) {
//
// Object listener1 = listenerMap.get(topic);
// if (listener1 != null) {
// throw new IllegalArgumentException("Listener with the same topic has been registered! topic=" + topic
// + ". Existed listener " + listener1 + ". New listener " + listener1);
// } else
// listenerMap.put(topic, listener);
//
// }
//
// public Map<String, Object> getListenerMap() {
// return listenerMap;
// }
// }
//
// Path: koper-core/src/main/java/koper/MessageCenter.java
// public interface MessageCenter<T> {
//
// @Deprecated
// T takeMessage();
//
// void putMessage(T msg);
//
// Router getRouter();
//
// }
// Path: koper-core/src/main/java/koper/client/MessageReceiverThread.java
import koper.ListenerRegistry;
import koper.MessageCenter;
import java.util.Properties;
/*
* 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 koper.client;
/**
* ConsumerThread. 每个topic由一个线程接收。
*
* @author kk
* @since 1.0
*/
public class MessageReceiverThread implements Runnable {
private Properties properties;
private MessageReceiver messageReceiver; | private MessageCenter messageCenter; |
KoperGroup/koper | koper-core/src/main/java/koper/client/MessageReceiverThread.java | // Path: koper-core/src/main/java/koper/ListenerRegistry.java
// public class ListenerRegistry {
//
// private Map<String, Object> listenerMap = new ConcurrentHashMap<>();
//
// /**
// * 注册监听器。 register listener
// *
// * @param topic
// * @param listener
// */
// public void register(String topic, Object listener) {
//
// Object listener1 = listenerMap.get(topic);
// if (listener1 != null) {
// throw new IllegalArgumentException("Listener with the same topic has been registered! topic=" + topic
// + ". Existed listener " + listener1 + ". New listener " + listener1);
// } else
// listenerMap.put(topic, listener);
//
// }
//
// public Map<String, Object> getListenerMap() {
// return listenerMap;
// }
// }
//
// Path: koper-core/src/main/java/koper/MessageCenter.java
// public interface MessageCenter<T> {
//
// @Deprecated
// T takeMessage();
//
// void putMessage(T msg);
//
// Router getRouter();
//
// }
| import koper.ListenerRegistry;
import koper.MessageCenter;
import java.util.Properties; | /*
* 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 koper.client;
/**
* ConsumerThread. 每个topic由一个线程接收。
*
* @author kk
* @since 1.0
*/
public class MessageReceiverThread implements Runnable {
private Properties properties;
private MessageReceiver messageReceiver;
private MessageCenter messageCenter; | // Path: koper-core/src/main/java/koper/ListenerRegistry.java
// public class ListenerRegistry {
//
// private Map<String, Object> listenerMap = new ConcurrentHashMap<>();
//
// /**
// * 注册监听器。 register listener
// *
// * @param topic
// * @param listener
// */
// public void register(String topic, Object listener) {
//
// Object listener1 = listenerMap.get(topic);
// if (listener1 != null) {
// throw new IllegalArgumentException("Listener with the same topic has been registered! topic=" + topic
// + ". Existed listener " + listener1 + ". New listener " + listener1);
// } else
// listenerMap.put(topic, listener);
//
// }
//
// public Map<String, Object> getListenerMap() {
// return listenerMap;
// }
// }
//
// Path: koper-core/src/main/java/koper/MessageCenter.java
// public interface MessageCenter<T> {
//
// @Deprecated
// T takeMessage();
//
// void putMessage(T msg);
//
// Router getRouter();
//
// }
// Path: koper-core/src/main/java/koper/client/MessageReceiverThread.java
import koper.ListenerRegistry;
import koper.MessageCenter;
import java.util.Properties;
/*
* 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 koper.client;
/**
* ConsumerThread. 每个topic由一个线程接收。
*
* @author kk
* @since 1.0
*/
public class MessageReceiverThread implements Runnable {
private Properties properties;
private MessageReceiver messageReceiver;
private MessageCenter messageCenter; | private ListenerRegistry listenerRegistry; |
KoperGroup/koper | koper-demo/src/main/java/koper/demo/dataevent/service/impl/OrderServiceImpl.java | // Path: koper-demo/src/main/java/koper/demo/dataevent/service/OrderService.java
// public interface OrderService {
//
// String insertOrder(Order order);
//
// void updateOrder(Order order);
// }
//
// Path: koper-demo/src/main/java/koper/demo/dataevent/entity/Order.java
// public class Order {
//
// private Integer id;
//
// private String orderNo;
//
// private String createdTime;
//
// public Integer getId() {
// return id;
// }
//
// public void setId(Integer id) {
// this.id = id;
// }
//
// public String getOrderNo() {
// return orderNo;
// }
//
// public void setOrderNo(String orderNo) {
// this.orderNo = orderNo;
// }
//
// public String getCreatedTime() {
// return createdTime;
// }
//
// public void setCreatedTime(String createdTime) {
// this.createdTime = createdTime;
// }
//
// }
//
// Path: koper-demo/src/main/java/koper/demo/dataevent/mapper/OrderMapper.java
// public interface OrderMapper {
//
// Integer insertOrder(Order order);
//
// Integer updateOrder(Order order);
//
// }
| import koper.demo.dataevent.service.OrderService;
import koper.demo.dataevent.entity.Order;
import koper.demo.dataevent.mapper.OrderMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; | /*
* 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 koper.demo.dataevent.service.impl;
/**
* @author caie
* @since 1.2
*/
@Service
public class OrderServiceImpl implements OrderService {
@Autowired | // Path: koper-demo/src/main/java/koper/demo/dataevent/service/OrderService.java
// public interface OrderService {
//
// String insertOrder(Order order);
//
// void updateOrder(Order order);
// }
//
// Path: koper-demo/src/main/java/koper/demo/dataevent/entity/Order.java
// public class Order {
//
// private Integer id;
//
// private String orderNo;
//
// private String createdTime;
//
// public Integer getId() {
// return id;
// }
//
// public void setId(Integer id) {
// this.id = id;
// }
//
// public String getOrderNo() {
// return orderNo;
// }
//
// public void setOrderNo(String orderNo) {
// this.orderNo = orderNo;
// }
//
// public String getCreatedTime() {
// return createdTime;
// }
//
// public void setCreatedTime(String createdTime) {
// this.createdTime = createdTime;
// }
//
// }
//
// Path: koper-demo/src/main/java/koper/demo/dataevent/mapper/OrderMapper.java
// public interface OrderMapper {
//
// Integer insertOrder(Order order);
//
// Integer updateOrder(Order order);
//
// }
// Path: koper-demo/src/main/java/koper/demo/dataevent/service/impl/OrderServiceImpl.java
import koper.demo.dataevent.service.OrderService;
import koper.demo.dataevent.entity.Order;
import koper.demo.dataevent.mapper.OrderMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
/*
* 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 koper.demo.dataevent.service.impl;
/**
* @author caie
* @since 1.2
*/
@Service
public class OrderServiceImpl implements OrderService {
@Autowired | private OrderMapper orderMapper; |
KoperGroup/koper | koper-demo/src/main/java/koper/demo/dataevent/service/impl/OrderServiceImpl.java | // Path: koper-demo/src/main/java/koper/demo/dataevent/service/OrderService.java
// public interface OrderService {
//
// String insertOrder(Order order);
//
// void updateOrder(Order order);
// }
//
// Path: koper-demo/src/main/java/koper/demo/dataevent/entity/Order.java
// public class Order {
//
// private Integer id;
//
// private String orderNo;
//
// private String createdTime;
//
// public Integer getId() {
// return id;
// }
//
// public void setId(Integer id) {
// this.id = id;
// }
//
// public String getOrderNo() {
// return orderNo;
// }
//
// public void setOrderNo(String orderNo) {
// this.orderNo = orderNo;
// }
//
// public String getCreatedTime() {
// return createdTime;
// }
//
// public void setCreatedTime(String createdTime) {
// this.createdTime = createdTime;
// }
//
// }
//
// Path: koper-demo/src/main/java/koper/demo/dataevent/mapper/OrderMapper.java
// public interface OrderMapper {
//
// Integer insertOrder(Order order);
//
// Integer updateOrder(Order order);
//
// }
| import koper.demo.dataevent.service.OrderService;
import koper.demo.dataevent.entity.Order;
import koper.demo.dataevent.mapper.OrderMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; | /*
* 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 koper.demo.dataevent.service.impl;
/**
* @author caie
* @since 1.2
*/
@Service
public class OrderServiceImpl implements OrderService {
@Autowired
private OrderMapper orderMapper;
| // Path: koper-demo/src/main/java/koper/demo/dataevent/service/OrderService.java
// public interface OrderService {
//
// String insertOrder(Order order);
//
// void updateOrder(Order order);
// }
//
// Path: koper-demo/src/main/java/koper/demo/dataevent/entity/Order.java
// public class Order {
//
// private Integer id;
//
// private String orderNo;
//
// private String createdTime;
//
// public Integer getId() {
// return id;
// }
//
// public void setId(Integer id) {
// this.id = id;
// }
//
// public String getOrderNo() {
// return orderNo;
// }
//
// public void setOrderNo(String orderNo) {
// this.orderNo = orderNo;
// }
//
// public String getCreatedTime() {
// return createdTime;
// }
//
// public void setCreatedTime(String createdTime) {
// this.createdTime = createdTime;
// }
//
// }
//
// Path: koper-demo/src/main/java/koper/demo/dataevent/mapper/OrderMapper.java
// public interface OrderMapper {
//
// Integer insertOrder(Order order);
//
// Integer updateOrder(Order order);
//
// }
// Path: koper-demo/src/main/java/koper/demo/dataevent/service/impl/OrderServiceImpl.java
import koper.demo.dataevent.service.OrderService;
import koper.demo.dataevent.entity.Order;
import koper.demo.dataevent.mapper.OrderMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
/*
* 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 koper.demo.dataevent.service.impl;
/**
* @author caie
* @since 1.2
*/
@Service
public class OrderServiceImpl implements OrderService {
@Autowired
private OrderMapper orderMapper;
| public String insertOrder(Order order) { |
KoperGroup/koper | koper-testcase/src/test/java/koper/kafka/KafkaReceiverTest.java | // Path: koper-core/src/main/java/koper/client/ConsumerLauncher.java
// public interface ConsumerLauncher {
//
// /**
// * start consumer
// */
// public void start();
//
// void setAutoStart(boolean autoStart);
//
// void setPartitions(int partitions);
//
// /**
// * @param threads
// */
// void setDispatcherThreads(int threads);
//
// /**
// * @return
// */
// public ListenerRegistry getListenerRegistry();
// }
| import koper.client.ConsumerLauncher;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext; | /*
* 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 koper.kafka;
/**
* @author kk
* @since 1.0
*/
public class KafkaReceiverTest {
private static Logger logger = LoggerFactory.getLogger(KafkaReceiverTest.class);
public static void main(String[] args) {
final ApplicationContext context =
new ClassPathXmlApplicationContext("classpath:kafka/context-data-consumer.xml");
| // Path: koper-core/src/main/java/koper/client/ConsumerLauncher.java
// public interface ConsumerLauncher {
//
// /**
// * start consumer
// */
// public void start();
//
// void setAutoStart(boolean autoStart);
//
// void setPartitions(int partitions);
//
// /**
// * @param threads
// */
// void setDispatcherThreads(int threads);
//
// /**
// * @return
// */
// public ListenerRegistry getListenerRegistry();
// }
// Path: koper-testcase/src/test/java/koper/kafka/KafkaReceiverTest.java
import koper.client.ConsumerLauncher;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
/*
* 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 koper.kafka;
/**
* @author kk
* @since 1.0
*/
public class KafkaReceiverTest {
private static Logger logger = LoggerFactory.getLogger(KafkaReceiverTest.class);
public static void main(String[] args) {
final ApplicationContext context =
new ClassPathXmlApplicationContext("classpath:kafka/context-data-consumer.xml");
| final ConsumerLauncher consumerLauncher = context.getBean(ConsumerLauncher.class); |
KoperGroup/koper | koper-reactor/src/main/java/koper/reactor/ReactorRef.java | // Path: koper-core/src/main/java/koper/sender/MessageSender.java
// public interface MessageSender {
//
// void send(String topic, String msg);
//
// void send(String topic, String key, String msg);
//
// void send(String topic, Object msg);
//
// void send(String topic, String key, Object msg);
// }
| import java.util.Random;
import koper.sender.MessageSender; | /*
* 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 koper.reactor;
/**
* ReactorRef
* @author Raymond He, [email protected]
* @since 1.0
* 2016年8月26日
*
*/
public class ReactorRef {
private long id;
private Class<? extends Reactor> reactorClass; | // Path: koper-core/src/main/java/koper/sender/MessageSender.java
// public interface MessageSender {
//
// void send(String topic, String msg);
//
// void send(String topic, String key, String msg);
//
// void send(String topic, Object msg);
//
// void send(String topic, String key, Object msg);
// }
// Path: koper-reactor/src/main/java/koper/reactor/ReactorRef.java
import java.util.Random;
import koper.sender.MessageSender;
/*
* 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 koper.reactor;
/**
* ReactorRef
* @author Raymond He, [email protected]
* @since 1.0
* 2016年8月26日
*
*/
public class ReactorRef {
private long id;
private Class<? extends Reactor> reactorClass; | public MessageSender messageSender; |
KoperGroup/koper | koper-dataevent/src/main/java/koper/event/AbstractDataEventListener.java | // Path: koper-core/src/main/java/koper/MsgBean.java
// public class MsgBean<K, V> implements Serializable {
//
// private static final long serialVersionUID = -4387811273059946901L;
//
// private String topic;
// private K key;
// private V value;
// private String valueType;
//
// private Date produceTime;
// private String produceIP;
// private long producePid;
// private long produceTid;
//
// private Date receiveTime;
// private Date consumeTime;
// private String cosumerIP;
// private long consumerPid;
// private long cosumerTid;
//
// public String getTopic() {
// return topic;
// }
//
// public void setTopic(String topic) {
// this.topic = topic;
// }
//
// public K getKey() {
// return key;
// }
//
// public void setKey(K key) {
// this.key = key;
// }
//
// public V getValue() {
// return value;
// }
//
// public void setValue(V value) {
// this.value = value;
// }
//
// public String getValueType() {
// return valueType;
// }
//
// public void setValueType(String valueType) {
// this.valueType = valueType;
// }
//
// public Date getProduceTime() {
// return produceTime;
// }
//
// public void setProduceTime(Date produceTime) {
// this.produceTime = produceTime;
// }
//
// /**
// * @param receiveTime the receiveTime to set
// */
// public void setReceiveTime(Date receiveTime) {
// this.receiveTime = receiveTime;
// }
//
// /**
// * @return the receiveTime
// */
// public Date getReceiveTime() {
// return receiveTime;
// }
//
// public Date getConsumeTime() {
// return consumeTime;
// }
//
// public void setConsumeTime(Date consumeTime) {
// this.consumeTime = consumeTime;
// }
//
//
// public String getProduceIP() {
// return produceIP;
// }
//
// public void setProduceIP(String produceIP) {
// this.produceIP = produceIP;
// }
//
// public long getProducePid() {
// return producePid;
// }
//
// public void setProducePid(long producePid) {
// this.producePid = producePid;
// }
//
// public long getProduceTid() {
// return produceTid;
// }
//
// public void setProduceTid(long produceTid) {
// this.produceTid = produceTid;
// }
//
// public String getConsumerIP() {
// return cosumerIP;
// }
//
// public void setConsumerIP(String cosumerIP) {
// this.cosumerIP = cosumerIP;
// }
//
// public long getConsumerPid() {
// return consumerPid;
// }
//
// public void setConsumerPid(long ccosumerPid) {
// this.consumerPid = ccosumerPid;
// }
//
// public long getConsumerTid() {
// return cosumerTid;
// }
//
// public void setConsumerTid(long cosumerTid) {
// this.cosumerTid = cosumerTid;
// }
//
// public long getReceiveUseTime() {
// return consumeTime == null || produceTime == null ? -1 : receiveTime.getTime() - produceTime.getTime();
// }
//
// public long getConsumeUseTime() {
// return consumeTime == null || produceTime == null ? -1 : consumeTime.getTime() - produceTime.getTime();
// }
//
// @Override
// public boolean equals(Object obj) {
// //TODO:待实现
// return super.equals(obj);
// }
//
// @Override
// public String toString() {
// return ToStringBuilder.reflectionToString(this);
// }
//
//
// }
| import koper.MsgBean;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory; | /*
* 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 koper.event;
/**
* AbstractDataEventListener
*
* @author kk [email protected]
* @since 1.0
* 2016年2月19日
*/
public abstract class AbstractDataEventListener implements DataEventListener {
private static Logger log = LoggerFactory.getLogger(AbstractDataEventListener.class);
/**
* @see DataEventListener#dataObjectName()
*/
@Override
public abstract String dataObjectName();
/**
* @param msgBean
* @see MessageListener#onMessage(String)
*/ | // Path: koper-core/src/main/java/koper/MsgBean.java
// public class MsgBean<K, V> implements Serializable {
//
// private static final long serialVersionUID = -4387811273059946901L;
//
// private String topic;
// private K key;
// private V value;
// private String valueType;
//
// private Date produceTime;
// private String produceIP;
// private long producePid;
// private long produceTid;
//
// private Date receiveTime;
// private Date consumeTime;
// private String cosumerIP;
// private long consumerPid;
// private long cosumerTid;
//
// public String getTopic() {
// return topic;
// }
//
// public void setTopic(String topic) {
// this.topic = topic;
// }
//
// public K getKey() {
// return key;
// }
//
// public void setKey(K key) {
// this.key = key;
// }
//
// public V getValue() {
// return value;
// }
//
// public void setValue(V value) {
// this.value = value;
// }
//
// public String getValueType() {
// return valueType;
// }
//
// public void setValueType(String valueType) {
// this.valueType = valueType;
// }
//
// public Date getProduceTime() {
// return produceTime;
// }
//
// public void setProduceTime(Date produceTime) {
// this.produceTime = produceTime;
// }
//
// /**
// * @param receiveTime the receiveTime to set
// */
// public void setReceiveTime(Date receiveTime) {
// this.receiveTime = receiveTime;
// }
//
// /**
// * @return the receiveTime
// */
// public Date getReceiveTime() {
// return receiveTime;
// }
//
// public Date getConsumeTime() {
// return consumeTime;
// }
//
// public void setConsumeTime(Date consumeTime) {
// this.consumeTime = consumeTime;
// }
//
//
// public String getProduceIP() {
// return produceIP;
// }
//
// public void setProduceIP(String produceIP) {
// this.produceIP = produceIP;
// }
//
// public long getProducePid() {
// return producePid;
// }
//
// public void setProducePid(long producePid) {
// this.producePid = producePid;
// }
//
// public long getProduceTid() {
// return produceTid;
// }
//
// public void setProduceTid(long produceTid) {
// this.produceTid = produceTid;
// }
//
// public String getConsumerIP() {
// return cosumerIP;
// }
//
// public void setConsumerIP(String cosumerIP) {
// this.cosumerIP = cosumerIP;
// }
//
// public long getConsumerPid() {
// return consumerPid;
// }
//
// public void setConsumerPid(long ccosumerPid) {
// this.consumerPid = ccosumerPid;
// }
//
// public long getConsumerTid() {
// return cosumerTid;
// }
//
// public void setConsumerTid(long cosumerTid) {
// this.cosumerTid = cosumerTid;
// }
//
// public long getReceiveUseTime() {
// return consumeTime == null || produceTime == null ? -1 : receiveTime.getTime() - produceTime.getTime();
// }
//
// public long getConsumeUseTime() {
// return consumeTime == null || produceTime == null ? -1 : consumeTime.getTime() - produceTime.getTime();
// }
//
// @Override
// public boolean equals(Object obj) {
// //TODO:待实现
// return super.equals(obj);
// }
//
// @Override
// public String toString() {
// return ToStringBuilder.reflectionToString(this);
// }
//
//
// }
// Path: koper-dataevent/src/main/java/koper/event/AbstractDataEventListener.java
import koper.MsgBean;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/*
* 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 koper.event;
/**
* AbstractDataEventListener
*
* @author kk [email protected]
* @since 1.0
* 2016年2月19日
*/
public abstract class AbstractDataEventListener implements DataEventListener {
private static Logger log = LoggerFactory.getLogger(AbstractDataEventListener.class);
/**
* @see DataEventListener#dataObjectName()
*/
@Override
public abstract String dataObjectName();
/**
* @param msgBean
* @see MessageListener#onMessage(String)
*/ | public void onMsgBean(MsgBean<String, String> msgBean) { |
KoperGroup/koper | koper-demo/src/main/java/koper/demo/main/SendDataEventMsgDemo.java | // Path: koper-demo/src/main/java/koper/demo/dataevent/entity/Order.java
// public class Order {
//
// private Integer id;
//
// private String orderNo;
//
// private String createdTime;
//
// public Integer getId() {
// return id;
// }
//
// public void setId(Integer id) {
// this.id = id;
// }
//
// public String getOrderNo() {
// return orderNo;
// }
//
// public void setOrderNo(String orderNo) {
// this.orderNo = orderNo;
// }
//
// public String getCreatedTime() {
// return createdTime;
// }
//
// public void setCreatedTime(String createdTime) {
// this.createdTime = createdTime;
// }
//
// }
//
// Path: koper-demo/src/main/java/koper/demo/dataevent/service/OrderService.java
// public interface OrderService {
//
// String insertOrder(Order order);
//
// void updateOrder(Order order);
// }
| import koper.demo.dataevent.entity.Order;
import koper.demo.dataevent.service.OrderService;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext; | /*
* 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 koper.demo.main;
/**
* @author caie
* @since 1.2
*/
public class SendDataEventMsgDemo {
public static void main(String[] args) {
ApplicationContext context = new ClassPathXmlApplicationContext(
"kafka/context-data-message.xml",
"kafka/context-data-producer.xml");
| // Path: koper-demo/src/main/java/koper/demo/dataevent/entity/Order.java
// public class Order {
//
// private Integer id;
//
// private String orderNo;
//
// private String createdTime;
//
// public Integer getId() {
// return id;
// }
//
// public void setId(Integer id) {
// this.id = id;
// }
//
// public String getOrderNo() {
// return orderNo;
// }
//
// public void setOrderNo(String orderNo) {
// this.orderNo = orderNo;
// }
//
// public String getCreatedTime() {
// return createdTime;
// }
//
// public void setCreatedTime(String createdTime) {
// this.createdTime = createdTime;
// }
//
// }
//
// Path: koper-demo/src/main/java/koper/demo/dataevent/service/OrderService.java
// public interface OrderService {
//
// String insertOrder(Order order);
//
// void updateOrder(Order order);
// }
// Path: koper-demo/src/main/java/koper/demo/main/SendDataEventMsgDemo.java
import koper.demo.dataevent.entity.Order;
import koper.demo.dataevent.service.OrderService;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
/*
* 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 koper.demo.main;
/**
* @author caie
* @since 1.2
*/
public class SendDataEventMsgDemo {
public static void main(String[] args) {
ApplicationContext context = new ClassPathXmlApplicationContext(
"kafka/context-data-message.xml",
"kafka/context-data-producer.xml");
| Order order = new Order(); |
KoperGroup/koper | koper-demo/src/main/java/koper/demo/main/SendDataEventMsgDemo.java | // Path: koper-demo/src/main/java/koper/demo/dataevent/entity/Order.java
// public class Order {
//
// private Integer id;
//
// private String orderNo;
//
// private String createdTime;
//
// public Integer getId() {
// return id;
// }
//
// public void setId(Integer id) {
// this.id = id;
// }
//
// public String getOrderNo() {
// return orderNo;
// }
//
// public void setOrderNo(String orderNo) {
// this.orderNo = orderNo;
// }
//
// public String getCreatedTime() {
// return createdTime;
// }
//
// public void setCreatedTime(String createdTime) {
// this.createdTime = createdTime;
// }
//
// }
//
// Path: koper-demo/src/main/java/koper/demo/dataevent/service/OrderService.java
// public interface OrderService {
//
// String insertOrder(Order order);
//
// void updateOrder(Order order);
// }
| import koper.demo.dataevent.entity.Order;
import koper.demo.dataevent.service.OrderService;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext; | /*
* 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 koper.demo.main;
/**
* @author caie
* @since 1.2
*/
public class SendDataEventMsgDemo {
public static void main(String[] args) {
ApplicationContext context = new ClassPathXmlApplicationContext(
"kafka/context-data-message.xml",
"kafka/context-data-producer.xml");
Order order = new Order();
order.setId(100);
order.setOrderNo("order_no");
order.setCreatedTime("oroder_created_time");
| // Path: koper-demo/src/main/java/koper/demo/dataevent/entity/Order.java
// public class Order {
//
// private Integer id;
//
// private String orderNo;
//
// private String createdTime;
//
// public Integer getId() {
// return id;
// }
//
// public void setId(Integer id) {
// this.id = id;
// }
//
// public String getOrderNo() {
// return orderNo;
// }
//
// public void setOrderNo(String orderNo) {
// this.orderNo = orderNo;
// }
//
// public String getCreatedTime() {
// return createdTime;
// }
//
// public void setCreatedTime(String createdTime) {
// this.createdTime = createdTime;
// }
//
// }
//
// Path: koper-demo/src/main/java/koper/demo/dataevent/service/OrderService.java
// public interface OrderService {
//
// String insertOrder(Order order);
//
// void updateOrder(Order order);
// }
// Path: koper-demo/src/main/java/koper/demo/main/SendDataEventMsgDemo.java
import koper.demo.dataevent.entity.Order;
import koper.demo.dataevent.service.OrderService;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
/*
* 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 koper.demo.main;
/**
* @author caie
* @since 1.2
*/
public class SendDataEventMsgDemo {
public static void main(String[] args) {
ApplicationContext context = new ClassPathXmlApplicationContext(
"kafka/context-data-message.xml",
"kafka/context-data-producer.xml");
Order order = new Order();
order.setId(100);
order.setOrderNo("order_no");
order.setCreatedTime("oroder_created_time");
| OrderService orderService = (OrderService) context.getBean("orderServiceImpl"); |
KoperGroup/koper | koper-demo/src/main/java/koper/demo/dataevent/mapper/impl/OrderMapperImpl.java | // Path: koper-demo/src/main/java/koper/demo/dataevent/entity/Order.java
// public class Order {
//
// private Integer id;
//
// private String orderNo;
//
// private String createdTime;
//
// public Integer getId() {
// return id;
// }
//
// public void setId(Integer id) {
// this.id = id;
// }
//
// public String getOrderNo() {
// return orderNo;
// }
//
// public void setOrderNo(String orderNo) {
// this.orderNo = orderNo;
// }
//
// public String getCreatedTime() {
// return createdTime;
// }
//
// public void setCreatedTime(String createdTime) {
// this.createdTime = createdTime;
// }
//
// }
//
// Path: koper-demo/src/main/java/koper/demo/dataevent/mapper/OrderMapper.java
// public interface OrderMapper {
//
// Integer insertOrder(Order order);
//
// Integer updateOrder(Order order);
//
// }
| import koper.demo.dataevent.entity.Order;
import koper.demo.dataevent.mapper.OrderMapper;
import org.springframework.stereotype.Repository; | /*
* 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 koper.demo.dataevent.mapper.impl;
/**
* @author caie
* @since 1.2
*/
@Repository
public class OrderMapperImpl implements OrderMapper {
@Override | // Path: koper-demo/src/main/java/koper/demo/dataevent/entity/Order.java
// public class Order {
//
// private Integer id;
//
// private String orderNo;
//
// private String createdTime;
//
// public Integer getId() {
// return id;
// }
//
// public void setId(Integer id) {
// this.id = id;
// }
//
// public String getOrderNo() {
// return orderNo;
// }
//
// public void setOrderNo(String orderNo) {
// this.orderNo = orderNo;
// }
//
// public String getCreatedTime() {
// return createdTime;
// }
//
// public void setCreatedTime(String createdTime) {
// this.createdTime = createdTime;
// }
//
// }
//
// Path: koper-demo/src/main/java/koper/demo/dataevent/mapper/OrderMapper.java
// public interface OrderMapper {
//
// Integer insertOrder(Order order);
//
// Integer updateOrder(Order order);
//
// }
// Path: koper-demo/src/main/java/koper/demo/dataevent/mapper/impl/OrderMapperImpl.java
import koper.demo.dataevent.entity.Order;
import koper.demo.dataevent.mapper.OrderMapper;
import org.springframework.stereotype.Repository;
/*
* 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 koper.demo.dataevent.mapper.impl;
/**
* @author caie
* @since 1.2
*/
@Repository
public class OrderMapperImpl implements OrderMapper {
@Override | public Integer insertOrder(Order order) { |
KoperGroup/koper | koper-demo/src/main/java/koper/demo/main/KafkaReceiverDemo.java | // Path: koper-core/src/main/java/koper/client/ConsumerLauncher.java
// public interface ConsumerLauncher {
//
// /**
// * start consumer
// */
// public void start();
//
// void setAutoStart(boolean autoStart);
//
// void setPartitions(int partitions);
//
// /**
// * @param threads
// */
// void setDispatcherThreads(int threads);
//
// /**
// * @return
// */
// public ListenerRegistry getListenerRegistry();
// }
| import koper.client.ConsumerLauncher;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext; | /*
* 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 koper.demo.main;
/**
* @author kk
* @since 1.0
*/
public class KafkaReceiverDemo {
private static Logger logger = LoggerFactory.getLogger(KafkaReceiverDemo.class);
public static void main(String[] args) {
final ApplicationContext context =
new ClassPathXmlApplicationContext("classpath:kafka/context-data-consumer.xml");
| // Path: koper-core/src/main/java/koper/client/ConsumerLauncher.java
// public interface ConsumerLauncher {
//
// /**
// * start consumer
// */
// public void start();
//
// void setAutoStart(boolean autoStart);
//
// void setPartitions(int partitions);
//
// /**
// * @param threads
// */
// void setDispatcherThreads(int threads);
//
// /**
// * @return
// */
// public ListenerRegistry getListenerRegistry();
// }
// Path: koper-demo/src/main/java/koper/demo/main/KafkaReceiverDemo.java
import koper.client.ConsumerLauncher;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
/*
* 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 koper.demo.main;
/**
* @author kk
* @since 1.0
*/
public class KafkaReceiverDemo {
private static Logger logger = LoggerFactory.getLogger(KafkaReceiverDemo.class);
public static void main(String[] args) {
final ApplicationContext context =
new ClassPathXmlApplicationContext("classpath:kafka/context-data-consumer.xml");
| final ConsumerLauncher consumerLauncher = context.getBean(ConsumerLauncher.class); |
KoperGroup/koper | koper-testcase/src/main/java/koper/listener/DemoListener1.java | // Path: koper-core/src/main/java/koper/AbstractMessageListener.java
// public abstract class AbstractMessageListener implements MessageListener {
//
// @Override
// public void onMsgBean(MsgBean<String, String> msgBean) {
//
// }
//
// @Override
// public void onMessage(String msg) {
// }
// }
//
// Path: koper-testcase/src/main/java/koper/demo/trading/mapper/Order.java
// public class Order {
//
// public String orderId;
// public String orderName;
// public Date createDate;
// public String memberId;
// public BigDecimal totalPrice;
//
// public String getOrderId() {
// return orderId;
// }
// public void setOrderId(String orderId) {
// this.orderId = orderId;
// }
// public String getOrderName() {
// return orderName;
// }
// public void setOrderName(String orderName) {
// this.orderName = orderName;
// }
// public Date getCreateDate() {
// return createDate;
// }
// public void setCreateDate(Date createDate) {
// this.createDate = createDate;
// }
// public String getMemberId() {
// return memberId;
// }
// public void setMemberId(String memberId) {
// this.memberId = memberId;
// }
// public BigDecimal getTotalPrice() {
// return totalPrice;
// }
// public void setTotalPrice(BigDecimal totalPrice) {
// this.totalPrice = totalPrice;
// }
//
// @Override
// public String toString() {
// return "Order{" +
// "orderId='" + orderId + '\'' +
// ", orderName='" + orderName + '\'' +
// ", createDate=" + createDate +
// ", memberId='" + memberId + '\'' +
// ", totalPrice=" + totalPrice +
// '}';
// }
// }
| import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import koper.AbstractMessageListener;
import koper.Listen;
import koper.demo.trading.mapper.Order;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component; | /*
* 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 koper.listener;
/**
* @author kk
* @since 1.0
*/
@Component
public class DemoListener1 extends AbstractMessageListener {
private static Logger log = LoggerFactory.getLogger(DemoListener1.class);
@Listen(topic = "com.zhaimi.koper.demo.trading.mapper.impl.OrderMapperImpl.updateOrder")
public void onMessage(String msg) {
log.info("DemoListener1接收到updateOrder 消息,message={}", msg);
JSONObject jsonObject = JSON.parseObject(msg);
//args是数组类型
JSONArray argArray = jsonObject.getJSONArray("args");
//result 是 String类型
String result = jsonObject.getString("result");
//第一个参数是Order类型 | // Path: koper-core/src/main/java/koper/AbstractMessageListener.java
// public abstract class AbstractMessageListener implements MessageListener {
//
// @Override
// public void onMsgBean(MsgBean<String, String> msgBean) {
//
// }
//
// @Override
// public void onMessage(String msg) {
// }
// }
//
// Path: koper-testcase/src/main/java/koper/demo/trading/mapper/Order.java
// public class Order {
//
// public String orderId;
// public String orderName;
// public Date createDate;
// public String memberId;
// public BigDecimal totalPrice;
//
// public String getOrderId() {
// return orderId;
// }
// public void setOrderId(String orderId) {
// this.orderId = orderId;
// }
// public String getOrderName() {
// return orderName;
// }
// public void setOrderName(String orderName) {
// this.orderName = orderName;
// }
// public Date getCreateDate() {
// return createDate;
// }
// public void setCreateDate(Date createDate) {
// this.createDate = createDate;
// }
// public String getMemberId() {
// return memberId;
// }
// public void setMemberId(String memberId) {
// this.memberId = memberId;
// }
// public BigDecimal getTotalPrice() {
// return totalPrice;
// }
// public void setTotalPrice(BigDecimal totalPrice) {
// this.totalPrice = totalPrice;
// }
//
// @Override
// public String toString() {
// return "Order{" +
// "orderId='" + orderId + '\'' +
// ", orderName='" + orderName + '\'' +
// ", createDate=" + createDate +
// ", memberId='" + memberId + '\'' +
// ", totalPrice=" + totalPrice +
// '}';
// }
// }
// Path: koper-testcase/src/main/java/koper/listener/DemoListener1.java
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import koper.AbstractMessageListener;
import koper.Listen;
import koper.demo.trading.mapper.Order;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
/*
* 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 koper.listener;
/**
* @author kk
* @since 1.0
*/
@Component
public class DemoListener1 extends AbstractMessageListener {
private static Logger log = LoggerFactory.getLogger(DemoListener1.class);
@Listen(topic = "com.zhaimi.koper.demo.trading.mapper.impl.OrderMapperImpl.updateOrder")
public void onMessage(String msg) {
log.info("DemoListener1接收到updateOrder 消息,message={}", msg);
JSONObject jsonObject = JSON.parseObject(msg);
//args是数组类型
JSONArray argArray = jsonObject.getJSONArray("args");
//result 是 String类型
String result = jsonObject.getString("result");
//第一个参数是Order类型 | Order order = JSON.parseObject(argArray.getString(0), Order.class); |
KoperGroup/koper | koper-testcase/src/main/java/koper/event/OrderLogListener.java | // Path: koper-testcase/src/main/java/koper/demo/trading/mapper/Order.java
// public class Order {
//
// public String orderId;
// public String orderName;
// public Date createDate;
// public String memberId;
// public BigDecimal totalPrice;
//
// public String getOrderId() {
// return orderId;
// }
// public void setOrderId(String orderId) {
// this.orderId = orderId;
// }
// public String getOrderName() {
// return orderName;
// }
// public void setOrderName(String orderName) {
// this.orderName = orderName;
// }
// public Date getCreateDate() {
// return createDate;
// }
// public void setCreateDate(Date createDate) {
// this.createDate = createDate;
// }
// public String getMemberId() {
// return memberId;
// }
// public void setMemberId(String memberId) {
// this.memberId = memberId;
// }
// public BigDecimal getTotalPrice() {
// return totalPrice;
// }
// public void setTotalPrice(BigDecimal totalPrice) {
// this.totalPrice = totalPrice;
// }
//
// @Override
// public String toString() {
// return "Order{" +
// "orderId='" + orderId + '\'' +
// ", orderName='" + orderName + '\'' +
// ", createDate=" + createDate +
// ", memberId='" + memberId + '\'' +
// ", totalPrice=" + totalPrice +
// '}';
// }
// }
| import com.alibaba.fastjson.JSON;
import koper.demo.trading.mapper.Order;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import java.util.List; | /*
* 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 koper.event;
/**
* InsertOrderListener. 订单日志监听器
*
* @author kk [email protected]
* @since 1.0
* 2016年3月21日
*/
@Component
@DataListener(dataObject="com.zhaimi.koper.demo.trading.mapper.impl.OrderMapperImpl")
public class OrderLogListener {
private static Logger log = LoggerFactory.getLogger(OrderLogListener.class);
public void onCancelOrder_B(DataEvent event) {
log.info("onCancelOrder_B" + event.getArgs());
}
/**
* deleteOrder事件响应处理方法
* 从event中获取数据:输入参数args,返回值 result。
* 数据格式为JSON。使用 fastjson工具类 进行解析
* @param event
*/
public void onCancelOrder(DataEvent event) {
List<?> args = event.getArgs();
//数据解析:需要根据生产接口定义的参数个数,数据类型进行解析
//根据定义,第一个参数String类型
//根据定义,第二个参数类型为 Order 类型 | // Path: koper-testcase/src/main/java/koper/demo/trading/mapper/Order.java
// public class Order {
//
// public String orderId;
// public String orderName;
// public Date createDate;
// public String memberId;
// public BigDecimal totalPrice;
//
// public String getOrderId() {
// return orderId;
// }
// public void setOrderId(String orderId) {
// this.orderId = orderId;
// }
// public String getOrderName() {
// return orderName;
// }
// public void setOrderName(String orderName) {
// this.orderName = orderName;
// }
// public Date getCreateDate() {
// return createDate;
// }
// public void setCreateDate(Date createDate) {
// this.createDate = createDate;
// }
// public String getMemberId() {
// return memberId;
// }
// public void setMemberId(String memberId) {
// this.memberId = memberId;
// }
// public BigDecimal getTotalPrice() {
// return totalPrice;
// }
// public void setTotalPrice(BigDecimal totalPrice) {
// this.totalPrice = totalPrice;
// }
//
// @Override
// public String toString() {
// return "Order{" +
// "orderId='" + orderId + '\'' +
// ", orderName='" + orderName + '\'' +
// ", createDate=" + createDate +
// ", memberId='" + memberId + '\'' +
// ", totalPrice=" + totalPrice +
// '}';
// }
// }
// Path: koper-testcase/src/main/java/koper/event/OrderLogListener.java
import com.alibaba.fastjson.JSON;
import koper.demo.trading.mapper.Order;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import java.util.List;
/*
* 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 koper.event;
/**
* InsertOrderListener. 订单日志监听器
*
* @author kk [email protected]
* @since 1.0
* 2016年3月21日
*/
@Component
@DataListener(dataObject="com.zhaimi.koper.demo.trading.mapper.impl.OrderMapperImpl")
public class OrderLogListener {
private static Logger log = LoggerFactory.getLogger(OrderLogListener.class);
public void onCancelOrder_B(DataEvent event) {
log.info("onCancelOrder_B" + event.getArgs());
}
/**
* deleteOrder事件响应处理方法
* 从event中获取数据:输入参数args,返回值 result。
* 数据格式为JSON。使用 fastjson工具类 进行解析
* @param event
*/
public void onCancelOrder(DataEvent event) {
List<?> args = event.getArgs();
//数据解析:需要根据生产接口定义的参数个数,数据类型进行解析
//根据定义,第一个参数String类型
//根据定义,第二个参数类型为 Order 类型 | Order order = JSON.parseObject( args.get(0).toString(),Order.class); |
KoperGroup/koper | koper-demo/src/main/java/koper/demo/message/listener/MemberSignupListener.java | // Path: koper-core/src/main/java/koper/AbstractMessageListener.java
// public abstract class AbstractMessageListener implements MessageListener {
//
// @Override
// public void onMsgBean(MsgBean<String, String> msgBean) {
//
// }
//
// @Override
// public void onMessage(String msg) {
// }
// }
//
// Path: koper-demo/src/main/java/koper/demo/message/service/SmsService.java
// @Service
// public class SmsService {
//
// public void sendSms(String msg) {
// // send sms
// }
// }
| import koper.AbstractMessageListener;
import koper.Listen;
import koper.demo.message.service.SmsService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component; | /*
* 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 koper.demo.message.listener;
/**
* @author caie
* @since 1.2
*/
@Component
public class MemberSignupListener extends AbstractMessageListener {
@Autowired | // Path: koper-core/src/main/java/koper/AbstractMessageListener.java
// public abstract class AbstractMessageListener implements MessageListener {
//
// @Override
// public void onMsgBean(MsgBean<String, String> msgBean) {
//
// }
//
// @Override
// public void onMessage(String msg) {
// }
// }
//
// Path: koper-demo/src/main/java/koper/demo/message/service/SmsService.java
// @Service
// public class SmsService {
//
// public void sendSms(String msg) {
// // send sms
// }
// }
// Path: koper-demo/src/main/java/koper/demo/message/listener/MemberSignupListener.java
import koper.AbstractMessageListener;
import koper.Listen;
import koper.demo.message.service.SmsService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
/*
* 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 koper.demo.message.listener;
/**
* @author caie
* @since 1.2
*/
@Component
public class MemberSignupListener extends AbstractMessageListener {
@Autowired | private SmsService smsService; |
KoperGroup/koper | koper-dataevent/src/main/java/koper/event/DefaultDataEvent.java | // Path: koper-core/src/main/java/koper/MsgBean.java
// public class MsgBean<K, V> implements Serializable {
//
// private static final long serialVersionUID = -4387811273059946901L;
//
// private String topic;
// private K key;
// private V value;
// private String valueType;
//
// private Date produceTime;
// private String produceIP;
// private long producePid;
// private long produceTid;
//
// private Date receiveTime;
// private Date consumeTime;
// private String cosumerIP;
// private long consumerPid;
// private long cosumerTid;
//
// public String getTopic() {
// return topic;
// }
//
// public void setTopic(String topic) {
// this.topic = topic;
// }
//
// public K getKey() {
// return key;
// }
//
// public void setKey(K key) {
// this.key = key;
// }
//
// public V getValue() {
// return value;
// }
//
// public void setValue(V value) {
// this.value = value;
// }
//
// public String getValueType() {
// return valueType;
// }
//
// public void setValueType(String valueType) {
// this.valueType = valueType;
// }
//
// public Date getProduceTime() {
// return produceTime;
// }
//
// public void setProduceTime(Date produceTime) {
// this.produceTime = produceTime;
// }
//
// /**
// * @param receiveTime the receiveTime to set
// */
// public void setReceiveTime(Date receiveTime) {
// this.receiveTime = receiveTime;
// }
//
// /**
// * @return the receiveTime
// */
// public Date getReceiveTime() {
// return receiveTime;
// }
//
// public Date getConsumeTime() {
// return consumeTime;
// }
//
// public void setConsumeTime(Date consumeTime) {
// this.consumeTime = consumeTime;
// }
//
//
// public String getProduceIP() {
// return produceIP;
// }
//
// public void setProduceIP(String produceIP) {
// this.produceIP = produceIP;
// }
//
// public long getProducePid() {
// return producePid;
// }
//
// public void setProducePid(long producePid) {
// this.producePid = producePid;
// }
//
// public long getProduceTid() {
// return produceTid;
// }
//
// public void setProduceTid(long produceTid) {
// this.produceTid = produceTid;
// }
//
// public String getConsumerIP() {
// return cosumerIP;
// }
//
// public void setConsumerIP(String cosumerIP) {
// this.cosumerIP = cosumerIP;
// }
//
// public long getConsumerPid() {
// return consumerPid;
// }
//
// public void setConsumerPid(long ccosumerPid) {
// this.consumerPid = ccosumerPid;
// }
//
// public long getConsumerTid() {
// return cosumerTid;
// }
//
// public void setConsumerTid(long cosumerTid) {
// this.cosumerTid = cosumerTid;
// }
//
// public long getReceiveUseTime() {
// return consumeTime == null || produceTime == null ? -1 : receiveTime.getTime() - produceTime.getTime();
// }
//
// public long getConsumeUseTime() {
// return consumeTime == null || produceTime == null ? -1 : consumeTime.getTime() - produceTime.getTime();
// }
//
// @Override
// public boolean equals(Object obj) {
// //TODO:待实现
// return super.equals(obj);
// }
//
// @Override
// public String toString() {
// return ToStringBuilder.reflectionToString(this);
// }
//
//
// }
| import koper.MsgBean;
import java.util.List; | /*
* 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 koper.event;
/**
* DefaultDataEvent
*
* @author kk [email protected]
* @since 1.0
* 2016年2月19日
*/
public class DefaultDataEvent implements DataEvent {
private String topic;
private String dataObjectName;
private String eventName; | // Path: koper-core/src/main/java/koper/MsgBean.java
// public class MsgBean<K, V> implements Serializable {
//
// private static final long serialVersionUID = -4387811273059946901L;
//
// private String topic;
// private K key;
// private V value;
// private String valueType;
//
// private Date produceTime;
// private String produceIP;
// private long producePid;
// private long produceTid;
//
// private Date receiveTime;
// private Date consumeTime;
// private String cosumerIP;
// private long consumerPid;
// private long cosumerTid;
//
// public String getTopic() {
// return topic;
// }
//
// public void setTopic(String topic) {
// this.topic = topic;
// }
//
// public K getKey() {
// return key;
// }
//
// public void setKey(K key) {
// this.key = key;
// }
//
// public V getValue() {
// return value;
// }
//
// public void setValue(V value) {
// this.value = value;
// }
//
// public String getValueType() {
// return valueType;
// }
//
// public void setValueType(String valueType) {
// this.valueType = valueType;
// }
//
// public Date getProduceTime() {
// return produceTime;
// }
//
// public void setProduceTime(Date produceTime) {
// this.produceTime = produceTime;
// }
//
// /**
// * @param receiveTime the receiveTime to set
// */
// public void setReceiveTime(Date receiveTime) {
// this.receiveTime = receiveTime;
// }
//
// /**
// * @return the receiveTime
// */
// public Date getReceiveTime() {
// return receiveTime;
// }
//
// public Date getConsumeTime() {
// return consumeTime;
// }
//
// public void setConsumeTime(Date consumeTime) {
// this.consumeTime = consumeTime;
// }
//
//
// public String getProduceIP() {
// return produceIP;
// }
//
// public void setProduceIP(String produceIP) {
// this.produceIP = produceIP;
// }
//
// public long getProducePid() {
// return producePid;
// }
//
// public void setProducePid(long producePid) {
// this.producePid = producePid;
// }
//
// public long getProduceTid() {
// return produceTid;
// }
//
// public void setProduceTid(long produceTid) {
// this.produceTid = produceTid;
// }
//
// public String getConsumerIP() {
// return cosumerIP;
// }
//
// public void setConsumerIP(String cosumerIP) {
// this.cosumerIP = cosumerIP;
// }
//
// public long getConsumerPid() {
// return consumerPid;
// }
//
// public void setConsumerPid(long ccosumerPid) {
// this.consumerPid = ccosumerPid;
// }
//
// public long getConsumerTid() {
// return cosumerTid;
// }
//
// public void setConsumerTid(long cosumerTid) {
// this.cosumerTid = cosumerTid;
// }
//
// public long getReceiveUseTime() {
// return consumeTime == null || produceTime == null ? -1 : receiveTime.getTime() - produceTime.getTime();
// }
//
// public long getConsumeUseTime() {
// return consumeTime == null || produceTime == null ? -1 : consumeTime.getTime() - produceTime.getTime();
// }
//
// @Override
// public boolean equals(Object obj) {
// //TODO:待实现
// return super.equals(obj);
// }
//
// @Override
// public String toString() {
// return ToStringBuilder.reflectionToString(this);
// }
//
//
// }
// Path: koper-dataevent/src/main/java/koper/event/DefaultDataEvent.java
import koper.MsgBean;
import java.util.List;
/*
* 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 koper.event;
/**
* DefaultDataEvent
*
* @author kk [email protected]
* @since 1.0
* 2016年2月19日
*/
public class DefaultDataEvent implements DataEvent {
private String topic;
private String dataObjectName;
private String eventName; | private MsgBean<String, String> msgBean; |
KoperGroup/koper | koper-demo/src/main/java/koper/demo/performance/SendDataEventMsgPerf.java | // Path: koper-demo/src/main/java/koper/demo/dataevent/entity/Order.java
// public class Order {
//
// private Integer id;
//
// private String orderNo;
//
// private String createdTime;
//
// public Integer getId() {
// return id;
// }
//
// public void setId(Integer id) {
// this.id = id;
// }
//
// public String getOrderNo() {
// return orderNo;
// }
//
// public void setOrderNo(String orderNo) {
// this.orderNo = orderNo;
// }
//
// public String getCreatedTime() {
// return createdTime;
// }
//
// public void setCreatedTime(String createdTime) {
// this.createdTime = createdTime;
// }
//
// }
//
// Path: koper-demo/src/main/java/koper/demo/dataevent/service/OrderService.java
// public interface OrderService {
//
// String insertOrder(Order order);
//
// void updateOrder(Order order);
// }
| import koper.demo.dataevent.entity.Order;
import koper.demo.dataevent.service.OrderService;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors; | /*
* 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 koper.demo.performance;
/**
* @author caie
* @since 1.2
*/
public class SendDataEventMsgPerf {
/**
* DataEventMsg 生产者入口
* @param args 第一个命令行参数:设定发送消息的线程数
* 第二个命令行参数:设定每发送一条消息后线程 sleep 的毫秒数
*/
public static void main(String[] args) throws Exception {
ApplicationContext context = new ClassPathXmlApplicationContext(
"kafka/context-data-message.xml",
"kafka/context-data-producer.xml");
| // Path: koper-demo/src/main/java/koper/demo/dataevent/entity/Order.java
// public class Order {
//
// private Integer id;
//
// private String orderNo;
//
// private String createdTime;
//
// public Integer getId() {
// return id;
// }
//
// public void setId(Integer id) {
// this.id = id;
// }
//
// public String getOrderNo() {
// return orderNo;
// }
//
// public void setOrderNo(String orderNo) {
// this.orderNo = orderNo;
// }
//
// public String getCreatedTime() {
// return createdTime;
// }
//
// public void setCreatedTime(String createdTime) {
// this.createdTime = createdTime;
// }
//
// }
//
// Path: koper-demo/src/main/java/koper/demo/dataevent/service/OrderService.java
// public interface OrderService {
//
// String insertOrder(Order order);
//
// void updateOrder(Order order);
// }
// Path: koper-demo/src/main/java/koper/demo/performance/SendDataEventMsgPerf.java
import koper.demo.dataevent.entity.Order;
import koper.demo.dataevent.service.OrderService;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
/*
* 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 koper.demo.performance;
/**
* @author caie
* @since 1.2
*/
public class SendDataEventMsgPerf {
/**
* DataEventMsg 生产者入口
* @param args 第一个命令行参数:设定发送消息的线程数
* 第二个命令行参数:设定每发送一条消息后线程 sleep 的毫秒数
*/
public static void main(String[] args) throws Exception {
ApplicationContext context = new ClassPathXmlApplicationContext(
"kafka/context-data-message.xml",
"kafka/context-data-producer.xml");
| Order order = new Order(); |
KoperGroup/koper | koper-demo/src/main/java/koper/demo/performance/SendDataEventMsgPerf.java | // Path: koper-demo/src/main/java/koper/demo/dataevent/entity/Order.java
// public class Order {
//
// private Integer id;
//
// private String orderNo;
//
// private String createdTime;
//
// public Integer getId() {
// return id;
// }
//
// public void setId(Integer id) {
// this.id = id;
// }
//
// public String getOrderNo() {
// return orderNo;
// }
//
// public void setOrderNo(String orderNo) {
// this.orderNo = orderNo;
// }
//
// public String getCreatedTime() {
// return createdTime;
// }
//
// public void setCreatedTime(String createdTime) {
// this.createdTime = createdTime;
// }
//
// }
//
// Path: koper-demo/src/main/java/koper/demo/dataevent/service/OrderService.java
// public interface OrderService {
//
// String insertOrder(Order order);
//
// void updateOrder(Order order);
// }
| import koper.demo.dataevent.entity.Order;
import koper.demo.dataevent.service.OrderService;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors; | /*
* 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 koper.demo.performance;
/**
* @author caie
* @since 1.2
*/
public class SendDataEventMsgPerf {
/**
* DataEventMsg 生产者入口
* @param args 第一个命令行参数:设定发送消息的线程数
* 第二个命令行参数:设定每发送一条消息后线程 sleep 的毫秒数
*/
public static void main(String[] args) throws Exception {
ApplicationContext context = new ClassPathXmlApplicationContext(
"kafka/context-data-message.xml",
"kafka/context-data-producer.xml");
Order order = new Order();
order.setId(100);
order.setOrderNo("order_no");
order.setCreatedTime("oroder_created_time");
| // Path: koper-demo/src/main/java/koper/demo/dataevent/entity/Order.java
// public class Order {
//
// private Integer id;
//
// private String orderNo;
//
// private String createdTime;
//
// public Integer getId() {
// return id;
// }
//
// public void setId(Integer id) {
// this.id = id;
// }
//
// public String getOrderNo() {
// return orderNo;
// }
//
// public void setOrderNo(String orderNo) {
// this.orderNo = orderNo;
// }
//
// public String getCreatedTime() {
// return createdTime;
// }
//
// public void setCreatedTime(String createdTime) {
// this.createdTime = createdTime;
// }
//
// }
//
// Path: koper-demo/src/main/java/koper/demo/dataevent/service/OrderService.java
// public interface OrderService {
//
// String insertOrder(Order order);
//
// void updateOrder(Order order);
// }
// Path: koper-demo/src/main/java/koper/demo/performance/SendDataEventMsgPerf.java
import koper.demo.dataevent.entity.Order;
import koper.demo.dataevent.service.OrderService;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
/*
* 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 koper.demo.performance;
/**
* @author caie
* @since 1.2
*/
public class SendDataEventMsgPerf {
/**
* DataEventMsg 生产者入口
* @param args 第一个命令行参数:设定发送消息的线程数
* 第二个命令行参数:设定每发送一条消息后线程 sleep 的毫秒数
*/
public static void main(String[] args) throws Exception {
ApplicationContext context = new ClassPathXmlApplicationContext(
"kafka/context-data-message.xml",
"kafka/context-data-producer.xml");
Order order = new Order();
order.setId(100);
order.setOrderNo("order_no");
order.setCreatedTime("oroder_created_time");
| OrderService orderService = (OrderService) context.getBean("orderServiceImpl"); |
KoperGroup/koper | koper-core/src/main/java/koper/client/MessageDispatcherThread.java | // Path: koper-core/src/main/java/koper/ListenerRegistry.java
// public class ListenerRegistry {
//
// private Map<String, Object> listenerMap = new ConcurrentHashMap<>();
//
// /**
// * 注册监听器。 register listener
// *
// * @param topic
// * @param listener
// */
// public void register(String topic, Object listener) {
//
// Object listener1 = listenerMap.get(topic);
// if (listener1 != null) {
// throw new IllegalArgumentException("Listener with the same topic has been registered! topic=" + topic
// + ". Existed listener " + listener1 + ". New listener " + listener1);
// } else
// listenerMap.put(topic, listener);
//
// }
//
// public Map<String, Object> getListenerMap() {
// return listenerMap;
// }
// }
//
// Path: koper-core/src/main/java/koper/MessageCenter.java
// public interface MessageCenter<T> {
//
// @Deprecated
// T takeMessage();
//
// void putMessage(T msg);
//
// Router getRouter();
//
// }
//
// Path: koper-core/src/main/java/koper/MessageDispatcher.java
// public interface MessageDispatcher {
//
// /**
// * 设置监听注册表
// *
// * @param listenerRegistry 监听注册表
// */
// void setListenerRegistry(ListenerRegistry listenerRegistry);
//
// /**
// * 设置消息中心
// *
// * @param messageCenter 消息中心
// */
// void setMessageCenter(MessageCenter messageCenter);
//
// /**
// * 启动消息分发器
// */
// void start();
//
// /**
// * 调用消息处理器
// *
// * @param msgBean 消息Bean
// */
// void invokeMessageHandler(MsgBean<String, String> msgBean);
// }
| import koper.ListenerRegistry;
import koper.MessageCenter;
import koper.MessageDispatcher; | /*
* 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 koper.client;
/**
* 消息分发器线程
*
* @author kk
* @author caie
* @since 1.2
*/
public class MessageDispatcherThread implements Runnable {
private MessageCenter messageCenter; | // Path: koper-core/src/main/java/koper/ListenerRegistry.java
// public class ListenerRegistry {
//
// private Map<String, Object> listenerMap = new ConcurrentHashMap<>();
//
// /**
// * 注册监听器。 register listener
// *
// * @param topic
// * @param listener
// */
// public void register(String topic, Object listener) {
//
// Object listener1 = listenerMap.get(topic);
// if (listener1 != null) {
// throw new IllegalArgumentException("Listener with the same topic has been registered! topic=" + topic
// + ". Existed listener " + listener1 + ". New listener " + listener1);
// } else
// listenerMap.put(topic, listener);
//
// }
//
// public Map<String, Object> getListenerMap() {
// return listenerMap;
// }
// }
//
// Path: koper-core/src/main/java/koper/MessageCenter.java
// public interface MessageCenter<T> {
//
// @Deprecated
// T takeMessage();
//
// void putMessage(T msg);
//
// Router getRouter();
//
// }
//
// Path: koper-core/src/main/java/koper/MessageDispatcher.java
// public interface MessageDispatcher {
//
// /**
// * 设置监听注册表
// *
// * @param listenerRegistry 监听注册表
// */
// void setListenerRegistry(ListenerRegistry listenerRegistry);
//
// /**
// * 设置消息中心
// *
// * @param messageCenter 消息中心
// */
// void setMessageCenter(MessageCenter messageCenter);
//
// /**
// * 启动消息分发器
// */
// void start();
//
// /**
// * 调用消息处理器
// *
// * @param msgBean 消息Bean
// */
// void invokeMessageHandler(MsgBean<String, String> msgBean);
// }
// Path: koper-core/src/main/java/koper/client/MessageDispatcherThread.java
import koper.ListenerRegistry;
import koper.MessageCenter;
import koper.MessageDispatcher;
/*
* 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 koper.client;
/**
* 消息分发器线程
*
* @author kk
* @author caie
* @since 1.2
*/
public class MessageDispatcherThread implements Runnable {
private MessageCenter messageCenter; | private ListenerRegistry listenerRegistry; |
KoperGroup/koper | koper-core/src/main/java/koper/client/MessageDispatcherThread.java | // Path: koper-core/src/main/java/koper/ListenerRegistry.java
// public class ListenerRegistry {
//
// private Map<String, Object> listenerMap = new ConcurrentHashMap<>();
//
// /**
// * 注册监听器。 register listener
// *
// * @param topic
// * @param listener
// */
// public void register(String topic, Object listener) {
//
// Object listener1 = listenerMap.get(topic);
// if (listener1 != null) {
// throw new IllegalArgumentException("Listener with the same topic has been registered! topic=" + topic
// + ". Existed listener " + listener1 + ". New listener " + listener1);
// } else
// listenerMap.put(topic, listener);
//
// }
//
// public Map<String, Object> getListenerMap() {
// return listenerMap;
// }
// }
//
// Path: koper-core/src/main/java/koper/MessageCenter.java
// public interface MessageCenter<T> {
//
// @Deprecated
// T takeMessage();
//
// void putMessage(T msg);
//
// Router getRouter();
//
// }
//
// Path: koper-core/src/main/java/koper/MessageDispatcher.java
// public interface MessageDispatcher {
//
// /**
// * 设置监听注册表
// *
// * @param listenerRegistry 监听注册表
// */
// void setListenerRegistry(ListenerRegistry listenerRegistry);
//
// /**
// * 设置消息中心
// *
// * @param messageCenter 消息中心
// */
// void setMessageCenter(MessageCenter messageCenter);
//
// /**
// * 启动消息分发器
// */
// void start();
//
// /**
// * 调用消息处理器
// *
// * @param msgBean 消息Bean
// */
// void invokeMessageHandler(MsgBean<String, String> msgBean);
// }
| import koper.ListenerRegistry;
import koper.MessageCenter;
import koper.MessageDispatcher; | /*
* 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 koper.client;
/**
* 消息分发器线程
*
* @author kk
* @author caie
* @since 1.2
*/
public class MessageDispatcherThread implements Runnable {
private MessageCenter messageCenter;
private ListenerRegistry listenerRegistry; | // Path: koper-core/src/main/java/koper/ListenerRegistry.java
// public class ListenerRegistry {
//
// private Map<String, Object> listenerMap = new ConcurrentHashMap<>();
//
// /**
// * 注册监听器。 register listener
// *
// * @param topic
// * @param listener
// */
// public void register(String topic, Object listener) {
//
// Object listener1 = listenerMap.get(topic);
// if (listener1 != null) {
// throw new IllegalArgumentException("Listener with the same topic has been registered! topic=" + topic
// + ". Existed listener " + listener1 + ". New listener " + listener1);
// } else
// listenerMap.put(topic, listener);
//
// }
//
// public Map<String, Object> getListenerMap() {
// return listenerMap;
// }
// }
//
// Path: koper-core/src/main/java/koper/MessageCenter.java
// public interface MessageCenter<T> {
//
// @Deprecated
// T takeMessage();
//
// void putMessage(T msg);
//
// Router getRouter();
//
// }
//
// Path: koper-core/src/main/java/koper/MessageDispatcher.java
// public interface MessageDispatcher {
//
// /**
// * 设置监听注册表
// *
// * @param listenerRegistry 监听注册表
// */
// void setListenerRegistry(ListenerRegistry listenerRegistry);
//
// /**
// * 设置消息中心
// *
// * @param messageCenter 消息中心
// */
// void setMessageCenter(MessageCenter messageCenter);
//
// /**
// * 启动消息分发器
// */
// void start();
//
// /**
// * 调用消息处理器
// *
// * @param msgBean 消息Bean
// */
// void invokeMessageHandler(MsgBean<String, String> msgBean);
// }
// Path: koper-core/src/main/java/koper/client/MessageDispatcherThread.java
import koper.ListenerRegistry;
import koper.MessageCenter;
import koper.MessageDispatcher;
/*
* 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 koper.client;
/**
* 消息分发器线程
*
* @author kk
* @author caie
* @since 1.2
*/
public class MessageDispatcherThread implements Runnable {
private MessageCenter messageCenter;
private ListenerRegistry listenerRegistry; | private MessageDispatcher messageDispatcher; |
KoperGroup/koper | koper-core/src/main/java/koper/CommonMessageCenter.java | // Path: koper-core/src/main/java/koper/router/RoundRobinRouter.java
// public class RoundRobinRouter implements Router {
//
// private AtomicInteger index = new AtomicInteger(0);
// private List<RegItem> mailBoxList = new ArrayList<>();
// private ReentrantReadWriteLock mailBoxLock = new ReentrantReadWriteLock();
//
// @Override
// public void registerThreadMailBox(Runnable runnable, BlockingQueue mailBox) {
// mailBoxLock.writeLock().lock();
// try {
// mailBoxList.add(new RegItem(runnable, mailBox));
// } finally {
// mailBoxLock.writeLock().unlock();
// }
// }
//
// @Override
// public void dispatch(Object msgBean) throws InterruptedException {
// while (mailBoxList.isEmpty()) {
// Thread.sleep(1000);
// }
// mailBoxLock.readLock().lock();
// try {
// BlockingQueue queue = mailBoxList.get(index.get()).getBlockingQueue();
// int newIndex = index.incrementAndGet();
// if (newIndex >= mailBoxList.size()) {
// index.set(0);
// }
// queue.put(msgBean);
// } finally {
// mailBoxLock.readLock().unlock();
// }
// }
//
// @Override
// public void deRegister(Runnable runnable) {
// mailBoxLock.writeLock().lock();
// try {
// for (RegItem regItem : mailBoxList) {
// if (runnable.equals(regItem.getRunnable())) {
// mailBoxList.remove(regItem);
// break;
// }
// }
// } finally {
// mailBoxLock.writeLock().unlock();
// }
// }
//
//
// }
//
// Path: koper-core/src/main/java/koper/router/Router.java
// public interface Router {
//
// /**
// * register dispatcher thread 's mail box here, mq receiver will dispatch {@Link MsgBean} to mail box
// *
// * @param thread which thread's main box
// * @param mailBox dispatcher thread 's local cache
// */
// void registerThreadMailBox(Runnable thread, BlockingQueue mailBox);
//
// /**
// * dispatch {@Link MsgBean} to mail box
// *
// * @param msgBean msg
// */
// void dispatch(Object msgBean) throws InterruptedException;
//
// /**
// * call it when thread is interrupted
// *
// * @param thread
// */
// void deRegister(Runnable thread);
// }
| import koper.router.RoundRobinRouter;
import koper.router.Router;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.concurrent.LinkedBlockingQueue; | /*
* 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 koper;
/**
* 消息中心默认实现。
* 本地维持一个阻塞队列,缺省消息最大条数32万条。
*
* @author kk
* @since 1.2
*/
public class CommonMessageCenter<T> implements MessageCenter<T> {
private static Logger log = LoggerFactory.getLogger(CommonMessageCenter.class);
| // Path: koper-core/src/main/java/koper/router/RoundRobinRouter.java
// public class RoundRobinRouter implements Router {
//
// private AtomicInteger index = new AtomicInteger(0);
// private List<RegItem> mailBoxList = new ArrayList<>();
// private ReentrantReadWriteLock mailBoxLock = new ReentrantReadWriteLock();
//
// @Override
// public void registerThreadMailBox(Runnable runnable, BlockingQueue mailBox) {
// mailBoxLock.writeLock().lock();
// try {
// mailBoxList.add(new RegItem(runnable, mailBox));
// } finally {
// mailBoxLock.writeLock().unlock();
// }
// }
//
// @Override
// public void dispatch(Object msgBean) throws InterruptedException {
// while (mailBoxList.isEmpty()) {
// Thread.sleep(1000);
// }
// mailBoxLock.readLock().lock();
// try {
// BlockingQueue queue = mailBoxList.get(index.get()).getBlockingQueue();
// int newIndex = index.incrementAndGet();
// if (newIndex >= mailBoxList.size()) {
// index.set(0);
// }
// queue.put(msgBean);
// } finally {
// mailBoxLock.readLock().unlock();
// }
// }
//
// @Override
// public void deRegister(Runnable runnable) {
// mailBoxLock.writeLock().lock();
// try {
// for (RegItem regItem : mailBoxList) {
// if (runnable.equals(regItem.getRunnable())) {
// mailBoxList.remove(regItem);
// break;
// }
// }
// } finally {
// mailBoxLock.writeLock().unlock();
// }
// }
//
//
// }
//
// Path: koper-core/src/main/java/koper/router/Router.java
// public interface Router {
//
// /**
// * register dispatcher thread 's mail box here, mq receiver will dispatch {@Link MsgBean} to mail box
// *
// * @param thread which thread's main box
// * @param mailBox dispatcher thread 's local cache
// */
// void registerThreadMailBox(Runnable thread, BlockingQueue mailBox);
//
// /**
// * dispatch {@Link MsgBean} to mail box
// *
// * @param msgBean msg
// */
// void dispatch(Object msgBean) throws InterruptedException;
//
// /**
// * call it when thread is interrupted
// *
// * @param thread
// */
// void deRegister(Runnable thread);
// }
// Path: koper-core/src/main/java/koper/CommonMessageCenter.java
import koper.router.RoundRobinRouter;
import koper.router.Router;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.concurrent.LinkedBlockingQueue;
/*
* 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 koper;
/**
* 消息中心默认实现。
* 本地维持一个阻塞队列,缺省消息最大条数32万条。
*
* @author kk
* @since 1.2
*/
public class CommonMessageCenter<T> implements MessageCenter<T> {
private static Logger log = LoggerFactory.getLogger(CommonMessageCenter.class);
| private Router router; |
KoperGroup/koper | koper-core/src/main/java/koper/CommonMessageCenter.java | // Path: koper-core/src/main/java/koper/router/RoundRobinRouter.java
// public class RoundRobinRouter implements Router {
//
// private AtomicInteger index = new AtomicInteger(0);
// private List<RegItem> mailBoxList = new ArrayList<>();
// private ReentrantReadWriteLock mailBoxLock = new ReentrantReadWriteLock();
//
// @Override
// public void registerThreadMailBox(Runnable runnable, BlockingQueue mailBox) {
// mailBoxLock.writeLock().lock();
// try {
// mailBoxList.add(new RegItem(runnable, mailBox));
// } finally {
// mailBoxLock.writeLock().unlock();
// }
// }
//
// @Override
// public void dispatch(Object msgBean) throws InterruptedException {
// while (mailBoxList.isEmpty()) {
// Thread.sleep(1000);
// }
// mailBoxLock.readLock().lock();
// try {
// BlockingQueue queue = mailBoxList.get(index.get()).getBlockingQueue();
// int newIndex = index.incrementAndGet();
// if (newIndex >= mailBoxList.size()) {
// index.set(0);
// }
// queue.put(msgBean);
// } finally {
// mailBoxLock.readLock().unlock();
// }
// }
//
// @Override
// public void deRegister(Runnable runnable) {
// mailBoxLock.writeLock().lock();
// try {
// for (RegItem regItem : mailBoxList) {
// if (runnable.equals(regItem.getRunnable())) {
// mailBoxList.remove(regItem);
// break;
// }
// }
// } finally {
// mailBoxLock.writeLock().unlock();
// }
// }
//
//
// }
//
// Path: koper-core/src/main/java/koper/router/Router.java
// public interface Router {
//
// /**
// * register dispatcher thread 's mail box here, mq receiver will dispatch {@Link MsgBean} to mail box
// *
// * @param thread which thread's main box
// * @param mailBox dispatcher thread 's local cache
// */
// void registerThreadMailBox(Runnable thread, BlockingQueue mailBox);
//
// /**
// * dispatch {@Link MsgBean} to mail box
// *
// * @param msgBean msg
// */
// void dispatch(Object msgBean) throws InterruptedException;
//
// /**
// * call it when thread is interrupted
// *
// * @param thread
// */
// void deRegister(Runnable thread);
// }
| import koper.router.RoundRobinRouter;
import koper.router.Router;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.concurrent.LinkedBlockingQueue; | /*
* 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 koper;
/**
* 消息中心默认实现。
* 本地维持一个阻塞队列,缺省消息最大条数32万条。
*
* @author kk
* @since 1.2
*/
public class CommonMessageCenter<T> implements MessageCenter<T> {
private static Logger log = LoggerFactory.getLogger(CommonMessageCenter.class);
private Router router;
public static final int LOCAL_Q_SIZE = 32;
private LinkedBlockingQueue<T> msgQ; //default max message count 3.2M
/**
*
*/
public CommonMessageCenter(int qSize, Router router) {
int size = qSize <= 0 ? LOCAL_Q_SIZE : qSize;
this.msgQ = new LinkedBlockingQueue<>(size);
this.router = router;
}
/**
* use {@Link RoundRobinRouter} as default router
*
* @param qSize
*/
public CommonMessageCenter(int qSize) {
int size = qSize <= 0 ? LOCAL_Q_SIZE : qSize;
this.msgQ = new LinkedBlockingQueue<>(size); | // Path: koper-core/src/main/java/koper/router/RoundRobinRouter.java
// public class RoundRobinRouter implements Router {
//
// private AtomicInteger index = new AtomicInteger(0);
// private List<RegItem> mailBoxList = new ArrayList<>();
// private ReentrantReadWriteLock mailBoxLock = new ReentrantReadWriteLock();
//
// @Override
// public void registerThreadMailBox(Runnable runnable, BlockingQueue mailBox) {
// mailBoxLock.writeLock().lock();
// try {
// mailBoxList.add(new RegItem(runnable, mailBox));
// } finally {
// mailBoxLock.writeLock().unlock();
// }
// }
//
// @Override
// public void dispatch(Object msgBean) throws InterruptedException {
// while (mailBoxList.isEmpty()) {
// Thread.sleep(1000);
// }
// mailBoxLock.readLock().lock();
// try {
// BlockingQueue queue = mailBoxList.get(index.get()).getBlockingQueue();
// int newIndex = index.incrementAndGet();
// if (newIndex >= mailBoxList.size()) {
// index.set(0);
// }
// queue.put(msgBean);
// } finally {
// mailBoxLock.readLock().unlock();
// }
// }
//
// @Override
// public void deRegister(Runnable runnable) {
// mailBoxLock.writeLock().lock();
// try {
// for (RegItem regItem : mailBoxList) {
// if (runnable.equals(regItem.getRunnable())) {
// mailBoxList.remove(regItem);
// break;
// }
// }
// } finally {
// mailBoxLock.writeLock().unlock();
// }
// }
//
//
// }
//
// Path: koper-core/src/main/java/koper/router/Router.java
// public interface Router {
//
// /**
// * register dispatcher thread 's mail box here, mq receiver will dispatch {@Link MsgBean} to mail box
// *
// * @param thread which thread's main box
// * @param mailBox dispatcher thread 's local cache
// */
// void registerThreadMailBox(Runnable thread, BlockingQueue mailBox);
//
// /**
// * dispatch {@Link MsgBean} to mail box
// *
// * @param msgBean msg
// */
// void dispatch(Object msgBean) throws InterruptedException;
//
// /**
// * call it when thread is interrupted
// *
// * @param thread
// */
// void deRegister(Runnable thread);
// }
// Path: koper-core/src/main/java/koper/CommonMessageCenter.java
import koper.router.RoundRobinRouter;
import koper.router.Router;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.concurrent.LinkedBlockingQueue;
/*
* 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 koper;
/**
* 消息中心默认实现。
* 本地维持一个阻塞队列,缺省消息最大条数32万条。
*
* @author kk
* @since 1.2
*/
public class CommonMessageCenter<T> implements MessageCenter<T> {
private static Logger log = LoggerFactory.getLogger(CommonMessageCenter.class);
private Router router;
public static final int LOCAL_Q_SIZE = 32;
private LinkedBlockingQueue<T> msgQ; //default max message count 3.2M
/**
*
*/
public CommonMessageCenter(int qSize, Router router) {
int size = qSize <= 0 ? LOCAL_Q_SIZE : qSize;
this.msgQ = new LinkedBlockingQueue<>(size);
this.router = router;
}
/**
* use {@Link RoundRobinRouter} as default router
*
* @param qSize
*/
public CommonMessageCenter(int qSize) {
int size = qSize <= 0 ? LOCAL_Q_SIZE : qSize;
this.msgQ = new LinkedBlockingQueue<>(size); | this.router = new RoundRobinRouter(); |
KoperGroup/koper | koper-aop/src/main/java/koper/aop/AbstractSendMessageAdvice.java | // Path: koper-core/src/main/java/koper/sender/MessageSender.java
// public interface MessageSender {
//
// void send(String topic, String msg);
//
// void send(String topic, String key, String msg);
//
// void send(String topic, Object msg);
//
// void send(String topic, String key, Object msg);
// }
| import koper.sender.MessageSender;
import org.aspectj.lang.ProceedingJoinPoint;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import java.lang.reflect.Method;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap; | /*
* 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 koper.aop;
/**
*
* AbstractSendMessageAdvice
*
* @author kk [email protected]
* @since 1.0
* 2016年1月20日
*/
public abstract class AbstractSendMessageAdvice implements ApplicationContextAware {
private static Logger log = LoggerFactory.getLogger(AbstractSendMessageAdvice.class);
protected ApplicationContext applicationContext;
@Autowired | // Path: koper-core/src/main/java/koper/sender/MessageSender.java
// public interface MessageSender {
//
// void send(String topic, String msg);
//
// void send(String topic, String key, String msg);
//
// void send(String topic, Object msg);
//
// void send(String topic, String key, Object msg);
// }
// Path: koper-aop/src/main/java/koper/aop/AbstractSendMessageAdvice.java
import koper.sender.MessageSender;
import org.aspectj.lang.ProceedingJoinPoint;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import java.lang.reflect.Method;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
/*
* 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 koper.aop;
/**
*
* AbstractSendMessageAdvice
*
* @author kk [email protected]
* @since 1.0
* 2016年1月20日
*/
public abstract class AbstractSendMessageAdvice implements ApplicationContextAware {
private static Logger log = LoggerFactory.getLogger(AbstractSendMessageAdvice.class);
protected ApplicationContext applicationContext;
@Autowired | protected MessageSender messageSender; |
KoperGroup/koper | koper-testcase/src/main/java/koper/listener/OrderListener.java | // Path: koper-core/src/main/java/koper/AbstractMessageListener.java
// public abstract class AbstractMessageListener implements MessageListener {
//
// @Override
// public void onMsgBean(MsgBean<String, String> msgBean) {
//
// }
//
// @Override
// public void onMessage(String msg) {
// }
// }
//
// Path: koper-testcase/src/main/java/koper/demo/trading/mapper/Order.java
// public class Order {
//
// public String orderId;
// public String orderName;
// public Date createDate;
// public String memberId;
// public BigDecimal totalPrice;
//
// public String getOrderId() {
// return orderId;
// }
// public void setOrderId(String orderId) {
// this.orderId = orderId;
// }
// public String getOrderName() {
// return orderName;
// }
// public void setOrderName(String orderName) {
// this.orderName = orderName;
// }
// public Date getCreateDate() {
// return createDate;
// }
// public void setCreateDate(Date createDate) {
// this.createDate = createDate;
// }
// public String getMemberId() {
// return memberId;
// }
// public void setMemberId(String memberId) {
// this.memberId = memberId;
// }
// public BigDecimal getTotalPrice() {
// return totalPrice;
// }
// public void setTotalPrice(BigDecimal totalPrice) {
// this.totalPrice = totalPrice;
// }
//
// @Override
// public String toString() {
// return "Order{" +
// "orderId='" + orderId + '\'' +
// ", orderName='" + orderName + '\'' +
// ", createDate=" + createDate +
// ", memberId='" + memberId + '\'' +
// ", totalPrice=" + totalPrice +
// '}';
// }
// }
| import koper.AbstractMessageListener;
import koper.Listen;
import koper.demo.trading.mapper.Order;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component; | /*
* 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 koper.listener;
/**
* @author caie
*/
@Component
@Listen(topic = "zhaimi.orderListener") | // Path: koper-core/src/main/java/koper/AbstractMessageListener.java
// public abstract class AbstractMessageListener implements MessageListener {
//
// @Override
// public void onMsgBean(MsgBean<String, String> msgBean) {
//
// }
//
// @Override
// public void onMessage(String msg) {
// }
// }
//
// Path: koper-testcase/src/main/java/koper/demo/trading/mapper/Order.java
// public class Order {
//
// public String orderId;
// public String orderName;
// public Date createDate;
// public String memberId;
// public BigDecimal totalPrice;
//
// public String getOrderId() {
// return orderId;
// }
// public void setOrderId(String orderId) {
// this.orderId = orderId;
// }
// public String getOrderName() {
// return orderName;
// }
// public void setOrderName(String orderName) {
// this.orderName = orderName;
// }
// public Date getCreateDate() {
// return createDate;
// }
// public void setCreateDate(Date createDate) {
// this.createDate = createDate;
// }
// public String getMemberId() {
// return memberId;
// }
// public void setMemberId(String memberId) {
// this.memberId = memberId;
// }
// public BigDecimal getTotalPrice() {
// return totalPrice;
// }
// public void setTotalPrice(BigDecimal totalPrice) {
// this.totalPrice = totalPrice;
// }
//
// @Override
// public String toString() {
// return "Order{" +
// "orderId='" + orderId + '\'' +
// ", orderName='" + orderName + '\'' +
// ", createDate=" + createDate +
// ", memberId='" + memberId + '\'' +
// ", totalPrice=" + totalPrice +
// '}';
// }
// }
// Path: koper-testcase/src/main/java/koper/listener/OrderListener.java
import koper.AbstractMessageListener;
import koper.Listen;
import koper.demo.trading.mapper.Order;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
/*
* 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 koper.listener;
/**
* @author caie
*/
@Component
@Listen(topic = "zhaimi.orderListener") | public class OrderListener extends AbstractMessageListener { |
KoperGroup/koper | koper-testcase/src/main/java/koper/listener/OrderListener.java | // Path: koper-core/src/main/java/koper/AbstractMessageListener.java
// public abstract class AbstractMessageListener implements MessageListener {
//
// @Override
// public void onMsgBean(MsgBean<String, String> msgBean) {
//
// }
//
// @Override
// public void onMessage(String msg) {
// }
// }
//
// Path: koper-testcase/src/main/java/koper/demo/trading/mapper/Order.java
// public class Order {
//
// public String orderId;
// public String orderName;
// public Date createDate;
// public String memberId;
// public BigDecimal totalPrice;
//
// public String getOrderId() {
// return orderId;
// }
// public void setOrderId(String orderId) {
// this.orderId = orderId;
// }
// public String getOrderName() {
// return orderName;
// }
// public void setOrderName(String orderName) {
// this.orderName = orderName;
// }
// public Date getCreateDate() {
// return createDate;
// }
// public void setCreateDate(Date createDate) {
// this.createDate = createDate;
// }
// public String getMemberId() {
// return memberId;
// }
// public void setMemberId(String memberId) {
// this.memberId = memberId;
// }
// public BigDecimal getTotalPrice() {
// return totalPrice;
// }
// public void setTotalPrice(BigDecimal totalPrice) {
// this.totalPrice = totalPrice;
// }
//
// @Override
// public String toString() {
// return "Order{" +
// "orderId='" + orderId + '\'' +
// ", orderName='" + orderName + '\'' +
// ", createDate=" + createDate +
// ", memberId='" + memberId + '\'' +
// ", totalPrice=" + totalPrice +
// '}';
// }
// }
| import koper.AbstractMessageListener;
import koper.Listen;
import koper.demo.trading.mapper.Order;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component; | /*
* 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 koper.listener;
/**
* @author caie
*/
@Component
@Listen(topic = "zhaimi.orderListener")
public class OrderListener extends AbstractMessageListener {
private Logger logger = LoggerFactory.getLogger(getClass());
@Override
public void onMessage(String msg) {
logger.info("got msg! msg: {}", msg);
}
| // Path: koper-core/src/main/java/koper/AbstractMessageListener.java
// public abstract class AbstractMessageListener implements MessageListener {
//
// @Override
// public void onMsgBean(MsgBean<String, String> msgBean) {
//
// }
//
// @Override
// public void onMessage(String msg) {
// }
// }
//
// Path: koper-testcase/src/main/java/koper/demo/trading/mapper/Order.java
// public class Order {
//
// public String orderId;
// public String orderName;
// public Date createDate;
// public String memberId;
// public BigDecimal totalPrice;
//
// public String getOrderId() {
// return orderId;
// }
// public void setOrderId(String orderId) {
// this.orderId = orderId;
// }
// public String getOrderName() {
// return orderName;
// }
// public void setOrderName(String orderName) {
// this.orderName = orderName;
// }
// public Date getCreateDate() {
// return createDate;
// }
// public void setCreateDate(Date createDate) {
// this.createDate = createDate;
// }
// public String getMemberId() {
// return memberId;
// }
// public void setMemberId(String memberId) {
// this.memberId = memberId;
// }
// public BigDecimal getTotalPrice() {
// return totalPrice;
// }
// public void setTotalPrice(BigDecimal totalPrice) {
// this.totalPrice = totalPrice;
// }
//
// @Override
// public String toString() {
// return "Order{" +
// "orderId='" + orderId + '\'' +
// ", orderName='" + orderName + '\'' +
// ", createDate=" + createDate +
// ", memberId='" + memberId + '\'' +
// ", totalPrice=" + totalPrice +
// '}';
// }
// }
// Path: koper-testcase/src/main/java/koper/listener/OrderListener.java
import koper.AbstractMessageListener;
import koper.Listen;
import koper.demo.trading.mapper.Order;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
/*
* 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 koper.listener;
/**
* @author caie
*/
@Component
@Listen(topic = "zhaimi.orderListener")
public class OrderListener extends AbstractMessageListener {
private Logger logger = LoggerFactory.getLogger(getClass());
@Override
public void onMessage(String msg) {
logger.info("got msg! msg: {}", msg);
}
| public void onMessage(Order order) { |
KoperGroup/koper | koper-demo/src/main/java/koper/demo/main/SendMsgDemo.java | // Path: koper-demo/src/main/java/koper/demo/message/entity/Member.java
// public class Member {
//
// private Integer id;
//
// private String name;
//
// private String phoneNo;
//
// public Integer getId() {
// return id;
// }
//
// public void setId(Integer id) {
// this.id = id;
// }
//
// public String getName() {
// return name;
// }
//
// public void setName(String name) {
// this.name = name;
// }
//
// public String getPhoneNo() {
// return phoneNo;
// }
//
// public void setPhoneNo(String phoneNo) {
// this.phoneNo = phoneNo;
// }
// }
//
// Path: koper-demo/src/main/java/koper/demo/message/service/MemberService.java
// public interface MemberService {
//
// void signup(Member member);
//
// }
| import koper.demo.message.entity.Member;
import koper.demo.message.service.MemberService;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext; | /*
* 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 koper.demo.main;
/**
* @author caie
* @since 1.2
*/
public class SendMsgDemo {
public static void main(String[] args) {
final ApplicationContext context =
new ClassPathXmlApplicationContext("classpath:kafka/context-data-producer.xml"); | // Path: koper-demo/src/main/java/koper/demo/message/entity/Member.java
// public class Member {
//
// private Integer id;
//
// private String name;
//
// private String phoneNo;
//
// public Integer getId() {
// return id;
// }
//
// public void setId(Integer id) {
// this.id = id;
// }
//
// public String getName() {
// return name;
// }
//
// public void setName(String name) {
// this.name = name;
// }
//
// public String getPhoneNo() {
// return phoneNo;
// }
//
// public void setPhoneNo(String phoneNo) {
// this.phoneNo = phoneNo;
// }
// }
//
// Path: koper-demo/src/main/java/koper/demo/message/service/MemberService.java
// public interface MemberService {
//
// void signup(Member member);
//
// }
// Path: koper-demo/src/main/java/koper/demo/main/SendMsgDemo.java
import koper.demo.message.entity.Member;
import koper.demo.message.service.MemberService;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
/*
* 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 koper.demo.main;
/**
* @author caie
* @since 1.2
*/
public class SendMsgDemo {
public static void main(String[] args) {
final ApplicationContext context =
new ClassPathXmlApplicationContext("classpath:kafka/context-data-producer.xml"); | final MemberService memberService = context.getBean(MemberService.class); |
KoperGroup/koper | koper-demo/src/main/java/koper/demo/main/SendMsgDemo.java | // Path: koper-demo/src/main/java/koper/demo/message/entity/Member.java
// public class Member {
//
// private Integer id;
//
// private String name;
//
// private String phoneNo;
//
// public Integer getId() {
// return id;
// }
//
// public void setId(Integer id) {
// this.id = id;
// }
//
// public String getName() {
// return name;
// }
//
// public void setName(String name) {
// this.name = name;
// }
//
// public String getPhoneNo() {
// return phoneNo;
// }
//
// public void setPhoneNo(String phoneNo) {
// this.phoneNo = phoneNo;
// }
// }
//
// Path: koper-demo/src/main/java/koper/demo/message/service/MemberService.java
// public interface MemberService {
//
// void signup(Member member);
//
// }
| import koper.demo.message.entity.Member;
import koper.demo.message.service.MemberService;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext; | /*
* 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 koper.demo.main;
/**
* @author caie
* @since 1.2
*/
public class SendMsgDemo {
public static void main(String[] args) {
final ApplicationContext context =
new ClassPathXmlApplicationContext("classpath:kafka/context-data-producer.xml");
final MemberService memberService = context.getBean(MemberService.class);
| // Path: koper-demo/src/main/java/koper/demo/message/entity/Member.java
// public class Member {
//
// private Integer id;
//
// private String name;
//
// private String phoneNo;
//
// public Integer getId() {
// return id;
// }
//
// public void setId(Integer id) {
// this.id = id;
// }
//
// public String getName() {
// return name;
// }
//
// public void setName(String name) {
// this.name = name;
// }
//
// public String getPhoneNo() {
// return phoneNo;
// }
//
// public void setPhoneNo(String phoneNo) {
// this.phoneNo = phoneNo;
// }
// }
//
// Path: koper-demo/src/main/java/koper/demo/message/service/MemberService.java
// public interface MemberService {
//
// void signup(Member member);
//
// }
// Path: koper-demo/src/main/java/koper/demo/main/SendMsgDemo.java
import koper.demo.message.entity.Member;
import koper.demo.message.service.MemberService;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
/*
* 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 koper.demo.main;
/**
* @author caie
* @since 1.2
*/
public class SendMsgDemo {
public static void main(String[] args) {
final ApplicationContext context =
new ClassPathXmlApplicationContext("classpath:kafka/context-data-producer.xml");
final MemberService memberService = context.getBean(MemberService.class);
| Member member = new Member(); |
KoperGroup/koper | koper-core/src/main/java/koper/MessageListenerBeanPostProcessor.java | // Path: koper-core/src/main/java/koper/client/ConsumerLauncher.java
// public interface ConsumerLauncher {
//
// /**
// * start consumer
// */
// public void start();
//
// void setAutoStart(boolean autoStart);
//
// void setPartitions(int partitions);
//
// /**
// * @param threads
// */
// void setDispatcherThreads(int threads);
//
// /**
// * @return
// */
// public ListenerRegistry getListenerRegistry();
// }
//
// Path: koper-core/src/main/java/koper/util/ReflectUtil.java
// public class ReflectUtil {
//
// public void add(int abc, int xyz, String yyy) {
//
// }
//
// private static Map<String, Class<?>> classMap = new HashMap<>();
//
// /**
// * 获取类上的Listen注解
// *
// * @param clazz Class类
// * @return Listen注解
// */
// public static Listen getListenAnnotation(Class<?> clazz) {
// return clazz.getAnnotation(Listen.class);
// }
//
// /**
// * Get method arg names.
// *
// * @param clazz
// * @param methodName
// * @return
// */
// public static <T> String[] getMethodArgNames(Class<T> clazz, String methodName) {
// try {
// ClassPool pool = ClassPool.getDefault();
// CtClass cc = pool.get(clazz.getName());
//
// CtMethod cm = cc.getDeclaredMethod(methodName);
//
// // 使用javaassist的反射方法获取方法的参数名
// MethodInfo methodInfo = cm.getMethodInfo();
// CodeAttribute codeAttribute = methodInfo.getCodeAttribute();
// LocalVariableAttribute attr = (LocalVariableAttribute) codeAttribute.getAttribute(LocalVariableAttribute.tag);
// if (attr == null) {
// throw new RuntimeException("LocalVariableAttribute of method is null! Class " + clazz.getName() + ",method name is " + methodName);
// }
// String[] paramNames = new String[cm.getParameterTypes().length];
// int pos = Modifier.isStatic(cm.getModifiers()) ? 0 : 1;
// for (int i = 0; i < paramNames.length; i++)
// paramNames[i] = attr.variableName(i + pos);
//
// return paramNames;
// } catch (NotFoundException e) {
// throw new RuntimeException(e.getMessage(), e);
// }
// }
//
// public static Class<?> getClass(String className) {
// return classMap.computeIfAbsent(className, clazzName -> {
// try {
// return Class.forName(clazzName);
// } catch (ClassNotFoundException e) {
// throw new RuntimeException(e);
// }
// });
// }
//
// public static void invoke(Object targetObject, Method method, Object[] objects) {
// final Class<?> clazz = targetObject.getClass();
// final FastClass fastClass = FastClass.create(clazz);
// try {
// fastClass.getMethod(method).invoke(targetObject, objects);
// } catch (InvocationTargetException e) {
// throw new RuntimeException(e);
// }
// }
//
// public static Optional<Method> getMethod(Class<?> clazz, String eventName, Predicate<Method> methodPredicate) {
// final Method[] methods = clazz.getDeclaredMethods();
//
// return Arrays.stream(methods)
// .filter(method -> method.getName().equals(eventName))
// .filter(methodPredicate)
// .findAny();
// }
//
// public static void main(String[] args) throws NotFoundException {
//
// String[] paramNames = ReflectUtil.getMethodArgNames(ReflectUtil.class, "add");
// // paramNames即参数名
// for (int i = 0; i < paramNames.length; i++) {
// System.out.println(paramNames[i]);
// }
// }
//
// }
| import koper.client.ConsumerLauncher;
import koper.util.ReflectUtil;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.util.ReflectionUtils;
import java.lang.reflect.Method; | /*
* 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 koper;
/**
* MessageListenerBeanPostProcessor
*
* @author kk
* @since 1.0
*/
public class MessageListenerBeanPostProcessor implements BeanPostProcessor {
private static final Logger log = LoggerFactory.getLogger(MessageListenerBeanPostProcessor.class);
@Autowired | // Path: koper-core/src/main/java/koper/client/ConsumerLauncher.java
// public interface ConsumerLauncher {
//
// /**
// * start consumer
// */
// public void start();
//
// void setAutoStart(boolean autoStart);
//
// void setPartitions(int partitions);
//
// /**
// * @param threads
// */
// void setDispatcherThreads(int threads);
//
// /**
// * @return
// */
// public ListenerRegistry getListenerRegistry();
// }
//
// Path: koper-core/src/main/java/koper/util/ReflectUtil.java
// public class ReflectUtil {
//
// public void add(int abc, int xyz, String yyy) {
//
// }
//
// private static Map<String, Class<?>> classMap = new HashMap<>();
//
// /**
// * 获取类上的Listen注解
// *
// * @param clazz Class类
// * @return Listen注解
// */
// public static Listen getListenAnnotation(Class<?> clazz) {
// return clazz.getAnnotation(Listen.class);
// }
//
// /**
// * Get method arg names.
// *
// * @param clazz
// * @param methodName
// * @return
// */
// public static <T> String[] getMethodArgNames(Class<T> clazz, String methodName) {
// try {
// ClassPool pool = ClassPool.getDefault();
// CtClass cc = pool.get(clazz.getName());
//
// CtMethod cm = cc.getDeclaredMethod(methodName);
//
// // 使用javaassist的反射方法获取方法的参数名
// MethodInfo methodInfo = cm.getMethodInfo();
// CodeAttribute codeAttribute = methodInfo.getCodeAttribute();
// LocalVariableAttribute attr = (LocalVariableAttribute) codeAttribute.getAttribute(LocalVariableAttribute.tag);
// if (attr == null) {
// throw new RuntimeException("LocalVariableAttribute of method is null! Class " + clazz.getName() + ",method name is " + methodName);
// }
// String[] paramNames = new String[cm.getParameterTypes().length];
// int pos = Modifier.isStatic(cm.getModifiers()) ? 0 : 1;
// for (int i = 0; i < paramNames.length; i++)
// paramNames[i] = attr.variableName(i + pos);
//
// return paramNames;
// } catch (NotFoundException e) {
// throw new RuntimeException(e.getMessage(), e);
// }
// }
//
// public static Class<?> getClass(String className) {
// return classMap.computeIfAbsent(className, clazzName -> {
// try {
// return Class.forName(clazzName);
// } catch (ClassNotFoundException e) {
// throw new RuntimeException(e);
// }
// });
// }
//
// public static void invoke(Object targetObject, Method method, Object[] objects) {
// final Class<?> clazz = targetObject.getClass();
// final FastClass fastClass = FastClass.create(clazz);
// try {
// fastClass.getMethod(method).invoke(targetObject, objects);
// } catch (InvocationTargetException e) {
// throw new RuntimeException(e);
// }
// }
//
// public static Optional<Method> getMethod(Class<?> clazz, String eventName, Predicate<Method> methodPredicate) {
// final Method[] methods = clazz.getDeclaredMethods();
//
// return Arrays.stream(methods)
// .filter(method -> method.getName().equals(eventName))
// .filter(methodPredicate)
// .findAny();
// }
//
// public static void main(String[] args) throws NotFoundException {
//
// String[] paramNames = ReflectUtil.getMethodArgNames(ReflectUtil.class, "add");
// // paramNames即参数名
// for (int i = 0; i < paramNames.length; i++) {
// System.out.println(paramNames[i]);
// }
// }
//
// }
// Path: koper-core/src/main/java/koper/MessageListenerBeanPostProcessor.java
import koper.client.ConsumerLauncher;
import koper.util.ReflectUtil;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.util.ReflectionUtils;
import java.lang.reflect.Method;
/*
* 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 koper;
/**
* MessageListenerBeanPostProcessor
*
* @author kk
* @since 1.0
*/
public class MessageListenerBeanPostProcessor implements BeanPostProcessor {
private static final Logger log = LoggerFactory.getLogger(MessageListenerBeanPostProcessor.class);
@Autowired | private ConsumerLauncher consumerLauncher; |
KoperGroup/koper | koper-core/src/main/java/koper/MessageListenerBeanPostProcessor.java | // Path: koper-core/src/main/java/koper/client/ConsumerLauncher.java
// public interface ConsumerLauncher {
//
// /**
// * start consumer
// */
// public void start();
//
// void setAutoStart(boolean autoStart);
//
// void setPartitions(int partitions);
//
// /**
// * @param threads
// */
// void setDispatcherThreads(int threads);
//
// /**
// * @return
// */
// public ListenerRegistry getListenerRegistry();
// }
//
// Path: koper-core/src/main/java/koper/util/ReflectUtil.java
// public class ReflectUtil {
//
// public void add(int abc, int xyz, String yyy) {
//
// }
//
// private static Map<String, Class<?>> classMap = new HashMap<>();
//
// /**
// * 获取类上的Listen注解
// *
// * @param clazz Class类
// * @return Listen注解
// */
// public static Listen getListenAnnotation(Class<?> clazz) {
// return clazz.getAnnotation(Listen.class);
// }
//
// /**
// * Get method arg names.
// *
// * @param clazz
// * @param methodName
// * @return
// */
// public static <T> String[] getMethodArgNames(Class<T> clazz, String methodName) {
// try {
// ClassPool pool = ClassPool.getDefault();
// CtClass cc = pool.get(clazz.getName());
//
// CtMethod cm = cc.getDeclaredMethod(methodName);
//
// // 使用javaassist的反射方法获取方法的参数名
// MethodInfo methodInfo = cm.getMethodInfo();
// CodeAttribute codeAttribute = methodInfo.getCodeAttribute();
// LocalVariableAttribute attr = (LocalVariableAttribute) codeAttribute.getAttribute(LocalVariableAttribute.tag);
// if (attr == null) {
// throw new RuntimeException("LocalVariableAttribute of method is null! Class " + clazz.getName() + ",method name is " + methodName);
// }
// String[] paramNames = new String[cm.getParameterTypes().length];
// int pos = Modifier.isStatic(cm.getModifiers()) ? 0 : 1;
// for (int i = 0; i < paramNames.length; i++)
// paramNames[i] = attr.variableName(i + pos);
//
// return paramNames;
// } catch (NotFoundException e) {
// throw new RuntimeException(e.getMessage(), e);
// }
// }
//
// public static Class<?> getClass(String className) {
// return classMap.computeIfAbsent(className, clazzName -> {
// try {
// return Class.forName(clazzName);
// } catch (ClassNotFoundException e) {
// throw new RuntimeException(e);
// }
// });
// }
//
// public static void invoke(Object targetObject, Method method, Object[] objects) {
// final Class<?> clazz = targetObject.getClass();
// final FastClass fastClass = FastClass.create(clazz);
// try {
// fastClass.getMethod(method).invoke(targetObject, objects);
// } catch (InvocationTargetException e) {
// throw new RuntimeException(e);
// }
// }
//
// public static Optional<Method> getMethod(Class<?> clazz, String eventName, Predicate<Method> methodPredicate) {
// final Method[] methods = clazz.getDeclaredMethods();
//
// return Arrays.stream(methods)
// .filter(method -> method.getName().equals(eventName))
// .filter(methodPredicate)
// .findAny();
// }
//
// public static void main(String[] args) throws NotFoundException {
//
// String[] paramNames = ReflectUtil.getMethodArgNames(ReflectUtil.class, "add");
// // paramNames即参数名
// for (int i = 0; i < paramNames.length; i++) {
// System.out.println(paramNames[i]);
// }
// }
//
// }
| import koper.client.ConsumerLauncher;
import koper.util.ReflectUtil;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.util.ReflectionUtils;
import java.lang.reflect.Method; | // pojo listener
final Listen listenAnnotation = bean.getClass().getAnnotation(Listen.class);
final String topic = listenAnnotation.topic();
if (StringUtils.isBlank(topic)) {
throw new RuntimeException(
String.format("class %s, @Listen annotation topic not specified, please check", bean)
);
} else {
registerListener(bean, topic);
}
}
return bean;
}
/**
* 注册消息监听器
*
* @param listener
*/
protected void registerMsgBeanListener(MsgBeanListener listener) {
Class<?> clazz = listener.getClass();
Method method;
String topic = null;
Listen listen;
method = getMethod(clazz, "onMsgBean");
listen = method == null ? null : method.getAnnotation(Listen.class);
if (listen == null) {
// 先拿类上的 Listen 注解, 没有再拿方法上的Listen | // Path: koper-core/src/main/java/koper/client/ConsumerLauncher.java
// public interface ConsumerLauncher {
//
// /**
// * start consumer
// */
// public void start();
//
// void setAutoStart(boolean autoStart);
//
// void setPartitions(int partitions);
//
// /**
// * @param threads
// */
// void setDispatcherThreads(int threads);
//
// /**
// * @return
// */
// public ListenerRegistry getListenerRegistry();
// }
//
// Path: koper-core/src/main/java/koper/util/ReflectUtil.java
// public class ReflectUtil {
//
// public void add(int abc, int xyz, String yyy) {
//
// }
//
// private static Map<String, Class<?>> classMap = new HashMap<>();
//
// /**
// * 获取类上的Listen注解
// *
// * @param clazz Class类
// * @return Listen注解
// */
// public static Listen getListenAnnotation(Class<?> clazz) {
// return clazz.getAnnotation(Listen.class);
// }
//
// /**
// * Get method arg names.
// *
// * @param clazz
// * @param methodName
// * @return
// */
// public static <T> String[] getMethodArgNames(Class<T> clazz, String methodName) {
// try {
// ClassPool pool = ClassPool.getDefault();
// CtClass cc = pool.get(clazz.getName());
//
// CtMethod cm = cc.getDeclaredMethod(methodName);
//
// // 使用javaassist的反射方法获取方法的参数名
// MethodInfo methodInfo = cm.getMethodInfo();
// CodeAttribute codeAttribute = methodInfo.getCodeAttribute();
// LocalVariableAttribute attr = (LocalVariableAttribute) codeAttribute.getAttribute(LocalVariableAttribute.tag);
// if (attr == null) {
// throw new RuntimeException("LocalVariableAttribute of method is null! Class " + clazz.getName() + ",method name is " + methodName);
// }
// String[] paramNames = new String[cm.getParameterTypes().length];
// int pos = Modifier.isStatic(cm.getModifiers()) ? 0 : 1;
// for (int i = 0; i < paramNames.length; i++)
// paramNames[i] = attr.variableName(i + pos);
//
// return paramNames;
// } catch (NotFoundException e) {
// throw new RuntimeException(e.getMessage(), e);
// }
// }
//
// public static Class<?> getClass(String className) {
// return classMap.computeIfAbsent(className, clazzName -> {
// try {
// return Class.forName(clazzName);
// } catch (ClassNotFoundException e) {
// throw new RuntimeException(e);
// }
// });
// }
//
// public static void invoke(Object targetObject, Method method, Object[] objects) {
// final Class<?> clazz = targetObject.getClass();
// final FastClass fastClass = FastClass.create(clazz);
// try {
// fastClass.getMethod(method).invoke(targetObject, objects);
// } catch (InvocationTargetException e) {
// throw new RuntimeException(e);
// }
// }
//
// public static Optional<Method> getMethod(Class<?> clazz, String eventName, Predicate<Method> methodPredicate) {
// final Method[] methods = clazz.getDeclaredMethods();
//
// return Arrays.stream(methods)
// .filter(method -> method.getName().equals(eventName))
// .filter(methodPredicate)
// .findAny();
// }
//
// public static void main(String[] args) throws NotFoundException {
//
// String[] paramNames = ReflectUtil.getMethodArgNames(ReflectUtil.class, "add");
// // paramNames即参数名
// for (int i = 0; i < paramNames.length; i++) {
// System.out.println(paramNames[i]);
// }
// }
//
// }
// Path: koper-core/src/main/java/koper/MessageListenerBeanPostProcessor.java
import koper.client.ConsumerLauncher;
import koper.util.ReflectUtil;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.util.ReflectionUtils;
import java.lang.reflect.Method;
// pojo listener
final Listen listenAnnotation = bean.getClass().getAnnotation(Listen.class);
final String topic = listenAnnotation.topic();
if (StringUtils.isBlank(topic)) {
throw new RuntimeException(
String.format("class %s, @Listen annotation topic not specified, please check", bean)
);
} else {
registerListener(bean, topic);
}
}
return bean;
}
/**
* 注册消息监听器
*
* @param listener
*/
protected void registerMsgBeanListener(MsgBeanListener listener) {
Class<?> clazz = listener.getClass();
Method method;
String topic = null;
Listen listen;
method = getMethod(clazz, "onMsgBean");
listen = method == null ? null : method.getAnnotation(Listen.class);
if (listen == null) {
// 先拿类上的 Listen 注解, 没有再拿方法上的Listen | final Listen clazzAnnotation = ReflectUtil.getListenAnnotation(clazz); |
KoperGroup/koper | koper-testcase/src/test/java/koper/kafka/SendMsgAopTest.java | // Path: koper-testcase/src/main/java/koper/demo/trading/mapper/Order.java
// public class Order {
//
// public String orderId;
// public String orderName;
// public Date createDate;
// public String memberId;
// public BigDecimal totalPrice;
//
// public String getOrderId() {
// return orderId;
// }
// public void setOrderId(String orderId) {
// this.orderId = orderId;
// }
// public String getOrderName() {
// return orderName;
// }
// public void setOrderName(String orderName) {
// this.orderName = orderName;
// }
// public Date getCreateDate() {
// return createDate;
// }
// public void setCreateDate(Date createDate) {
// this.createDate = createDate;
// }
// public String getMemberId() {
// return memberId;
// }
// public void setMemberId(String memberId) {
// this.memberId = memberId;
// }
// public BigDecimal getTotalPrice() {
// return totalPrice;
// }
// public void setTotalPrice(BigDecimal totalPrice) {
// this.totalPrice = totalPrice;
// }
//
// @Override
// public String toString() {
// return "Order{" +
// "orderId='" + orderId + '\'' +
// ", orderName='" + orderName + '\'' +
// ", createDate=" + createDate +
// ", memberId='" + memberId + '\'' +
// ", totalPrice=" + totalPrice +
// '}';
// }
// }
//
// Path: koper-testcase/src/main/java/koper/demo/trading/mapper/OrderMapper.java
// public interface OrderMapper {
//
// String getOrder(String orderId, Order order);
//
// String cancelOrder(Order order);
//
// String createOrder(String memberId, Order order);
//
// String updateOrder(Order order);
//
// String insertOrder(Order order);
//
// /**
// * @param orderId
// * @param order
// * @return
// */
// String deleteOrder(String orderId, Order order);
//
// String deleteOldOrder(int orderId, boolean reserve);
//
// String cancelOldOrder(Order order);
// }
| import koper.demo.trading.mapper.Order;
import koper.demo.trading.mapper.OrderMapper;
import junit.textui.TestRunner;
import org.springframework.test.AbstractDependencyInjectionSpringContextTests; | /*
* 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 koper.kafka;
/**
* @author kk
* @since 1.0
*/
public class SendMsgAopTest extends AbstractDependencyInjectionSpringContextTests {
private OrderMapper orderMapper;
/**
* @param orderMapper the orderMapper to set
*/
public void setOrderMapper(OrderMapper orderMapper) {
this.orderMapper = orderMapper;
}
@Override
protected String[] getConfigLocations() {
return new String[]{
"classpath:kafka/context-data-message.xml",
"classpath:kafka/context-data-producer.xml"
};
}
public void testMethodSendMessage() {
System.out.println("kk research lab.");
| // Path: koper-testcase/src/main/java/koper/demo/trading/mapper/Order.java
// public class Order {
//
// public String orderId;
// public String orderName;
// public Date createDate;
// public String memberId;
// public BigDecimal totalPrice;
//
// public String getOrderId() {
// return orderId;
// }
// public void setOrderId(String orderId) {
// this.orderId = orderId;
// }
// public String getOrderName() {
// return orderName;
// }
// public void setOrderName(String orderName) {
// this.orderName = orderName;
// }
// public Date getCreateDate() {
// return createDate;
// }
// public void setCreateDate(Date createDate) {
// this.createDate = createDate;
// }
// public String getMemberId() {
// return memberId;
// }
// public void setMemberId(String memberId) {
// this.memberId = memberId;
// }
// public BigDecimal getTotalPrice() {
// return totalPrice;
// }
// public void setTotalPrice(BigDecimal totalPrice) {
// this.totalPrice = totalPrice;
// }
//
// @Override
// public String toString() {
// return "Order{" +
// "orderId='" + orderId + '\'' +
// ", orderName='" + orderName + '\'' +
// ", createDate=" + createDate +
// ", memberId='" + memberId + '\'' +
// ", totalPrice=" + totalPrice +
// '}';
// }
// }
//
// Path: koper-testcase/src/main/java/koper/demo/trading/mapper/OrderMapper.java
// public interface OrderMapper {
//
// String getOrder(String orderId, Order order);
//
// String cancelOrder(Order order);
//
// String createOrder(String memberId, Order order);
//
// String updateOrder(Order order);
//
// String insertOrder(Order order);
//
// /**
// * @param orderId
// * @param order
// * @return
// */
// String deleteOrder(String orderId, Order order);
//
// String deleteOldOrder(int orderId, boolean reserve);
//
// String cancelOldOrder(Order order);
// }
// Path: koper-testcase/src/test/java/koper/kafka/SendMsgAopTest.java
import koper.demo.trading.mapper.Order;
import koper.demo.trading.mapper.OrderMapper;
import junit.textui.TestRunner;
import org.springframework.test.AbstractDependencyInjectionSpringContextTests;
/*
* 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 koper.kafka;
/**
* @author kk
* @since 1.0
*/
public class SendMsgAopTest extends AbstractDependencyInjectionSpringContextTests {
private OrderMapper orderMapper;
/**
* @param orderMapper the orderMapper to set
*/
public void setOrderMapper(OrderMapper orderMapper) {
this.orderMapper = orderMapper;
}
@Override
protected String[] getConfigLocations() {
return new String[]{
"classpath:kafka/context-data-message.xml",
"classpath:kafka/context-data-producer.xml"
};
}
public void testMethodSendMessage() {
System.out.println("kk research lab.");
| Order order = new Order(); |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.