|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object openjava.mop.OJClass
The OJClass
class represents a class metaobject. If
the class has its valid .class file in CLASSPATH, the metaobject can
behave like java.lang.Class
. If the class has its
valid .oj file in the packages where some classes are being compiled
by OpenJava system, or in the packages explicitly specified by
something like OpenJava compiler option or environment variable, the
metaobject can have information about source code just as
stamements, expressions, and etc.
Additionaly, you can overrides the methods for introspection.
OJClass[] getDeclaredClasses() OJMethod[] getDeclaredMethods() OJField[] getDeclaredFields() OJConstructor[] getDeclaredConstructors() OJMethod getAcceptableMethod(OJClass,String,OJClass[]) OJMethod getAcceptableConstructor(OJClass,String,OJClass[])
Class
,
OJMethod
,
OJField
,
OJConstructor
| Field Summary |
| Fields inherited from interface openjava.mop.OJMember |
DECLARED, PUBLIC |
| Constructor Summary | |
OJClass(java.lang.Class java_class,
MetaInfo metainfo)
Generates a metaobject from byte code. |
|
OJClass(Environment outer_env,
OJClass declarer,
ClassDeclaration ptree)
Generates a metaobject from source code. |
| Method Summary | |
protected OJClass |
addClass(OJClass clazz)
|
protected OJConstructor |
addConstructor(OJConstructor constr)
|
protected OJField |
addField(OJField field)
|
protected void |
addInterface(OJClass clazz)
|
protected OJMethod |
addMethod(OJMethod method)
|
protected void |
beClass()
Under implementation. |
protected void |
beInterface()
Under implementation. |
Expression |
expandAllocation(Environment env,
AllocationExpression expr)
|
Expression |
expandArrayAccess(Environment env,
ArrayAccess expr)
|
Expression |
expandArrayAllocation(Environment env,
ArrayAllocationExpression expr)
|
Expression |
expandAssignmentExpression(Environment env,
AssignmentExpression expr)
|
Expression |
expandCastedExpression(Environment env,
CastExpression decl)
|
Expression |
expandCastExpression(Environment env,
CastExpression decl)
|
Expression |
expandExpression(Environment env,
Expression expr)
|
Expression |
expandFieldRead(Environment env,
FieldAccess expr)
|
Expression |
expandFieldWrite(Environment env,
AssignmentExpression expr)
|
Expression |
expandMethodCall(Environment env,
MethodCall expr)
|
TypeName |
expandTypeName(Environment env,
TypeName expr)
|
Statement |
expandVariableDeclaration(Environment env,
VariableDeclaration decl)
|
static OJClass |
forClass(java.lang.Class javaClass)
Converts a OJClass object to an OJClass
object. |
static OJClass |
forName(java.lang.String name)
Returns the OJClass object associated with the class
with the given string name. |
static OJClass |
forParseTree(Environment env,
OJClass declaringClass,
ClassDeclaration ptree)
Converts ParseTree objects to an OJClass
object. |
OJConstructor |
getAcceptableConstructor(OJClass[] parameterTypes,
OJClass situation)
Can be overriden |
OJMethod |
getAcceptableMethod(java.lang.String name,
OJClass[] parameterTypes,
OJClass situation)
Can be overriden |
OJClass[] |
getAllClasses()
|
OJField |
getAllField(java.lang.String name)
Deprecated. |
OJField[] |
getAllFields()
|
OJMethod |
getAllMethod(java.lang.String name,
OJClass[] parameterTypes)
Deprecated. |
OJMethod[] |
getAllMethods()
|
OJMethod[] |
getAllMethods(java.lang.String name)
Deprecated. |
java.lang.Class |
getByteCode()
|
OJClass[] |
getClasses()
Returns an array containing OJClass objects
representing all the public classes and interfaces
that are members of the class represented by this
OJClass object. |
OJClass[] |
getClasses(OJClass situation)
Returns an array containing OJClass objects
representing all the classes and interfaces which are members
of the class represented by this OJClass object,
accessible from the situation represented by the given
OJClass object. |
java.lang.Class |
getCompatibleJavaClass()
|
OJClass |
getComponentType()
Returns the OJClass representing the component type of an
array. |
OJConstructor |
getConstructor(OJClass[] parameterTypes)
Returns a OJConstructor object that reflects the
specified public constructor of the class represented by this
OJClass object. |
OJConstructor |
getConstructor(OJClass[] parameterTypes,
OJClass situation)
Returns a OJConstructor object that reflects the
specified constructor accesible from the situation represented
by the given OJClass object. |
OJConstructor[] |
getConstructors()
Returns an array containing OJConstructor objects
reflecting all the public constructors of the class
represented by this OJClass object. |
OJConstructor[] |
getConstructors(OJClass situation)
Returns an array containing OJConstructor objects
reflecting all the constructors of the class represented by
this OJClass object, accesible from the situation
represented by the given OJClass object. |
OJClass[] |
getDeclaredClasses()
Returns an array of OJClass objects reflecting all
the classes and interfaces declared as members of the class
represented by this OJClass object. |
OJConstructor |
getDeclaredConstructor(OJClass[] parameterTypes)
Returns a OJConstructor object that reflects the
specified constructor of the class or interface represented by
this OJClass object. |
OJConstructor[] |
getDeclaredConstructors()
Returns an array of OJConstructor objects reflecting
all the constructors declared by the class represented by this
OJClass object. |
OJField |
getDeclaredField(java.lang.String name)
Returns a OJField object that reflects the specified
declared field of the class or interface represented by this
OJClass object. |
OJField[] |
getDeclaredFields()
Returns an array of OJField objects reflecting all
the fields declared by the class or interface represented by
this OJClass object. |
OJMethod |
getDeclaredMethod(java.lang.String name,
OJClass[] parameterTypes)
Returns a OJMethod object that reflects the
specified declared method of the class or interface represented
by this OJClass object. |
OJMethod[] |
getDeclaredMethods()
Returns an array of OJMethod objects reflecting all
the methods declared by the class or interface represented by
this OJClass object. |
OJClass |
getDeclaringClass()
If the class or interface represented by this OJClass object is a member of another class,
returns the OJClass object representing the class
in which it was declared. |
static SyntaxRule |
getDeclSuffixRule(java.lang.String keyword)
|
Environment |
getEnvironment()
Obtains an environment of this class object. |
OJField |
getField(java.lang.String name)
Returns a OJField object that reflects the
specified public member field of the class or
interface represented by this OJClass object. |
OJField |
getField(java.lang.String name,
OJClass situation)
Returns a OJField object that reflects the
specified member field accesible from the situation represented
by the given OJClass object. |
OJField[] |
getFields()
Returns an array containing OJField objects
reflecting all the accessible public fields of the
class or interface represented by this OJClass
object. |
OJField[] |
getFields(OJClass situation)
Returns an array containing OJField objects
reflecting all the fields of the class or interface represented
by this OJClass object, accessible from the
situation represented by the given OJClass object. |
OJClass[] |
getInheritableClasses()
Deprecated. |
OJClass[] |
getInheritableClasses(OJClass situation)
|
OJConstructor[] |
getInheritableConstructors(OJClass situation)
|
OJField[] |
getInheritableFields()
Deprecated. |
OJField[] |
getInheritableFields(OJClass situation)
|
OJMethod[] |
getInheritableMethods()
Deprecated. |
OJMethod[] |
getInheritableMethods(OJClass situation)
|
OJClass[] |
getInheritedClasses()
|
OJField[] |
getInheritedFields()
|
OJMethod[] |
getInheritedMethods()
|
OJClass[] |
getInterfaces()
Determines the interfaces implemented by the class or interface represented by this object. |
java.lang.String |
getMetaInfo(java.lang.String key)
|
java.util.Enumeration |
getMetaInfoElements()
|
java.util.Enumeration |
getMetaInfoKeys()
|
OJMethod |
getMethod(java.lang.String name,
OJClass[] parameterTypes)
Returns a OJMethod object that reflects the
specified public member method of the class or interface
represented by this OJClass object. |
OJMethod |
getMethod(java.lang.String name,
OJClass[] parameterTypes,
OJClass situation)
Returns a OJMethod object that reflects the
specified member method accesible from the situation
represented by the given OJClass object. |
OJMethod[] |
getMethods()
Returns an array containing OJMethod objects
reflecting all the public member methods of the class
or interface represented by this OJClass object,
including those declared by the class or interface and and
those inherited from superclasses and superinterfaces. |
OJMethod[] |
getMethods(OJClass situation)
Returns an array containing OJMethod objects
reflecting all the member methods of the class or interface
represented by this OJClass object, accesible from
the situation represented by the given OJClass
object. |
OJModifier |
getModifiers()
Returns the Java language modifiers and the user defined modifiers for this class or interface, as a OJModifier object. |
java.lang.String |
getName()
Returns the fully-qualified name of the entity (class, interface, array class, primitive type, or void) represented by this OJClass object, as a String . |
java.lang.String |
getPackage()
Gets the package name for this class as a String . |
java.lang.String |
getSimpleName()
Returns the simple name of the class, interface or array class represented by this OJClass object, as a
String . |
ClassDeclaration |
getSourceCode()
|
ParseTree |
getSuffix(java.lang.String keyword)
Obtains an parse tree of suffix in extended syntax starting with the specified keyword. |
OJClass |
getSuperclass()
Returns the OJClass representing the superclass of
the entity (class, interface, primitive type or void)
represented by this OJClass . |
static SyntaxRule |
getTypeSuffixRule(java.lang.String keyword)
|
boolean |
isAlterable()
|
boolean |
isArray()
Determines if this OJClass object represents an
array class. |
boolean |
isAssignableFrom(OJClass clazz)
Determines if the class or interface represented by this OJClass object is either the same as, or is a
superclass or superinterface of, the class or interface
represented by the specified OJClass parameter. |
boolean |
isExecutable()
|
boolean |
isInSamePackage(OJClass c)
Determines if the specified class object is in the same package as this class object. |
boolean |
isInterface()
Determines if the specified OJClass object represents
an interface type. |
boolean |
isPrimitive()
Determines if the specified OJClass object represents a
primitive type. |
boolean |
isPrimitiveWrapper()
Determines if the specified OJClass object represents a
wrapper class for a primitive type. |
static boolean |
isRegisteredKeyword(java.lang.String keyword)
|
static boolean |
isRegisteredModifier(java.lang.String keyword)
|
OJClass |
makeCopy(java.lang.String qname)
Generate a copy of this class object with the specified name. |
protected static Expression |
makeExpression(Environment env,
java.lang.String str)
Generates a expression parse tree from a given String object under the given environment. |
protected Expression |
makeExpression(java.lang.String str)
Generates an expression parse tree from a given String object under the environment of
this class object. |
protected static Statement |
makeStatement(Environment env,
java.lang.String str)
Generates a statement parse tree from a given String object under the given environment. |
protected Statement |
makeStatement(java.lang.String str)
Generates a statement parse tree from a given String object under the environment of
this class object. |
protected static StatementList |
makeStatementList(Environment env,
java.lang.String str)
Generates a statement list parse tree from a given String object under the given environment. |
protected StatementList |
makeStatementList(java.lang.String str)
Generates a statement list parse tree from a given String object under the environment of
this class object. |
OJClass |
primitiveWrapper()
Obtains the wrapper class if this class represents a primitive type. |
protected java.lang.String |
putMetaInfo(java.lang.String key,
java.lang.String value)
|
protected OJClass |
removeClass(OJClass clazz)
|
protected OJConstructor |
removeConstructor(OJConstructor constr)
|
protected OJField |
removeField(OJField field)
|
protected OJMethod |
removeMethod(OJMethod method)
|
OJField |
resolveException(NoSuchMemberException e,
java.lang.String name)
|
OJMethod |
resolveException(NoSuchMemberException e,
java.lang.String name,
OJClass[] argtypes)
|
protected OJClass[] |
setInterfaces(OJClass[] classes)
|
protected java.lang.String |
setName(java.lang.String simple_name)
not implemented yet |
protected OJClass |
setSuperclass(OJClass clazz)
|
Signature |
signature()
|
java.lang.String |
toString()
Converts the object to a string. |
void |
translateDefinition()
|
ClassDeclaration |
translateDefinition(Environment env,
ClassDeclaration decl)
|
OJClass |
unwrappedPrimitive()
Obtains the real type class if this class represents a primitive wrapper type. |
void |
waitTranslation(OJClass clazz)
Waits a callee-side translation on another class metaobject to be done. |
void |
writeMetaInfo(java.io.Writer out)
inner use only |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
public OJClass(Environment outer_env, OJClass declarer, ClassDeclaration ptree)
This constructor will be invoked by the OpenJava system. In inheriting this class, you must call this consturctor from a constructor with the same signature in your class.
For example, in defining a subclass YourClass
derived from this class, at least you have to write as follows:
public YourClass( Environment outer_env, OJClass declarer, ClassDeclaration ptree ) { super( outer_env, declarer, ptree ); }
outer_env
- environment of this class metaobjectdeclarer
- the class metaobject declaring this
class metaobject.ptree
- the parse tree representing this class metaobject.public OJClass(java.lang.Class java_class, MetaInfo metainfo)
This constructor will be invoked only by the OpenJava system. In inheriting this class, you must call this consturctor from a constructor with the same signature in your class.
For example, in defining a subclass YourClass
derived from this class, at least you have to write as follows:
public YourClass( Class java_class, MetaInfo metainfo ) { super( java_class, metainfo ); }
| Method Detail |
public static OJClass forName(java.lang.String name) throws OJClassNotFoundException
OJClass
object associated with the class
with the given string name.
Given the fully-qualified name for a class or interface, this
method attempts to locate, load and link the class. If it
succeeds, returns the Class object representing the class. If
it fails, the method throws a OJClassNotFoundException.
For example, the following code fragment returns the runtime
OJClass
descriptor for the class named
java.lang.Thread
:
OJClass t = OJClass.forName( "java.lang.Thread" );
OJClass
descriptor for the class with
the specified name.
OJClassNotFoundException
- if the class could not be found.public static OJClass forClass(java.lang.Class javaClass)
OJClass
object to an OJClass
object.
This method returns the same OJClass
object
whenever it is invoked for the same Class
object.
It gurantees one-to-one correspondence between Class
and OJClass
.
public static OJClass forParseTree(Environment env, OJClass declaringClass, ClassDeclaration ptree) throws AmbiguousClassesException, java.lang.ClassNotFoundException
ParseTree
objects to an OJClass
object. The generated OJClass
object is to be
registered as globally asscessible class but not to appear as
generated source code.
AmbiguousClassesException
java.lang.ClassNotFoundException
protected static final Expression makeExpression(Environment env, java.lang.String str) throws MOPException
String
object under the given environment.
env
- an environment for the source code.str
- a fragment of source code representing an expression.
MOPException
protected final Expression makeExpression(java.lang.String str) throws MOPException
String
object under the environment of
this class object.
str
- a fragment of source code representing an expression.
MOPException
protected static final Statement makeStatement(Environment env, java.lang.String str) throws MOPException
String
object under the given environment.
env
- an environment for the source code.str
- a fragment of source code representing a statement.
MOPException
protected final Statement makeStatement(java.lang.String str) throws MOPException
String
object under the environment of
this class object.
str
- a fragment of source code representing a statement.
MOPException
protected static final StatementList makeStatementList(Environment env, java.lang.String str) throws MOPException
String
object under the given environment.
env
- an environment for the source code.str
- a fragment of source code representing a statement list.
MOPException
protected final StatementList makeStatementList(java.lang.String str) throws MOPException
String
object under the environment of
this class object.
str
- a fragment of source code representing a statement list.
MOPException
public java.lang.String toString()
getName
. If this OJClass
object
represents a primitive type, this method returns the name of the
primitive type. If this OJClass
object represents
void this method returns "void".
public Environment getEnvironment()
getEnvironment
in interface OJMember
public boolean isAssignableFrom(OJClass clazz)
OJClass
object is either the same as, or is a
superclass or superinterface of, the class or interface
represented by the specified OJClass
parameter. It
returns true
if so; otherwise it returns
false
. If this OJClass
object
represents a primitive type, this method returns
true
if the type represented by this
OJClass
object can accept the type represented by
the specified OJClass
parameter; otherwise it
returns false
.
Specifically, this method tests whether the type
represented by the specified OJClass
parameter can
be converted to the type represented by this
OJClass
object via an identity conversion or via a
widening reference/primitive conversion.
The behavior
about primitive types is different from the method of the same
name of java.lang.Class
.
java.lang.NullPointerException
- if the specified class parameter is
null.public boolean isInterface()
OJClass
object represents
an interface type.
true
if this object represents an interface;
false
otherwise.public boolean isArray()
OJClass
object represents an
array class.
true
if this object represents an array class;
false
otherwise.public boolean isPrimitive()
OJClass
object represents a
primitive type.
There are nine predefined OJClass
objects to represent
the eight primitive types and void. These are created by the Java
Virtual Machine, and have the same names as the primitive types that
they represent, namely boolean
, byte
,
char
, short
, int
,
long
, float
, and double
.
These objects may be accessed via the following public static
final variables, and are the only OJClass
objects for
which this method returns true
.
true
if this object represents a primitive type;
false
otherwise.OJSystem.BOOLEAN
,
OJSystem.CHAR
,
OJSystem.BYTE
,
OJSystem.SHORT
,
OJSystem.INT
,
OJSystem.LONG
,
OJSystem.FLOAT
,
OJSystem.DOUBLE
,
OJSystem.VOID
public boolean isPrimitiveWrapper()
OJClass
object represents a
wrapper class for a primitive type.
true
if this object represents a wrapper class
for a primitive type; false
otherwise.public OJClass primitiveWrapper()
For example this method returns java.lang.Integer for int.
null
for void.public OJClass unwrappedPrimitive()
For example this method returns int for java.lang.Integer.
public java.lang.String getName()
OJClass
object, as a String
.
If this OJClass
object represents a class of
arrays, then the internal form of the name consists of the name
of the element type in Java signature format, followed by one
or more "[]" characters representing the depth of array
nesting. This representation differs from that of
java.lang.Class.forName()
. Thus:
returns "OJClass.forClass( (new int[3][4]).getClass() ).getName()
java.lang.Object[]
" and:
returns "OJClass.forClass( (new int[3][4]).getClass() ).getName()
int[][]
".
The class or interface name classname is given in fully qualified form as shown in the example above.
getName
in interface OJMember
public java.lang.String getSimpleName()
OJClass
object, as a
String
. Thus:
returns "OJClass.forClass( (new Object[3]).getClass() ).getName()
Object
".
public java.lang.String getPackage()
String
.
Null is returned if its package was not specified in source code of
this class.
public boolean isInSamePackage(OJClass c)
If null is given, this method returns alway false.
c
- the class object to test against this class object.
public OJClass getSuperclass()
OJClass
representing the superclass of
the entity (class, interface, primitive type or void)
represented by this OJClass
. If this
OJClass
represents either the
java.lang.Object
class, an interface, a primitive
type, or void, then null is returned. If this object
represents an array class then the OJClass
object
representing the java.lang.Object
class is
returned.
public OJClass[] getInterfaces()
If this object represents a class, the return value is an array
containing objects representing all interfaces implemented by the
class. The order of the interface objects in the array corresponds to
the order of the interface names in the implements
clause
of the declaration of the class represented by this object. For
example, given the declaration:
suppose the value ofclass Shimmer implements FloorWax, DessertTopping { ... }
clazz
is an class object for
the class Shimmer
; the value of the expression:
is theclazz.getInterfaces()[0]
OJClass
object that represents interface
FloorWax
; and the value of:
is theclazz.getInterfaces()[1]
OJClass
object that represents interface
DessertTopping
.
If this object represents an interface, the array contains
objects representing all interfaces extended by the
interface. The order of the interface objects in the array
corresponds to the order of the interface names in the
extends
clause of the declaration of the interface
represented by this object.
If this object represents a class or interface that implements no interfaces, the method returns an array of length 0.
If this object represents a primitive type or void, the method returns an array of length 0.
To be
getDeclaredInterfaces()
.
public OJClass getComponentType()
OJClass
representing the component type of an
array. If this class does not represent an array class this method
returns null.
public OJModifier getModifiers()
OJModifier
object.
If the underlying class is an array class, then its
public
, private
and protected
modifiers are the same as those of its component type. If this
OJClass
represents a primitive type or void, its
public
modifier is always true
, and its
protected
and private
modifers are always
false
. If this object represents an array class, a
primitive type or void, then its final
modifier is always
true
and its interface modifer is always
false
. The values of its other modifiers are not determined
by this specification.
getModifiers
in interface OJMember
OJModifier
public ParseTree getSuffix(java.lang.String keyword)
openjava.ptree.ParseTree
object has a structure
built by an openjava.syntax.SyntaxRule
object
returned via the method getDeclSuffixRule(String)
.
getDeclSuffixRule(String)
,
SyntaxRule
public OJClass getDeclaringClass()
OJClass
object is a member of another class,
returns the OJClass
object representing the class
in which it was declared. This method returns null if this
class or interface is not a member of any other class. If this
OJClass
object represents an array class, a
primitive type, or void, then this method returns null.
getDeclaringClass
in interface OJMember
public final OJClass[] getAllClasses()
public final OJField[] getAllFields()
public final OJMethod[] getAllMethods()
public OJClass[] getInheritedClasses()
public OJField[] getInheritedFields()
public final OJMethod[] getInheritedMethods()
public final OJClass[] getInheritableClasses()
getInheritableClasses(OJClass)
getInheritableClasses(OJClass)
public final OJField[] getInheritableFields()
getInheritableFields(OJClass)
getInheritableFields(OJClass)
public final OJMethod[] getInheritableMethods()
getInheritableMethods(OJClass)
getInheritableMethodss(OJClass)
public OJClass[] getInheritableClasses(OJClass situation)
public OJField[] getInheritableFields(OJClass situation)
public OJMethod[] getInheritableMethods(OJClass situation)
public OJConstructor[] getInheritableConstructors(OJClass situation)
public OJClass[] getClasses()
OJClass
objects
representing all the public classes and interfaces
that are members of the class represented by this
OJClass
object. This includes public class and
interface members inherited from superclasses and public class
and interface members declared by the class. This method
returns an array of length 0 if this OJClass
object has no public member classes or interfaces. This method
also returns an array of length 0 if this OJClass
object represents a primitive type, an array class, or void.
public OJField[] getFields()
OJField
objects
reflecting all the accessible public fields of the
class or interface represented by this OJClass
object. The elements in the array returned are not sorted and
are not in any particular order. This method returns an array
of length 0 if the class or interface has no accessible public
fields, or if it represents an array class, a primitive type,
or void.
Specifically, if this OJClass
object
represents a class, this method returns the public fields of
this class and of all its superclasses. If this
OJClass
object represents an interface, this
method returns the fields of this interface and of all its
superinterfaces.
The implicit length field for array classs is reflected by this method.
OJField
public OJMethod[] getMethods()
OJMethod
objects
reflecting all the public member methods of the class
or interface represented by this OJClass
object,
including those declared by the class or interface and and
those inherited from superclasses and superinterfaces. The
elements in the array returned are not sorted and are not in
any particular order. This method returns an array of length 0
if this OJClass
object represents a class or
interface that has no public member methods, or if this
OJClass
object represents an array class, primitive
type, or void.
OJMethod
public OJConstructor[] getConstructors()
OJConstructor
objects
reflecting all the public constructors of the class
represented by this OJClass
object. An array of
length 0 is returned if the class has no public constructors,
or if the class is an array class, or if the class reflects a
primitive type or void.
OJConstructor
public OJField getField(java.lang.String name) throws NoSuchMemberException
OJField
object that reflects the
specified public member field of the class or
interface represented by this OJClass
object. The
name
parameter is a String
specifying
the simple name of the desired field.
NoSuchMemberException
- if a field with the specified name is
not found.OJField
public OJMethod getMethod(java.lang.String name, OJClass[] parameterTypes) throws NoSuchMemberException
OJMethod
object that reflects the
specified public member method of the class or interface
represented by this OJClass
object. The
name
parameter is a String
specifying
the simple name the desired method. The
parameterTypes
parameter is an array of
OJClass
objects that identify the method's formal
parameter types, in declared order. If
parameterTypes
is null
, it is treated
as if it were an empty array.
NoSuchMemberException
- if a matching method is not found
or if then name is "<init>"or "<clinit>".OJMethod
public OJConstructor getConstructor(OJClass[] parameterTypes) throws NoSuchMemberException
OJConstructor
object that reflects the
specified public constructor of the class represented by this
OJClass
object. The parameterTypes
parameter is an array of OJClass
objects that
identify the constructor's formal parameter types, in declared
order.
The constructor to reflect is the public constructor of the
class represented by this OJClass
object whose
formal parameter types match those specified by
parameterTypes
.
NoSuchMemberException
- if a matching method is not found.OJConstructor
public final OJClass[] getClasses(OJClass situation)
OJClass
objects
representing all the classes and interfaces which are members
of the class represented by this OJClass
object,
accessible from the situation represented by the given
OJClass
object. This includes class and interface
members inherited from superclasses and declared class and
interface members accessible from the given situation. This
method returns an array of length 0 if this
OJClass
object has no public member classes or
interfaces. This method also returns an array of length 0 if
this OJClass
object represents a primitive type,
an array class, or void.
The accessiblity depends on the package of the class, modifiers of each members, and the package of the situation.
public final OJField[] getFields(OJClass situation)
OJField
objects
reflecting all the fields of the class or interface represented
by this OJClass
object, accessible from the
situation represented by the given OJClass
object.
The elements in the array returned are not sorted and
are not in any particular order. This method returns an array
of length 0 if the class or interface has no accessible public
fields, or if it represents an array class, a primitive type,
or void.
Specifically, if this OJClass
object
represents a class, this method returns the public fields of
this class and of all its superclasses. If this
OJClass
object represents an interface, this
method returns the fields of this interface and of all its
superinterfaces.
The accessiblity depends on the package of the class, modifiers of each members, and the package of the situation.
The implicit length field for array classs is reflected by this method.
OJField
public final OJMethod[] getMethods(OJClass situation)
OJMethod
objects
reflecting all the member methods of the class or interface
represented by this OJClass
object, accesible from
the situation represented by the given OJClass
object. Returned methods include those declared by the class
or interface and and those inherited from superclasses and
superinterfaces. The elements in the array returned are not
sorted and are not in any particular order. This method
returns an array of length 0 if this OJClass
object represents a class or interface that has no public
member methods, or if this OJClass
object
represents an array class, primitive type, or void.
The accessiblity depends on the package of the class, modifiers of each members, and the package of the situation.
OJMethod
public final OJConstructor[] getConstructors(OJClass situation)
OJConstructor
objects
reflecting all the constructors of the class represented by
this OJClass
object, accesible from the situation
represented by the given OJClass
object. An array
of length 0 is returned if the class has no public
constructors, or if the class is an array class, or if the
class reflects a primitive type or void.
The accessiblity depends on the package of the class, modifiers of each members, and the package of the situation.
OJConstructor
public OJField getField(java.lang.String name, OJClass situation) throws NoSuchMemberException
OJField
object that reflects the
specified member field accesible from the situation represented
by the given OJClass
object. The
name
parameter is a String
specifying
the simple name of the desired field.
NoSuchMemberException
- if a field with the specified name is
not found.OJField
public OJMethod getMethod(java.lang.String name, OJClass[] parameterTypes, OJClass situation) throws NoSuchMemberException
OJMethod
object that reflects the
specified member method accesible from the situation
represented by the given OJClass
object. The
name
parameter is a String
specifying
the simple name the desired method. The
parameterTypes
parameter is an array of
OJClass
objects that identify the method's formal
parameter types, in declared order. If
parameterTypes
is null
, it is treated
as if it were an empty array.
NoSuchMemberException
- if a matching method is not found.OJMethod
public OJConstructor getConstructor(OJClass[] parameterTypes, OJClass situation) throws NoSuchMemberException
OJConstructor
object that reflects the
specified constructor accesible from the situation represented
by the given OJClass
object. The
parameterTypes
parameter is an array of
OJClass
objects that identify the constructor's
formal parameter types, in declared order.
The constructor to reflect is the constructor of the
class represented by this OJClass
object whose
formal parameter types match those specified by
parameterTypes
.
NoSuchMemberException
- if a matching method is not found.OJConstructor
public final OJField getAllField(java.lang.String name) throws NoSuchMemberException
c.getField(name,c)
NoSuchMemberException
getField(String,OJClass)
public final OJMethod[] getAllMethods(java.lang.String name)
public final OJMethod getAllMethod(java.lang.String name, OJClass[] parameterTypes) throws NoSuchMemberException
c.getMethod(name,ptypes,c)
NoSuchMemberException
getMethod(String,OJClass[],OJClass)
public OJMethod getAcceptableMethod(java.lang.String name, OJClass[] parameterTypes, OJClass situation) throws NoSuchMemberException
NoSuchMemberException
public OJConstructor getAcceptableConstructor(OJClass[] parameterTypes, OJClass situation) throws NoSuchMemberException
NoSuchMemberException
public OJClass[] getDeclaredClasses()
OJClass
objects reflecting all
the classes and interfaces declared as members of the class
represented by this OJClass
object. This includes
public, protected, default (package) access, and private
classes and interfaces declared by the class, but excludes
inherited classes and interfaces. This method returns an array
of length 0 if the class declares no classes or interfaces as
members, or if this OJClass
object represents a
primitive type, an array class, or void.
This method may be overriden to provide proper information in the extended language.
public OJField[] getDeclaredFields()
OJField
objects reflecting all
the fields declared by the class or interface represented by
this OJClass
object. This includes public,
protected, default (package) access, and private fields, but
excludes inherited fields. The elements in the array returned
are not sorted and are not in any particular order. This
method returns an array of length 0 if the class or interface
declares no fields, or if this OJClass
object
represents a primitive type, an array class, or void.
This method may be overriden to provide proper information in the extended language.
OJField
public OJMethod[] getDeclaredMethods()
OJMethod
objects reflecting all
the methods declared by the class or interface represented by
this OJClass
object. This includes public,
protected, default (package) access, and private methods, but
excludes inherited methods. The elements in the array returned
are not sorted and are not in any particular order. This
method returns an array of length 0 if the class or interface
declares no methods, or if this OJClass
object
represents a primitive type, an array class, or void. The
class initialization method <clinit>
is not
included in the returned array. If the class declares multiple
public member methods with the same parameter types, they are
all included in the returned array.
This method may be overriden to provide proper information in the extended language.
OJMethod
public OJConstructor[] getDeclaredConstructors()
OJConstructor
objects reflecting
all the constructors declared by the class represented by this
OJClass
object. These are public, protected, default
(package) access, and private constructors. The elements in
the array returned are not sorted and are not in any particular
order. If the class has a default constructor, it is included
in the returned array. This method returns an array of length
0 if this OJClass
object represents an interface, a
primitive type, an array class, or void.
This method may be overriden to provide proper information in the extended language.
OJConstructor
public final OJField getDeclaredField(java.lang.String name) throws NoSuchMemberException
OJField
object that reflects the specified
declared field of the class or interface represented by this
OJClass
object. The name
parameter is a
String
that specifies the simple name of the
desired field. Note that this method will reflect the
length
field of an array class.
NoSuchMemberException
- if a field with the specified name is
not found.OJField
public final OJMethod getDeclaredMethod(java.lang.String name, OJClass[] parameterTypes) throws NoSuchMemberException
OJMethod
object that reflects the
specified declared method of the class or interface represented
by this OJClass
object. The name
parameter is a String
that specifies the simple
name of the desired method, and the parameterTypes
parameter is an array of OJClass
objects that
identify the method's formal parameter types, in declared
order. If more than one method with the same parameter types
is declared in a class, and one of these methods has a return
type that is more specific than any of the others, that method
is returned; otherwise one of the methods is chosen
arbitrarily.
NoSuchMemberException
- if a matching method is not found.OJMethod
public final OJConstructor getDeclaredConstructor(OJClass[] parameterTypes) throws NoSuchMemberException
OJConstructor
object that reflects the
specified constructor of the class or interface represented by
this OJClass
object. The
parameterTypes
parameter is an array of
OJClass
objects that identify the constructor's
formal parameter types, in declared order.
NoSuchMemberException
- if a matching method is not found.OJConstructor
public OJClass makeCopy(java.lang.String qname) throws MOPException
qname
- a qualified name for the new copy.
MOPException
public boolean isExecutable()
public boolean isAlterable()
public java.lang.Class getByteCode() throws CannotExecuteException
CannotExecuteException
public ClassDeclaration getSourceCode() throws CannotAlterException
CannotAlterException
public java.lang.Class getCompatibleJavaClass()
public Signature signature()
signature
in interface OJMember
public final void waitTranslation(OJClass clazz) throws MOPException
clazz
- a class metaobject to wait
MOPException
protected java.lang.String setName(java.lang.String simple_name) throws CannotAlterException
CannotAlterException
protected void beInterface() throws CannotAlterException
CannotAlterException
protected void beClass() throws CannotAlterException
CannotAlterException
protected OJClass setSuperclass(OJClass clazz) throws CannotAlterException
CannotAlterException
protected OJClass[] setInterfaces(OJClass[] classes) throws CannotAlterException
CannotAlterException
protected void addInterface(OJClass clazz) throws CannotAlterException
CannotAlterException
protected OJClass addClass(OJClass clazz) throws CannotAlterException
CannotAlterException
protected OJClass removeClass(OJClass clazz) throws CannotAlterException
CannotAlterException
protected OJField addField(OJField field) throws CannotAlterException
CannotAlterException
protected OJField removeField(OJField field) throws CannotAlterException
CannotAlterException
protected OJMethod addMethod(OJMethod method) throws CannotAlterException
CannotAlterException
protected OJMethod removeMethod(OJMethod method) throws CannotAlterException
CannotAlterException
protected OJConstructor addConstructor(OJConstructor constr) throws CannotAlterException
CannotAlterException
protected OJConstructor removeConstructor(OJConstructor constr) throws CannotAlterException
CannotAlterException
public void translateDefinition() throws MOPException
MOPException
public ClassDeclaration translateDefinition(Environment env, ClassDeclaration decl) throws MOPException
MOPException
public Expression expandFieldRead(Environment env, FieldAccess expr)
public Expression expandFieldWrite(Environment env, AssignmentExpression expr)
public Expression expandMethodCall(Environment env, MethodCall expr)
public TypeName expandTypeName(Environment env, TypeName expr)
public Expression expandAllocation(Environment env, AllocationExpression expr)
public Expression expandArrayAllocation(Environment env, ArrayAllocationExpression expr)
public Expression expandArrayAccess(Environment env, ArrayAccess expr)
public Expression expandAssignmentExpression(Environment env, AssignmentExpression expr)
public Expression expandExpression(Environment env, Expression expr)
public Statement expandVariableDeclaration(Environment env, VariableDeclaration decl)
public Expression expandCastExpression(Environment env, CastExpression decl)
public Expression expandCastedExpression(Environment env, CastExpression decl)
public OJField resolveException(NoSuchMemberException e, java.lang.String name) throws NoSuchMemberException
NoSuchMemberException
public OJMethod resolveException(NoSuchMemberException e, java.lang.String name, OJClass[] argtypes) throws NoSuchMemberException
NoSuchMemberException
public static boolean isRegisteredKeyword(java.lang.String keyword)
public static SyntaxRule getDeclSuffixRule(java.lang.String keyword)
public static SyntaxRule getTypeSuffixRule(java.lang.String keyword)
public static boolean isRegisteredModifier(java.lang.String keyword)
public final java.lang.String getMetaInfo(java.lang.String key)
public final java.util.Enumeration getMetaInfoKeys()
public final java.util.Enumeration getMetaInfoElements()
protected final java.lang.String putMetaInfo(java.lang.String key, java.lang.String value) throws CannotAlterException
CannotAlterException
public final void writeMetaInfo(java.io.Writer out) throws java.io.IOException
java.io.IOException
|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |


| ts.union {stats} | R Documentation |
Bind time series which have a common frequency. ts.union
pads
with NA
s to the total time coverage, ts.intersect
restricts to the time covered by all the series.
ts.intersect(..., dframe = FALSE) ts.union(..., dframe = FALSE)
... |
two or more univariate or multivariate time series, or objects which can coerced to time series. |
dframe |
logical; if |
As a special case, ...
can contain vectors or matrices of the
same length as the combined time series of the time series present, as
well as those of a single row.
A time series object if dframe
is FALSE
, otherwise a
data frame.
ts.union(mdeaths, fdeaths) cbind(mdeaths, fdeaths) # same as the previous line ts.intersect(window(mdeaths, 1976), window(fdeaths, 1974, 1978)) sales1 <- ts.union(BJsales, lead = BJsales.lead) ts.intersect(sales1, lead3 = lag(BJsales.lead, -3))


I'm a designer (musician, nutritionist) and photographer based in Ottawa, Canada. I specialize in obsessing over fine details while calmly translating information into pleasing visual experiences! Specifically, my areas of focus are branding, web and UI/UX design.
Learning and creating is where I feel best, so I appreciate that design provides infinite opportunities to do both. I am inspired by how each mind processes information differently and love to take a collaborative approach to design through empathy, research and visual translation.
Apart from design, I love reading, continuous learning, spending time in nature, and, when it is safe to do so, making and playing music with the Haig.


Arrays and hashes are useful for containing large amounts of elements in a single place. Both are able to accept more elements and store them, or remove or change the value of the elements contained within them. Arrays can be set up by either using literal notation: array = [] Or, you can use an array object constructor: array = Array.new Array's elements are accesible by their index number. Such that: array=[1,4,6,7] array[1] => will output the element in the second position [4] Arrays are indexed starting with 0 as the first position, or as Chris Pine said, "zeroith" position. The first element will have an index[0]. Every array will contain the number of indexes equal to array.length - 1 because you start with 0 as your first index position. You are able to delete elements or add elements to arrays, or even change the value of an index position in arrays. Arrays are capable of containing arrays themselves too. These are called multi-dimensional arrays: array =[['good','bad','ugly'],[3,2,1],['here',1,'we','go',2]] The arrays contained within the array are called sub-arrays. Each of their elements are accesible by first calling the parent array's index number and then the element itself's index: array[2][1] => should give you 2! I hope I'm right on that! To add elements to arrays, you can use array.push[]. This will add whatever you input to the end of the array. You can also use array.pop, and this will remove the last element of the array and tell you what it was. I won't lie, I still have so much more to learn about utilizing the power of arrays. Moving on to hashes........ Hashes are similar to arrays in that they are able to store large amounts of elements in a single place. The main difference is that hashes use a key:value pair structure. Each element in a hash is either an object key, or the value associated with that object. The creation of hashes is similar to arrays. my_hash = {'one' => 'thing'} Or, you can use the literal notation: my_hash = Hash.new As you can see, the set up is slightly different for making the key:value pairs. You must use the '=>' notation to assign a value to a key. Keys and values can be any ruby objects. To access either one from the hash, use this notation: puts "#{either key or value}" This just scrapes the surface of how and when you can use these two objects, but I need so much more practice to be able to explain them more in depth. Again, so much more to learn about the awesome power of these two objects. More to come as I come more into all of this.


Users
Team Prefix
Number of Teams
User File
User Format
User Format
Integrations
Integration Checkbox


Sprite count: 0
FPS: 0
Slide diagonally
Bounce up and down
Do a spiral
Spin!
Change size!
Size change:


July 2016 – Present
Novi Sad, Serbia | https://www.netcentric.biz/
March 2015 – Jun 2016
Novi Sad, Serbia | http://codeplicity.com/
September 2012 – January 2015
Novi Sad, Serbia | http://www.gallantdigital.com/
January 2012 – August 2012
Lisbon, Portugal | http://www.innovagency.com/
Oktober 2005 – March 2011
Nis, Serbia | http://www.elfak.ni.ac.rs/en
September 1998 - Jun 2002


A boilerplate/starter project for quickly building RESTful APIs using Node.js, Express, and Mongoose.
By running a single command, you will get a production-ready Node.js app installed and fully configured on your machine. The app comes with many built-in features, such as authentication using JWT, request validation, unit and integration tests, continuous integration, docker support, API documentation, pagination, etc. For more details, check the features list below.
To create a project, simply run:
npx create-nodejs-express-app <project-name>
Or
npm init nodejs-express-app <project-name>
If you would still prefer to do the installation manually, follow these steps:
Clone the repo:
git clone --depth 1 https://github.com/hagopj13/node-express-boilerplate.git
cd node-express-boilerplate
npx rimraf ./.git
Install the dependencies:
yarn install
Set the environment variables:
cp .env.example .env
# open .env and modify the environment variables (if needed)
Running locally:
yarn dev
Running in production:
yarn start
Testing:
# run all tests
yarn test
# run all tests in watch mode
yarn test:watch
# run test coverage
yarn coverage
Docker:
# run docker container in development mode
yarn docker:dev
# run docker container in production mode
yarn docker:prod
# run all tests in a docker container
yarn docker:test
Linting:
# run ESLint
yarn lint
# fix ESLint errors
yarn lint:fix
# run prettier
yarn prettier
# fix prettier errors
yarn prettier:fix
The environment variables can be found and modified in the .env
file. They come with these default values:
# Port number
PORT=3000
# URL of the Mongo DB
MONGODB_URL=mongodb://<IP_ADDRESS>:27017/node-boilerplate
# JWT
# JWT secret key
JWT_SECRET=thisisasamplesecret
# Number of minutes after which an access token expires
JWT_ACCESS_EXPIRATION_MINUTES=30
# Number of days after which a refresh token expires
JWT_REFRESH_EXPIRATION_DAYS=30
# SMTP configuration options for the email service
# For testing, you can use a fake SMTP service like Ethereal: https://ethereal.email/create
SMTP_HOST=email-server
SMTP_PORT=587
SMTP_USERNAME=email-server-username
SMTP_PASSWORD=email-server-password
<EMAIL_ADDRESS>src\
|--config\ # Environment variables and configuration related things
|--controllers\ # Route controllers (controller layer)
|--docs\ # Swagger files
|--middlewares\ # Custom express middlewares
|--models\ # Mongoose models (data layer)
|--routes\ # Routes
|--services\ # Business logic (service layer)
|--utils\ # Utility classes and functions
|--validations\ # Request data validation schemas
|--app.js # Express app
|--index.js # App entry point
To view the list of available APIs and their specifications, run the server and go to http://localhost:3000/v1/docs
in your browser. This documentation page is automatically generated using the swagger definitions written as comments in the route files.
List of available routes:
Auth routes:
POST /v1/auth/register
- register
POST /v1/auth/login
- login
POST /v1/auth/refresh-tokens
- refresh auth tokens
POST /v1/auth/forgot-password
- send reset password email
POST /v1/auth/reset-password
- reset password
User routes:
POST /v1/users
- create a user
GET /v1/users
- get all users
GET /v1/users/:userId
- get user
PATCH /v1/users/:userId
- update user
DELETE /v1/users/:userId
- delete user
The app has a centralized error handling mechanism.
Controllers should try to catch the errors and forward them to the error handling middleware (by calling next(error)
). For convenience, you can also wrap the controller inside the catchAsync utility wrapper, which forwards the error.
const catchAsync = require('../utils/catchAsync');
const controller = catchAsync(async (req, res) => {
// this error will be forwarded to the error handling middleware
throw new Error('Something wrong happened');
});
The error handling middleware sends an error response, which has the following format:
{
"code": 404,
"message": "Not found"
}
When running in development mode, the error response also contains the error stack.
The app has a utility ApiError class to which you can attach a response code and a message, and then throw it from anywhere (catchAsync will catch it).
For example, if you are trying to get a user from the DB who is not found, and you want to send a 404 error, the code should look something like:
const httpStatus = require('http-status');
const ApiError = require('../utils/ApiError');
const User = require('../models/User');
const getUser = async (userId) => {
const user = await User.findById(userId);
if (!user) {
throw new ApiError(httpStatus.NOT_FOUND, 'User not found');
}
};
Request data is validated using Joi. Check the documentation for more details on how to write Joi validation schemas.
The validation schemas are defined in the src/validations
directory and are used in the routes by providing them as parameters to the validate
middleware.
const express = require('express');
const validate = require('../../middlewares/validate');
const userValidation = require('../../validations/user.validation');
const userController = require('../../controllers/user.controller');
const router = express.Router();
router.post('/users', validate(userValidation.createUser), userController.createUser);
To require authentication for certain routes, you can use the auth
middleware.
const express = require('express');
const auth = require('../../middlewares/auth');
const userController = require('../../controllers/user.controller');
const router = express.Router();
router.post('/users', auth(), userController.createUser);
These routes require a valid JWT access token in the Authorization request header using the Bearer schema. If the request does not contain a valid access token, an Unauthorized (401) error is thrown.
Generating Access Tokens:
An access token can be generated by making a successful call to the register (POST /v1/auth/register
) or login (POST /v1/auth/login
) endpoints. The response of these endpoints also contains refresh tokens (explained below).
An access token is valid for 30 minutes. You can modify this expiration time by changing the JWT_ACCESS_EXPIRATION_MINUTES
environment variable in the .env file.
Refreshing Access Tokens:
After the access token expires, a new access token can be generated, by making a call to the refresh token endpoint (POST /v1/auth/refresh-tokens
) and sending along a valid refresh token in the request body. This call returns a new access token and a new refresh token.
A refresh token is valid for 30 days. You can modify this expiration time by changing the JWT_REFRESH_EXPIRATION_DAYS
environment variable in the .env file.
The auth
middleware can also be used to require certain rights/permissions to access a route.
const express = require('express');
const auth = require('../../middlewares/auth');
const userController = require('../../controllers/user.controller');
const router = express.Router();
router.post('/users', auth('manageUsers'), userController.createUser);
In the example above, an authenticated user can access this route only if that user has the manageUsers
permission.
The permissions are role-based. You can view the permissions/rights of each role in the src/config/roles.js
file.
If the user making the request does not have the required permissions to access this route, a Forbidden (403) error is thrown.
Import the logger from src/config/logger.js
. It is using the Winston logging library.
Logging should be done according to the following severity levels (ascending order from most important to least important):
const logger = require('<path to src>/config/logger');
logger.error('message'); // level 0
logger.warn('message'); // level 1
logger.info('message'); // level 2
logger.http('message'); // level 3
logger.verbose('message'); // level 4
logger.debug('message'); // level 5
In development mode, log messages of all severity levels will be printed to the console.
In production mode, only info
, warn
, and error
logs will be printed to the console.
It is up to the server (or process manager) to actually read them from the console and store them in log files.
This app uses pm2 in production mode, which is already configured to store the logs in log files.
Note: API request information (request url, response code, timestamp, etc.) are also automatically logged (using morgan).
The app also contains 2 custom mongoose plugins that you can attach to any mongoose model schema. You can find the plugins in src/models/plugins
.
const mongoose = require('mongoose');
const { toJSON, paginate } = require('./plugins');
const userSchema = mongoose.Schema(
{
/* schema definition here */
},
{ timestamps: true }
);
userSchema.plugin(toJSON);
userSchema.plugin(paginate);
const User = mongoose.model('User', userSchema);
The toJSON plugin applies the following changes in the toJSON transform call:
The paginate plugin adds the paginate
static method to the mongoose schema.
Adding this plugin to the User
model schema will allow you to do the following:
const queryUsers = async (filter, options) => {
const users = await User.paginate(filter, options);
return users;
};
The filter
param is a regular mongo filter.
The options
param can have the following (optional) fields:
const options = {
sortBy: 'name:desc', // sort order
limit: 5, // maximum results per page
page: 2, // page number
};
The plugin also supports sorting by multiple criteria (separated by a comma): sortBy: name:desc,role:asc
The paginate
method returns a Promise, which fulfills with an object having the following properties:
{
"results": [],
"page": 2,
"limit": 5,
"totalPages": 10,
"totalResults": 48
}
Linting is done using ESLint and Prettier.
In this app, ESLint is configured to follow the Airbnb JavaScript style guide with some modifications. It also extends eslint-config-prettier to turn off all rules that are unnecessary or might conflict with Prettier.
To modify the ESLint configuration, update the .eslintrc.json
file. To modify the Prettier configuration, update the .prettierrc.json
file.
To prevent a certain file or directory from being linted, add it to .eslintignore
and .prettierignore
.
To maintain a consistent coding style across different IDEs, the project contains .editorconfig
Contributions are more than welcome! Please check out the contributing guide.


Enter the User ID for which you want to check the recommendations:
Enter the maximum number of recommendations you want to display ( keep it <100 ):


There should be
no red
anywhere.
There should be
2 identical squares
after this line:
X
There should be
2 identical squares
after this line:
X


Last week we manage to configure MicroK8s for having our own Kubernetes (k8s) cluster, so for learning a bit more on it we are going to learn how to install a PostgreSQL server that will be run natively in our cloud.
For installing PostgreSQL we are going to use a k8s operator, but first let’s understand what an operator is.
Operators are software extensions to k8s that make use of custom resources to manage applications and their components. K8s’ controllers concept lets you extend the cluster’s behaviour without modifying the code of k8s itself. Operators are clients of the k8s API that act as controllers for a Custom Resource.
So basically we extended the functionality of our cluster to easily deploy applications that could automatize how they are deployed and configure.
Why use a operator to deploy a database server? Because databases in a cloud are really hard, we need to provision storage, manage replication, credentials for the clients, and a dozen of complicated and delicate details, an operator will automatize all of this for us.
For this we are going to use this postgres-operator.
Adding the Operator
First we need to clone the repo:
Note: Currently on version 1.2.0 of the operator there is a bug that is fixed but not released, we will patch the installation before. Edit the file manifests/postgres-operator.yaml :
change
to:
End Note
Now we will install the operator using the manifests:
Now to check that the operator has started we could do:
Creating a Database
Operators work with resource, when we provide to k8s a resource with the data for a register operator it will use it to install it.
For example les create a database named movies with and admin user name moviesdba and a user named moviesuser. For this we will create a file that will could name movies-db.yml :
Now let’s create our database using :
Now we we need to wait that our database is running, we could check until we get this output :
And the inspect the nodes four our database with :
As we could see our database has a master and a replica running.
Accessing our database
For testing our database lest just use the postgresql client, we could install it with :
We will login in our server with our moviesdba user so we need to get it password, we could get it with:
The operator has configured our database server to only be accessed within the cluster so in order to test it we will forward the postgres port 5432 on our master to our localhost port 6432, this will run until we do ctrl+c :
Finally we can connect to our database with with the provide user and password using psql in another shell :
We have verify that our users are setup in our database, now we are ready for more steps that I’ll try to cover in the following days creating an application that run on our k8s cluster and connect to our database.
Finally if we look to look more about how this operator works, how we could scale our replicas and repair our database we should take a look to the operator documentation.
References
- https://github.com/zalando/postgres-operator/blob/master/docs/quickstart.md
- https://github.com/ubuntu/microk8s/issues/695
- https://grouplens.org/datasets/movielens/
- https://github.com/helm/helm/issues/6359
- https://webcloudpower.com/use-kubernetics-locally-with-microk8s/
- https://postgres-operator.readthedocs.io


ESP Sensor
Home
Wi-Fi
OpenSenseMap
Restart
☰
%CONFIG_SAVED%
OpenSenseMap configuration:
senseBox ID
Temperature Sensor Id
Humidity Sensor Id
Pressure Sensor Id


The average undergraduate student who takes out student loans has around \(\$25,000\) in debt by the end of their higher education, according to the U.S. Department of Education. However, this debt is not spread equitably by demographic category: \(30\%\) of non-Hispanic-identifying Black families carry an education loan, compared to \(20\%\) of non-Hispanic white families and \(14\%\) of Hispanic-identifying families [9.11.157].
in-context