Class: Quark::Quark::Server

Inherits:
DatawireQuarkCore::QuarkObject show all
Extended by:
DatawireQuarkCore::Static
Defined in:
lib/quark.rb

Constant Summary

Constants included from DatawireQuarkCore::Static

DatawireQuarkCore::Static::Unassigned

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from DatawireQuarkCore::Static

_lazy_statics, static, unlazy_statics

Methods inherited from DatawireQuarkCore::QuarkObject

#to_s

Constructor Details

#initialize(impl) ⇒ Server

Returns a new instance of Server.



1746
1747
1748
1749
1750
1751
1752
1753
# File 'lib/quark.rb', line 1746

def initialize(impl)
    
    self.__init_fields__
    (self).impl = impl
    (self)._sendCORS = false

    nil
end

Instance Attribute Details

#_sendCORSObject

Returns the value of attribute _sendCORS.



1739
1740
1741
# File 'lib/quark.rb', line 1739

def _sendCORS
  @_sendCORS
end

#implObject

Returns the value of attribute impl.



1739
1740
1741
# File 'lib/quark.rb', line 1739

def impl
  @impl
end

Instance Method Details

#__init_fields__Object



1857
1858
1859
1860
1861
1862
1863
# File 'lib/quark.rb', line 1857

def __init_fields__()
    
    self.impl = nil
    self._sendCORS = nil

    nil
end

#_getClassObject



1798
1799
1800
1801
1802
1803
# File 'lib/quark.rb', line 1798

def _getClass()
    
    return "quark.Server<quark.Object>"

    nil
end

#_getField(name) ⇒ Object



1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
# File 'lib/quark.rb', line 1805

def _getField(name)
    
    if ((name) == ("impl"))
        return (self).impl
    end
    if ((name) == ("_sendCORS"))
        return (self)._sendCORS
    end
    return nil

    nil
end

#_setField(name, value) ⇒ Object



1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
# File 'lib/quark.rb', line 1818

def _setField(name, value)
    
    if ((name) == ("impl"))
        (self).impl = ::DatawireQuarkCore.cast(value) { ::Quark.T }
    end
    if ((name) == ("_sendCORS"))
        (self)._sendCORS = ::DatawireQuarkCore.cast(value) { ::Object }
    end

    nil
end

#onHTTPRequest(request, response) ⇒ Object



1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
# File 'lib/quark.rb', line 1765

def onHTTPRequest(request, response)
    
    body = request.getBody()
    envelope = ::DatawireQuarkCore::JSONObject.parse(body)
    if ((((envelope).getObjectItem("$method")) == (envelope.undefined())) || (((envelope).getObjectItem("rpc")) == (envelope.undefined())))
        response.setBody((("Failed to understand request.\n\n") + (body)) + ("\n"))
        response.setCode(400)
        ::Quark.quark.concurrent.Context.runtime().respond(request, response)
    else
        methodName = (envelope).getObjectItem("$method").getString()
        json = (envelope).getObjectItem("rpc")
        method = ::Quark.quark.reflect.QuarkClass.get(::DatawireQuarkCore._getClass(self)).getField("impl").getType().getMethod(methodName)
        params = method.getParameters()
        args = ::DatawireQuarkCore::List.new([])
        idx = 0
        while ((idx) < ((params).size)) do
            (args) << (::Quark.quark.fromJSON((params)[idx], nil, json.getListItem(idx)))
            idx = (idx) + (1)
        end
        result = ::DatawireQuarkCore.cast(method.invoke(@impl, args)) { ::Quark.quark.concurrent.Future }
        result.onFinished(::Quark.quark.ServerResponder.new((self)._sendCORS, request, response))
    end

    nil
end

#onServletEnd(url) ⇒ Object

called when the servlet is removed



1850
1851
1852
1853
1854
1855
# File 'lib/quark.rb', line 1850

def onServletEnd(url)
    
    nil

    nil
end

#onServletError(url, error) ⇒ Object



1791
1792
1793
1794
1795
1796
# File 'lib/quark.rb', line 1791

def onServletError(url, error)
    
    ::Quark.quark.concurrent.Context.runtime().fail(((("RPC Server failed to register ") + (url)) + (" due to: ")) + (error.getMessage()))

    nil
end

#onServletInit(url, runtime) ⇒ Object

called after the servlet is successfully installed. The url will be the actual url used, important especially if ephemeral port was requested



1840
1841
1842
1843
1844
1845
# File 'lib/quark.rb', line 1840

def onServletInit(url, runtime)
    
    nil

    nil
end

#sendCORS(send) ⇒ Object



1758
1759
1760
1761
1762
1763
# File 'lib/quark.rb', line 1758

def sendCORS(send)
    
    (self)._sendCORS = send

    nil
end

#serveHTTP(url) ⇒ Object



1830
1831
1832
1833
1834
1835
# File 'lib/quark.rb', line 1830

def serveHTTP(url)
    
    ::Quark.quark.concurrent.Context.runtime().serveHTTP(url, self)

    nil
end